-
Notifications
You must be signed in to change notification settings - Fork 275
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
ng client: support for prefix_targets_with_hash when downloading targets #1501
ng client: support for prefix_targets_with_hash when downloading targets #1501
Conversation
I will need more time investigating and when I am ready I will update this pr and make it non-draft. |
7aa67e6
to
a834ffd
Compare
This pr is ready for review. More importantly, I made sure that when That way the usage of |
Please reword the commit. |
ce87b6f
to
a1646de
Compare
I squashed my commits and made the following changes:
|
a1646de
to
b22425b
Compare
Addressed the new comments made by @sechkova. |
tests/test_updater_ng.py
Outdated
targetname: Name of the target file. | ||
|
||
""" | ||
delegator_path = os.path.join(self.client_directory, delegator_filename) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You keep using this delegator to get the hashes, I keep disagreeing. We need a second opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am sorry it seemed that I disagree. I am just not sure how can I get information about hashes that needs to be calculated for a particular delegation if I don't access the delegator.
First, I thought you meant I didn't need to instantiate a Metadata instance in order to solve this problem and that's what I changed, but it seems like you meant something else.
It looks like I am missing something.
Can you share more how can I simplify this without accessing the delegator?
b22425b
to
2c9eee1
Compare
I removed the need of accessing the delegator file by swapping the places of |
4bb9639
to
f65e196
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine to me now.
f65e196
to
779376f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code part looks good. Could still have a look at variable use but these are nitpicks:
- why is target_fileinfo declared but then not used four lines later
- should filepath be renamed so it's clear that it's the path for local file
The test code looks a bit bad in that it's adding 80 lines of fairly complex code for a simple test that doesn't even check that the files it downloaded are the correct ones (half of the code is copy-paste as well)... but fixing this well probably needs a redesign of the whole test architecture so I'm not asking for changes here apart from the comment WRT modifying Updater internals.
779376f
to
0eb33ab
Compare
Add support for prefixing targets with their hashes when downloading or using HASH.FILENAME.EXT as target names. The introduction of prefix_targets_with_hash was necessary, because there are use cases like Warehouse where you could use consistent_snapshot, but without adding a hash prefix to your targets. When prefix_targets_with_hash is set to True, target files conforming the format HASH.FILENAME.EXT will be downloaded from the server, but they will be saved on the client side without their hash prefixes or FILENAME.EXT. This makes sure the client won't understand the usage of prefix_targets_with_hash. Still, if you want to use HASH.FILENAME.EXT as target names when downloading, then additionally you need to provide consistent_snapshot set to True in your root.json. The reason is that the specification uses consistent_snapshot for the same purpose: "If consistent snapshots are not used (see § 6.2 Consistent snapshots), then the filename used to download the target file is of the fixed form FILENAME.EXT (e.g., foobar.tar.gz). Otherwise, the filename is of the form HASH.FILENAME.EXT (e.g., c14aeb4ac9f4a8fc0d83d12482b9197452f6adf3eb710e3b1e2b79e8d14cb681.foobar.tar.gz), where HASH is one of the hashes of the targets file listed in the targets metadata file found earlier in step § 5.6 Update the targets role. In either case, the client MUST write the file to non-volatile storage as FILENAME.EXT." The same behavior of using two flags is used in the legacy code when calling tuf.client.updater.download_target() in a repository using prefix_targets_with_hash and consistent_snapshot. See chapter 5.7.3: https://theupdateframework.github.io/specification/latest/index.html#fetch-target By default, prefix_targets_with_hash is set to true to make it easier to the user to provide uniquely identifiable targets file names by using consistent_snapshot set to True. Signed-off-by: Martin Vrachev <[email protected]>
Docstrings for each class are required by linting tool. Signed-off-by: Martin Vrachev <[email protected]>
0eb33ab
to
1b392bd
Compare
I updated the pr so that:
Maybe you can share what do you think could be simplified and we can submit an issue or directly the following pr? |
I (and others) have made some notes here #1444 -- that one is about generated test data in general but there are comments wrt the other end of the spectrum (vast amounts of metadata that is at least mostly static), maybe no need to file new issues? We'll need to prototype some approaches to see if they make sense... |
Yep, I agree with you we need prototypes and more discussions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. The UpdaterConfig docs should still be improved but lets not stop this PR with that either... the code looks fine to me.
Fixes #1479
Description of the changes being introduced by the pull request:
ng client: support for prefix_targets_with_hash
Add support for prefixing targets with their hashes when downloading or
using HASH.FILENAME.EXT as target names.
The introduction of prefix_targets_with_hash was necessary, because
there are use cases like Warehouse where you could use
consistent_snapshot, but without adding a hash prefix to your targets.
When prefix_targets_with_hash is set to True, target files conforming
the format HASH.FILENAME.EXT will be downloaded from the server, but
they will be saved on the client side without their hash prefixes or
FILENAME.EXT.
This makes sure the client won't understand the usage of
prefix_targets_with_hash.
Still, if you want to use HASH.FILENAME.EXT as target names when
downloading, then additionally you need to provide consistent_snapshot
set to True in your root.json. The reason is that the specification uses
consistent_snapshot for the same purpose:
See chapter 5.7.3:
https://theupdateframework.github.io/specification/latest/index.html#fetch-target
By default, prefix_targets_with_hash is set to true to make it easier
to the user to provide uniquely identifiable targets file names by
using consistent_snapshot set to True.
The same behavior of using two flags is used in the legacy code when
calling tuf.client.updater.download_target() in a repository using
prefix_targets_with_hash and consistent_snapshot:
https://github.com/theupdateframework/tuf/blob/develop/tuf/client/updater.py#L1302
Signed-off-by: Martin Vrachev [email protected]
Please verify and check that the pull request fulfills the following
requirements: