Skip to content

ngclient: downloading targets fails if targetpath includes subdirectories #1571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jku opened this issue Sep 8, 2021 · 5 comments · Fixed by #1592
Closed

ngclient: downloading targets fails if targetpath includes subdirectories #1571

jku opened this issue Sep 8, 2021 · 5 comments · Fixed by #1592
Assignees
Labels
backlog Issues to address with priority for current development goals bug ngclient

Comments

@jku
Copy link
Member

jku commented Sep 8, 2021

ngclient has so far copied the legacy client decision of downloading files to the same directory structure as the repository uses. It has however removed the code that creates the directory structure.

So downloading any targets with paths like "path/to/file" will fail because the local directories do not exist.

@jku
Copy link
Member Author

jku commented Sep 9, 2021

I think this is actually a good time to get rid of this idea of using target paths as local path with directories (as it has several issues, not just that we don't create the subdirectories)... I'll take this

@jku jku self-assigned this Sep 9, 2021
@jku jku changed the title ngclient: target directory creation is missing ngclient: downloading targets fails if targetpath includes subdirectories Sep 9, 2021
@jku
Copy link
Member Author

jku commented Sep 13, 2021

We might want to fix this with #1412
#1412 (comment)

@MVrachev MVrachev added the backlog Issues to address with priority for current development goals label Sep 15, 2021
@jku
Copy link
Member Author

jku commented Sep 24, 2021

I have a branch but this is in practice blocked by #1587 : The legacy tests do not include any targets with sub directories (!) and I can't be bothered to add them, will wait for #1587.

I also suppose this one makes #1576 trickier to test (as the downloads just won't work).

jku pushed a commit to jku/python-tuf that referenced this issue Sep 24, 2021
Doing so is not always safe and has various other issues
(like target paths "a/../b" and "b" ending up as the same
local path).

Instead URL-encode the target path to make it a plain filename. This
removes any opportunity for path trickery and removes the need to create
the required sub directories (which we were not doing currently, leading
to failed downloads). URL-encoding encodes much more than we really need
but doing so should not hurt: the important thing is that it encodes
all path separators.

Return the actual filepath as return value. I would like to modify the
destination argument to be either a directory or a filename so caller
could decide the filename if they want to. But I won't do it now
because updated_targets() (the caching mechanism) relies on filenames
being chosen by TUF. The plan is to make it possible for caller to
choose the filename though.

Fixes theupdateframework#1571

Signed-off-by: Jussi Kukkonen <[email protected]>
@MVrachev
Copy link
Collaborator

I think this is actually a good time to get rid of this idea of using target paths as local path with directories (as it has several issues, not just that we don't create the subdirectories)... I'll take this

@jku I am sorry I created a commit before reading this issue and noticing you are assigned to it.
I created one commit possibly solving that issue: 6f108c9, but the question remains do we want
to further support targetpaths as local paths.

What other do you mean besides this one if we consider targetpaths as local paths?

@jku
Copy link
Member Author

jku commented Sep 27, 2021

@jku I am sorry I created a commit before reading this issue and noticing you are assigned to it.
I created one commit possibly solving that issue: 6f108c9,

That's fine, I'm sure you needed to do something to test -- and we are annoyingly touching the same bits of code. We'll see how bad the merging/rebasing gets...

but the question remains do we want to further support targetpaths as local paths.

I don't want to create local directories based on a URL -- a specific TUF implementation might know that is a reasonable thing to do but I don't think the library can know that. I'm suggesting we use the whole target path (url encoded) as a filename, and then also offer a way for the client application to decide the filepath themselves (so if the client knows using target path as path is safe, it can create the directories).

jku pushed a commit to jku/python-tuf that referenced this issue Sep 27, 2021
Doing so is not always safe and has various other issues
(like target paths "a/../b" and "b" ending up as the same
local path).

Instead URL-encode the target path to make it a plain filename. This
removes any opportunity for path trickery and removes the need to create
the required sub directories (which we were not doing currently, leading
to failed downloads). URL-encoding encodes much more than we really need
but doing so should not hurt: the important thing is that it encodes
all path separators.

Return the actual filepath as return value. I would like to modify the
destination argument to be either a directory or a filename so caller
could decide the filename if they want to. But I won't do it now
because updated_targets() (the caching mechanism) relies on filenames
being chosen by TUF. The plan is to make it possible for caller to
choose the filename though.

This is part of bigger plan in theupdateframework#1580
Fixes theupdateframework#1571

Signed-off-by: Jussi Kukkonen <[email protected]>
jku pushed a commit to jku/python-tuf that referenced this issue Sep 27, 2021
Doing so is not always safe and has various other issues
(like target paths "a/../b" and "b" ending up as the same
local path).

Instead URL-encode the target path to make it a plain filename. This
removes any opportunity for path trickery and removes the need to create
the required sub directories (which we were not doing currently, leading
to failed downloads). URL-encoding encodes much more than we really need
but doing so should not hurt: the important thing is that it encodes
all path separators.

Return the actual filepath as return value. I would like to modify the
arguments so caller could decide the filename if they want to. But I
won't do it now because updated_targets() (the caching mechanism)
relies on filenames being chosen by TUF. The plan is to make it
possible for caller to choose the filename though.

This is clearly a "filesystem API break" for anyone depending on the
actual target file names, and does not make sense if we do not plan to
go forward with other updated_targets()/download_target() changes
listed in theupdateframework#1580.

This is part of bigger plan in theupdateframework#1580
Fixes theupdateframework#1571

Signed-off-by: Jussi Kukkonen <[email protected]>
jku pushed a commit to jku/python-tuf that referenced this issue Sep 27, 2021
Doing so is not always safe and has various other issues
(like target paths "a/../b" and "b" ending up as the same
local path).

Instead URL-encode the target path to make it a plain filename. This
removes any opportunity for path trickery and removes the need to create
the required sub directories (which we were not doing currently, leading
to failed downloads). URL-encoding encodes much more than we really need
but doing so should not hurt: the important thing is that it encodes
all path separators.

Return the actual filepath as return value. I would like to modify the
arguments so caller could decide the filename if they want to. But I
won't do it now because updated_targets() (the caching mechanism)
relies on filenames being chosen by TUF. The plan is to make it
possible for caller to choose the filename though.

This is clearly a "filesystem API break" for anyone depending on the
actual target file names, and does not make sense if we do not plan to
go forward with other updated_targets()/download_target() changes
listed in theupdateframework#1580.

This is part of bigger plan in theupdateframework#1580
Fixes theupdateframework#1571

Signed-off-by: Jussi Kukkonen <[email protected]>
@jku jku closed this as completed in #1592 Sep 30, 2021
MVrachev pushed a commit to MVrachev/tuf that referenced this issue Oct 8, 2021
Doing so is not always safe and has various other issues
(like target paths "a/../b" and "b" ending up as the same
local path).

Instead URL-encode the target path to make it a plain filename. This
removes any opportunity for path trickery and removes the need to create
the required sub directories (which we were not doing currently, leading
to failed downloads). URL-encoding encodes much more than we really need
but doing so should not hurt: the important thing is that it encodes
all path separators.

Return the actual filepath as return value. I would like to modify the
arguments so caller could decide the filename if they want to. But I
won't do it now because updated_targets() (the caching mechanism)
relies on filenames being chosen by TUF. The plan is to make it
possible for caller to choose the filename though.

This is clearly a "filesystem API break" for anyone depending on the
actual target file names, and does not make sense if we do not plan to
go forward with other updated_targets()/download_target() changes
listed in theupdateframework#1580.

This is part of bigger plan in theupdateframework#1580
Fixes theupdateframework#1571

Signed-off-by: Jussi Kukkonen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog Issues to address with priority for current development goals bug ngclient
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants