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

Metadata API: Accept X.Y spec_version #1796

Merged

Conversation

jku
Copy link
Member

@jku jku commented Jan 26, 2022

All TUF implementations used to use "1.0" as the spec version and most
of them have never modified that value since.

Accept two-digit spec_version for legacy compatibility: it is strictly
speaking against the current spec (which requires semver) but there
should be no harm in doing this and it allows us to deserialize
metadata generated by e.g. go-tuf.

Fixes #1751

Signed-off-by: Jussi Kukkonen jkukkonen@vmware.com

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

@jku jku requested a review from MVrachev January 26, 2022 09:04
@jku jku force-pushed the accept-two-part-spec-version branch from 4cd9e15 to b857a37 Compare January 26, 2022 09:09
@coveralls
Copy link

coveralls commented Jan 26, 2022

Pull Request Test Coverage Report for Build 1751048969

  • 4 of 4 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.07%) to 97.765%

Totals Coverage Status
Change from base Build 1745632739: 0.07%
Covered Lines: 4090
Relevant Lines: 4169

💛 - Coveralls

Comment on lines +436 to +437
if len(spec_list) not in [2, 3] or not all(
el.isdigit() for el in spec_list
Copy link
Member Author

Choose a reason for hiding this comment

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

this is a weird construct but black wants to lay it out this way -- I'll take suggestions to make it clearer though

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't have a better suggestion as well, but it's not so bad.
black splits all brackets so that we can see clearly what are the arguments which are the complicated part.

@jku
Copy link
Member Author

jku commented Jan 26, 2022

coverage claims none of the valueerrors are tested. I'll have to investigate that -- EDIT: done, bug fix commit added.

Copy link
Member

@joshuagl joshuagl left a comment

Choose a reason for hiding this comment

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

The specification does suggest semver, but also leaves it up to clients to decide what is considered a match.

This seems fine to me.

Copy link
Collaborator

@MVrachev MVrachev left a comment

Choose a reason for hiding this comment

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

Overall, I agree with the changes even though it would have been better if the clients and implementations all stick to using all of the numbers in semver.

Comment on lines +442 to +443
if spec_list[0] != SPECIFICATION_VERSION[0]:
raise ValueError(f"Unsupported spec_version {spec_version}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

So, finally, we don't want to log if there are differences in minor versions?

Copy link
Member Author

Choose a reason for hiding this comment

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

could do a debug log I suppose... but realistically a large portion of metadata that is deserialized is likely to not match exactly (think updated clients loading older targets metadata that was created with lower spec_version).

Comment on lines +39 to +41
"no spec_version": '{"_type": "snapshot", "version": 1, "expires": "2030-01-01T00:00:00Z", "meta": {}}',
"no version": '{"_type": "snapshot", "spec_version": "1.0.0", "expires": "2030-01-01T00:00:00Z", "meta": {}}',
"no expires": '{"_type": "snapshot", "spec_version": "1.0.0", "version": 1, "meta": {}}',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good catch. The data can even be valid, but because of the _type, it will fail...

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah -- one of those cases where parsing exception messages might have helped... but I'm still not willing to do that amount of work

Jussi Kukkonen added 2 commits January 26, 2022 15:34
All TUF implementations used to use "1.0" as the spec version and most
of them have never modified that value since.

Accept two-part spec_version for legacy compatibility: it is strictly
speaking against the current spec (which requires semver) but there
should be no harm in doing this and it allows us to deserialize
metadata generated by e.g. go-tuf.

Fixes theupdateframework#1751

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
Most of the test_invalid_signed_serialization subtests are currently
failing because "_type": "signed" and then the test tries to deserialize
them as Snapshot (which fails a type check).

Correct the type to "snapshot" so that we can fail in the correct places
during serialization instead.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
@jku jku force-pushed the accept-two-part-spec-version branch from 996f477 to 1695622 Compare January 26, 2022 13:36
@jku
Copy link
Member Author

jku commented Jan 26, 2022

force pushed with one change:

  • the new valid test case uses the common legacy value "1.0" instead of just some two part value

Copy link
Member

@lukpueh lukpueh left a comment

Choose a reason for hiding this comment

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

Patch looks good to me. Also kudos for catching the test bug!

@lukpueh lukpueh merged commit 9cda6e5 into theupdateframework:develop Feb 8, 2022
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.

spec version incompatibility
5 participants