Skip to content

Add an example script about succinct roles usage - #2038

Merged
lukpueh merged 6 commits into
theupdateframework:developfrom
MVrachev:tap15-example
Aug 12, 2022
Merged

lukpueh merged 6 commits into
theupdateframework:developfrom
MVrachev:tap15-example

Conversation

@MVrachev

Copy link
Copy Markdown
Collaborator

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
:

  • The code follows the Code Style Guidelines
  • Tests have been added for the bug fix or new feature
  • Docs have been added for the bug fix or new feature

@coveralls

coveralls commented Jun 24, 2022 •

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 2582892597

Warning: 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

  • 40 of 40 (100.0%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.08%) to 98.169%

Totals Coverage Status
Change from base Build 2571468942: 0.08%
Covered Lines: 1173
Relevant Lines: 1186

💛 - Coveralls

@jku

jku commented Jun 28, 2022 •

Copy link
Copy Markdown
Member

Higher-level question (answer may be "let's handle in another issue"):
Are we happy with the level of usefulness of these hashed bin examples?

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 succinct_....py script actually imported basic_repo.py in the beginning and just added metadata to an already complete repository using the same keys etc? Importing scripts from other scripts is bad form of course but it might give us a usable repository with minimal hassle.

@jku jku left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@MVrachev

Copy link
Copy Markdown
Collaborator Author

Higher-level question (answer may be "let's handle in another issue"): Are we happy with the level of usefulness of these hashed bin examples?

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 succinct_....py script actually imported basic_repo.py in the beginning and just added metadata to an already complete repository using the same keys etc? Importing scripts from other scripts is bad form of course but it might give us a usable repository with minimal hassle.

My only real concern is that this script will no longer be self-sufficient.
You have a point in that those scripts are located under examples/repo_example (which by the way probably should be renamed to repo_examples) suggesting that those scripts are actually creating repositories.

Maybe we already make a lot of references to basic_repo.py and we can directly utilize it.
In hash_bin_delegation.py we mention basic_repo.py 5 times, in this script we mention it 4.
@lukpueh any opinions on this as you are heavily connected with those scripts.

@MVrachev

Copy link
Copy Markdown
Collaborator Author

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.

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.

Comment thread tuf/api/metadata.py Resolved
@MVrachev
MVrachev force-pushed the tap15-example branch 3 times, most recently from f318edf to cec9cb0 Compare June 30, 2022 09:54
@jku

jku commented Jul 1, 2022

Copy link
Copy Markdown
Member

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

@MVrachev

MVrachev commented Jul 2, 2022 •

Copy link
Copy Markdown
Collaborator Author

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?

@jku

jku commented Jul 4, 2022

Copy link
Copy Markdown
Member

@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?
Basically, do we have hopes that these examples produce usable repositories (that could be tested), or are we content that they are just snippets of code? I could choose either one, was hoping Lukas has an opinion :)

@lukpueh

lukpueh commented Jul 4, 2022

Copy link
Copy Markdown
Member

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 path_hash_prefixes field in the spec, hence the excessive commenting in the script. With succinct hash bin delegation this is a bit different, because there is TAP 15 and also a new documented management class in the metadata API.

@joshuagl

joshuagl commented Jul 4, 2022

Copy link
Copy Markdown
Member

for traditional hash bin delegation there is actually no other documentation than the example script, except for a paragraph about the path_hash_prefixes field in the spec

We would like to change that theupdateframework/specification#210

@MVrachev

MVrachev commented Jul 5, 2022

Copy link
Copy Markdown
Collaborator Author

With succinct hash bin delegation this is a bit different, because there is TAP 15 and also a new documented management class in the metadata API.

@lukpueh will appreciate an opinion on where the documentation can be shortened and is too detailed.

@lukpueh lukpueh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]>
@MVrachev
MVrachev requested a review from lukpueh July 21, 2022 19:34
Martin Vrachev added 3 commits July 21, 2022 22:39
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]>
@MVrachev

Copy link
Copy Markdown
Collaborator Author

@lukpueh I updated the pr as you had suggested.
I tried simplifying it as much as I could.

Ready for the next batch of comments.

@lukpueh lukpueh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my revision above.

# 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can omit this comment. Verification is not in the scope of this example.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree.

#
# 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#2038 (comment) applies here too.

Comment on lines +181 to +182
# versioned file names. Most notably see 'targets.json' and
# 'delegated_bin-0d.json'. For more information on versioned file names see:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this phrase a conjunction? Should it be two sentences?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. It's a weird phrase.

Suggested change
# 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jhdalek55

Copy link
Copy Markdown
Contributor

I'll take a look later this morning.

@jhdalek55

Copy link
Copy Markdown
Contributor

@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?

@lukpueh

lukpueh commented Aug 5, 2022

Copy link
Copy Markdown
Member

@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!

@jhdalek55

Copy link
Copy Markdown
Contributor

Ok. I'll take a look.

@jhdalek55 jhdalek55 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. It's a weird phrase.

Suggested change
# 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.

lukpueh and others added 2 commits August 11, 2022 16:54
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]>
@lukpueh

lukpueh commented Aug 11, 2022

Copy link
Copy Markdown
Member

@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.

cc @joshuagl, @jku

@jku jku left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@lukpueh
lukpueh merged commit a773e8f into theupdateframework:develop Aug 12, 2022
@MVrachev

MVrachev commented Aug 15, 2022 •

Copy link
Copy Markdown
Collaborator Author

I don't mind the changes you added.
I am not a native speaker and really appreciate the help of @jhdalek55 and all of the reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants