Skip to content
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

Support delegations in client #137

Conversation

raphaelgavache
Copy link
Contributor

@raphaelgavache raphaelgavache commented Jul 12, 2021

This PR adds the support of delegations in the client

Notable changes

  • support delegations in client.Download, following spec 1.0.19 section 5.6
  • root is no longer required in the snapshot meta

Notes

  • ignore the commit Add TUF3 php test, this commit only imports test files
  • copied TUF3 files from php fixtures to test delegations logic

Follow ups

  • add chained root downloading to comply with spec and add other fixtures from php

Review walkthrough

1. data/types.go data/types_test.go
  • delegations fields are added to the structs with JSON support
  • MatchesPath matches a file to a delegation with the support of Paths and PathHashPrefixes
2. verify/db.go
  • reuse DB struct verifiers to verify delegated roles from a parent Targets keys
  • delegationsVerifier is added to bypass specific logic dedicated to the 4 top roles
3. client/client.go
  • client.Download will now try to fetch FileMeta through the graph of delegations if it's not already cached. Previous pattern was check cache, check local top level Targets. New pattern is check cache, check local top level Targets, check local delegations, download missing delegations.
  • root is no longer required in snapshot
  • MaxDelegations parameter is introduced to bound a search in the delegations
4. client/delegations.go client/delegations_test.go
  • getTargetFileMeta implements the delegation search logic

@trishankatdatadog
Copy link
Member

Thanks, @raphaelgavache!

Would you please summarize the changes over the source code, so that we know what to expect while reviewing?

Copy link
Contributor

@ethan-lowman-dd ethan-lowman-dd left a comment

Choose a reason for hiding this comment

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

Thanks Raphael. Here's a first batch of comments. I hope to complete a first pass by tomorrow.

data/hex_bytes.go Show resolved Hide resolved
data/types.go Outdated Show resolved Hide resolved
client/delegations_test.go Outdated Show resolved Hide resolved
client/client_test.go Outdated Show resolved Hide resolved
client/delegations.go Outdated Show resolved Hide resolved
verify/db.go Outdated Show resolved Hide resolved
verify/db.go Outdated Show resolved Hide resolved
verify/db.go Outdated Show resolved Hide resolved
verify/verify.go Outdated Show resolved Hide resolved
verify/db.go Show resolved Hide resolved
@raphaelgavache raphaelgavache force-pushed the raphael/support_delegations_client branch from e62e1b0 to b01e941 Compare July 12, 2021 21:28
@raphaelgavache
Copy link
Contributor Author

Thanks Ethan, the delegation verifier code is now a lot cleaner!
I'll apply your other comments tomorrow morning and add an error when both Paths and PathsPrefixes are set to stick to the spec

@trishankatdatadog
Copy link
Member

Thanks for your review, @ethan-lowman-dd!

@raphaelgavache: does this implement a single-pass (i.e., look for only one target at a time) or a multi-pass (i.e., look for multiple targets at once) approach to delegations?

@raphaelgavache
Copy link
Contributor Author

It's the single-pass one that searches for one target at a time

@coveralls
Copy link

coveralls commented Jul 12, 2021

Pull Request Test Coverage Report for Build 1046833689

  • 200 of 235 (85.11%) changed or added relevant lines in 7 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+2.0%) to 69.354%

Changes Missing Coverage Covered Lines Changed/Added Lines %
client/client.go 23 24 95.83%
verify/db.go 26 28 92.86%
data/types.go 29 33 87.88%
verify/verify.go 6 11 54.55%
client/errors.go 0 7 0.0%
client/delegations.go 112 128 87.5%
Files with Coverage Reduction New Missed Lines %
verify/db.go 1 85.9%
Totals Coverage Status
Change from base Build 987132054: 2.0%
Covered Lines: 1772
Relevant Lines: 2555

💛 - Coveralls

@trishankatdatadog
Copy link
Member

As a sanity-check, can we cross-check for correctness against this recursive implementation?

Copy link
Contributor

@ethan-lowman-dd ethan-lowman-dd left a comment

Choose a reason for hiding this comment

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

See this branch for the proposed changes from today.

verify/verify.go Outdated Show resolved Hide resolved
data/types.go Outdated Show resolved Hide resolved
data/types.go Outdated Show resolved Hide resolved
data/types.go Outdated Show resolved Hide resolved
client/delegations.go Outdated Show resolved Hide resolved
client/delegations.go Outdated Show resolved Hide resolved
client/delegations.go Outdated Show resolved Hide resolved
client/delegations_test.go Show resolved Hide resolved
data/types.go Show resolved Hide resolved
* Clarify validation of signing role & metadata type

* Add/update comments

* Validation happens on both decode & encode

* Bubble up an error if MatchesPath is called on an invalid DelegatedRole

* Match spec for delegation traversal

* Comment in the iterator

* Add diamond test case

* Revert "Match spec for delegation traversal"

This reverts commit 15fee6b.

* Rename IsTopLevelRole back to ValidRole to avoid breaking change
Copy link
Member

@trishankatdatadog trishankatdatadog left a comment

Choose a reason for hiding this comment

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

first set of comments

data/types.go Outdated Show resolved Hide resolved
verify/db.go Outdated Show resolved Hide resolved
verify/verify.go Outdated Show resolved Hide resolved
client/client.go Show resolved Hide resolved
data/types.go Show resolved Hide resolved
client/delegations.go Outdated Show resolved Hide resolved
client/delegations.go Outdated Show resolved Hide resolved
client/delegations.go Outdated Show resolved Hide resolved
client/delegations.go Outdated Show resolved Hide resolved
client/delegations.go Outdated Show resolved Hide resolved
* Add back lower case check

* Initialize with size and comment

* Simplify iterator initialization
Copy link
Member

@trishankatdatadog trishankatdatadog left a comment

Choose a reason for hiding this comment

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

second round of comments

client/delegations.go Outdated Show resolved Hide resolved
client/delegations.go Outdated Show resolved Hide resolved
client/delegations.go Outdated Show resolved Hide resolved
client/delegations.go Outdated Show resolved Hide resolved
client/delegations.go Outdated Show resolved Hide resolved
data/types.go Show resolved Hide resolved
client/client.go Show resolved Hide resolved
client/delegations.go Outdated Show resolved Hide resolved
client/delegations.go Outdated Show resolved Hide resolved
client/delegations.go Outdated Show resolved Hide resolved
ethan-lowman-dd and others added 4 commits July 16, 2021 19:26
…ec (#6)

(instead of true cycle detection with "edges seen").

This reverts commit cfbb024.
Co-authored-by: Ethan Lowman <[email protected]>
* Update name

* Rename file to target

* Nits

* Move verifier in iterator and rename fields
Copy link
Member

@trishankatdatadog trishankatdatadog left a comment

Choose a reason for hiding this comment

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

LGTM, the code is super nice!

@joshuagl and @asraa can you pls help review? 🙂

client/delegations.go Outdated Show resolved Hide resolved
client/delegations.go Show resolved Hide resolved
client/delegations.go Show resolved Hide resolved
* Update delegations to err on top level role

* Add simple cycle test

* Remove duplicate check
client/client.go Show resolved Hide resolved
client/client.go Show resolved Hide resolved
client/delegations.go Show resolved Hide resolved
@trishankatdatadog
Copy link
Member

@raphaelgavache, one more thing: can you check whether you match paths using glob-style matching?

Meanwhile, I will read your tests to check for correctness...

@@ -210,13 +218,17 @@ func (c *Client) update(latestRoot bool) (data.TargetFiles, error) {

// If we don't have the root.json, download it, save it in local
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be the responsibility of the user to download the very first root.json from a secure channel?

data/types.go Show resolved Hide resolved
@trishankatdatadog
Copy link
Member

Hmm, looks like @mnm678 and @asraa are not maintainers of go-tuf, which is not cool! We should fix this. I'm going to go ahead and merge this in the interesting of unblocking this PR, which has been through extensive review. Thanks again everyone, especially @raphaelgavache!

@trishankatdatadog trishankatdatadog merged commit e95956b into theupdateframework:master Aug 4, 2021
@ethan-lowman-dd ethan-lowman-dd mentioned this pull request Aug 16, 2021
@raphaelgavache
Copy link
Contributor Author

Thank you for the reviews!

mnm678 pushed a commit to mnm678/go-tuf that referenced this pull request Oct 21, 2021
* Add delegation client

* Add TUF3 php test

* Use ioutil for go 1.15

* Add more delegations tests

* Cleanups

* Check new paths

* Add suggestion

* Add struct tags

* Add tags and remove duplicate types

* Formatting

* Fix order of asserts (should be want, got)

* Clean up DelegatedRole validation

* Fix root to top targets delegation

* July 14 changes (theupdateframework#4)

* Clarify validation of signing role & metadata type

* Add/update comments

* Validation happens on both decode & encode

* Bubble up an error if MatchesPath is called on an invalid DelegatedRole

* Match spec for delegation traversal

* Comment in the iterator

* Add diamond test case

* Revert "Match spec for delegation traversal"

This reverts commit 15fee6b.

* Rename IsTopLevelRole back to ValidRole to avoid breaking change

* Update after reviews

* Add back lower case check

* Initialize with size and comment

* Simplify iterator initialization

* Revert back to "nodes seen" interpretation of delegation traversal spec (theupdateframework#6)

(instead of true cycle detection with "edges seen").

This reverts commit cfbb024.

* Update client/delegations.go

Co-authored-by: Ethan Lowman <[email protected]>

* Update following reviews of 16th of july (theupdateframework#7)

* Update name

* Rename file to target

* Nits

* Move verifier in iterator and rename fields

* Add tests

* Update after 19th july review (theupdateframework#9)

* Update delegations to err on top level role

* Add simple cycle test

* Remove duplicate check

* Fix comment

* Update comment

Co-authored-by: Ethan Lowman <[email protected]>
Co-authored-by: Ethan Lowman <[email protected]>
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.

7 participants