Repository navigation
Add an example script about succinct roles usage - #2038
Conversation
Pull Request Test Coverage Report for Build 2582892597Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
|
Higher-level question (answer may be "let's handle in another issue"): What I mean is that a basic test of repository metadata is "can I use this metadata with a client?": currently it seems like I'd have to do a lot of work to go from this example to something that actually works in a meaningful way. As a straw man proposal: what if the |
jku
left a comment
There was a problem hiding this comment.
Looks nice. It feels a bit verbose (the file is larger than hashed_bin_delegation.py even though it has less code): It might be better example code if the comments were shorter and more focused "because we want X, we do Y then Z" but I also think it's perfectly fine as is.
The other comments are just opinions but please doublecheck the paragraph abnout hexadecimal in bin names.
My only real concern is that this script will no longer be self-sufficient. Maybe we already make a lot of references to |
I think I had to give some context about succinct hash bin delegations and didn't want just to point out steps with no explanation. |
f318edf to
cec9cb0
Compare
|
I wonder if lukas is around next week? Could get his opinion on the general direction these scripts should be going to... but this PR looks good to me, I think we can just file more issues for other changes |
I think he should be @lukpueh can you have a look when you have the time? @jku are there any particular issues you want me to file? |
well no, this is just me asking again Are we happy with the level of usefulness of these hashed bin examples? |
I don't have a very strong opinion. My idea was to make the scripts as simple as possible to show the most basic interaction with the Metadata API to create TUF repositories. Making them importable with re-usuable functionality will likely increase their complexity. So, I suppose it's a matter of priorities. Mine was to inspire and not to provide repository tooling. Maybe we can find a middle-way, but I would rather spend that extra designing/engineering effort on actual repository tooling, which should then also allow for simpler example scripts. Regarding code comments, for traditional hash bin delegation there is actually no other documentation than the example script, except for a paragraph about the |
We would like to change that theupdateframework/specification#210 |
@lukpueh will appreciate an opinion on where the documentation can be shortened and is too detailed. |
lukpueh
left a comment
There was a problem hiding this comment.
Nice work, Martin! Here's a first batch of comments. As argued somewhere inline, I think you could shorten the comments especially in the beginning of the workflow quite a bit.
Want to give it a try and I'll do another round of review?
Btw. I here are a few dev doc writing tricks I learned at EuroPython last week. (hat tip to @MasonEgger)
We no longer need or use SPEC_VERSION variable defined in the begging of the script. Additionally, I decided to add a small addition to the "roles" type annotation as that gives better context to the syntax highlighter of VS code. Signed-off-by: Martin Vrachev <[email protected]>
Add a basic example script showing all features of the succinct hash bin delegations and the available API calls of SuccinctRoles. The explanations are used to promote the usage of succinct hash bin delegations by explaining it well enough so our users can understand the API limitations and how to use them and at the same time I tried not going into too many details of the SuccinctRoles math as its implementation is inside tuf/api/metadata.py and there there are explanations about that. Signed-off-by: Martin Vrachev <[email protected]>
If we have a goal of making metadata that can just be served to clients, then these (and the parent metadata) should have versioned filenames. Change the file names of the delegated files in the hashed_bin_delegation.py to versioned. Signed-off-by: Martin Vrachev <[email protected]>
Signed-off-by: Martin Vrachev <[email protected]>
|
@lukpueh I updated the pr as you had suggested. Ready for the next batch of comments. |
lukpueh
left a comment
There was a problem hiding this comment.
Thanks for the updates, @MVrachev! This has become a lot more concise. I'd appreciate a final review of a native speaker before we merge. cc @joshuagl, @jhdalek55
| NUMBER_OF_BINS = 32 | ||
| # | ||
| # The bit length is the number of bins that will be used to calculate the bin | ||
| # for each target path. It can be calculated directly from NUMBER_OF_BINS: |
There was a problem hiding this comment.
I find it hard to parse this sentence. I think I liked it better as it was before. Or what about e.g.:
"The number of bins determines how many bits in a target path are considered to assign the target to a bin."
| # required for signing the bins or in other words the value of the threshold. | ||
| # For the purpose of this example we choose the threshold to be: | ||
| THRESHOLD = 1 | ||
| # Note: If THRESHOLD is changed to more than 1 the example should be modified. |
There was a problem hiding this comment.
I think you can omit this comment. Verification is not in the scope of this example.
| # | ||
| # Using succinct hash bin delegations has two restrictions: | ||
| # 1) no other delegated roles have to be used | ||
| # 2) only one succinct hash bin delegation can exist for one targets role |
There was a problem hiding this comment.
I think you can omit this extra info. It is documented in TAP15 and in the metadata API. And not relevant for the example.
| # Sign all metadata and persist to a temporary directory at CWD for review using | ||
| # versioned file names. Most notably see 'targets.json' and | ||
| # 'delegated_bin-0d.json'. For more information on versioned file names see: | ||
| # https://theupdateframework.github.io/specification/latest/#writing-consistent-snapshots |
| # versioned file names. Most notably see 'targets.json' and | ||
| # 'delegated_bin-0d.json'. For more information on versioned file names see: |
There was a problem hiding this comment.
| # versioned file names. Most notably see 'targets.json' and | |
| # 'delegated_bin-0d.json'. For more information on versioned file names see: | |
| # versioned file names. Most notably see '1.targets.json' and | |
| # '1.delegated_bin-0d.json'. For more information on versioned file names see: |
?
| PRETTY = JSONSerializer(compact=False) | ||
| TMP_DIR = tempfile.mkdtemp(dir=os.getcwd()) | ||
|
|
||
| # Generate a key for targets we haven't added one up to this point. |
There was a problem hiding this comment.
Does this phrase a conjunction? Should it be two sentences?
There was a problem hiding this comment.
Agreed. It's a weird phrase.
| # Generate a key for targets we haven't added one up to this point. | |
| # Generate a key for targets that up to this point have not received one. |
There was a problem hiding this comment.
I suggest to move the create_key call up to where we created the other key. Then we don't have to explain why we all of a sudden create another key.
|
I'll take a look later this morning. |
|
@lukpueh Do you wish a review just on this PR or on the TAP as a whole? If its the latter, send me the correct link? |
Just the new file in this PR. You can comment here: https://github.com/theupdateframework/python-tuf/pull/2038/files#diff-8b760bfeb4c14beace00509e9a55c8486510b4516e7ba9e10adee18782673616 The document is a Python program but with extensive code comments to serve as sort of tutorial. I'd appreciate if you could take a look if the code comments are sound English. No need to comment on the overall structure. I think that is fine as is. Thanks! |
|
Ok. I'll take a look. |
jhdalek55
left a comment
There was a problem hiding this comment.
Most of the changes here are minor, but needed to clarify the text.
| # required for signing the bins or in other words the value of the threshold. | ||
| # For the purpose of this example we choose the threshold to be: | ||
| THRESHOLD = 1 | ||
| # Note: If THRESHOLD is changed to more than 1 the example should be modified. |
| PRETTY = JSONSerializer(compact=False) | ||
| TMP_DIR = tempfile.mkdtemp(dir=os.getcwd()) | ||
|
|
||
| # Generate a key for targets we haven't added one up to this point. |
There was a problem hiding this comment.
Agreed. It's a weird phrase.
| # Generate a key for targets we haven't added one up to this point. | |
| # Generate a key for targets that up to this point have not received one. |
Apply minor rewording suggestions from code review. Co-authored-by: Lois Anne DeLong <[email protected]> Signed-off-by: Lukas Puehringer <[email protected]>
Generate keys for all roles in one place and rename to better distinguish delegating targets key from bins key. Signed-off-by: Lukas Puehringer <[email protected]>
|
@MVrachev, I took the liberty the push two commits, addressing my and @jhdalek55's comments. Feel free to revert if you don't agree. Otherwise, I'm fine with this PR. Can we maybe get another set of eyes? This PR is the last blocker for our next release. |
There was a problem hiding this comment.
Looks good to me.
As a nitpick, the succinct role creation would likely be a little neater and safer if you don't try to insert the keys during object construction (and use add_key() afterwards instead). I filed #2071 to improve that area anyway
|
I don't mind the changes you added. |
Related to issue #1909
Description of the changes being introduced by the pull request:
Add a basic example script showing all features of the succinct hash bin
delegations and the available API calls of
SuccinctRoles.The explanations are used to promote the usage of succinct hash bin
delegations by explaining it well enough so our users can understand
the API limitations and how to use them and at the same time I tried not
going into too many details of the SuccinctRoles math as its
implementation is inside tuf/api/metadata.py and there there are
explanations about that.
Please verify and check that the pull request fulfills the following
requirements: