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

New API: Add DelegationRole and Delegations classes #1370

Merged
merged 4 commits into from
May 12, 2021

Conversation

MVrachev
Copy link
Collaborator

Addresses #1139

Description of the changes being introduced by the pull request:

In the top-level metadata classes, there are complex attributes such as
"meta" in Targets and Snapshot, "key" and "roles" in Root etc.
We want to represent those complex attributes with a class to allow
easier verification and support for metadata with unrecognized fields.
For more context read ADR 0004 and ADR 0008 in the docs/adr folder.

DelegationRole shares a couple of fields with the Role class and that's
why it inherits it.
I decided to use a separate Delegations class because I thought it will
make it easier to read, verify and add additional helper functions.
Also, I tried to make sure that I test each level of the delegations
representation for support of storing unrecognized fields.

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

Comment on lines +506 to +559
elif metadata == "targets" and dict1["signed"].get("delegations"):
for keyid in dict1["signed"]["delegations"]["keys"].keys():
dict1["signed"]["delegations"]["keys"][keyid]["d"] = "c"
new_roles = []
for role in dict1["signed"]["delegations"]["roles"]:
role["e"] = "g"
new_roles.append(role)
dict1["signed"]["delegations"]["roles"] = new_roles
dict1["signed"]["delegations"]["foo"] = "bar"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I know this is ugly, but until @jku proposes his test where he automatically validates support for unrecognized fields on each level of the dictionary, we would have to stick to this.

Copy link
Member

@jku jku Apr 30, 2021

Choose a reason for hiding this comment

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

the reason I haven't done it is that while there seemingly was a consensus that "unrecognised keys should be allowed everywhere in the file format" ... it's not really true. There's a lot of places where that would be weird and unsafe (what if someone inserts random data into "keys" or "roles") and we should not allow that. The real rule is probably "unreconised keys should be allowed at every object root level": so you should be allowed to insert a key into Signed, Key or Role ... but not into any dictionary where we cannot know the recognised key names before hand (like "keys") or where the allowed keys are strictly defined (like "meta").

Poisoning everything except a hard-coded list of dictionaries (instead of only poisoning specific dicts) may still be the better testing solution but it's not trivial.

Copy link
Member

Choose a reason for hiding this comment

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

there's an implementation in #1382 now

Copy link
Member

@jku jku left a comment

Choose a reason for hiding this comment

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

I'll take another look after #1367 fixes are done and this is rebased: currently it looks buggy

tuf/api/metadata.py Outdated Show resolved Hide resolved
tuf/api/metadata.py Outdated Show resolved Hide resolved
tuf/api/metadata.py Outdated Show resolved Hide resolved
tuf/api/metadata.py Outdated Show resolved Hide resolved
tuf/api/metadata.py Outdated Show resolved Hide resolved
tuf/api/metadata.py Outdated Show resolved Hide resolved
tuf/api/metadata.py Outdated Show resolved Hide resolved
tuf/api/metadata.py Outdated Show resolved Hide resolved
tuf/api/metadata.py Outdated Show resolved Hide resolved
@MVrachev
Copy link
Collaborator Author

Rebased on top of the latest develop branch and addressed all comments made by @jku.

Copy link
Member

@jku jku left a comment

Choose a reason for hiding this comment

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

This looks good to me, thanks.

I left one typo comment and have a naming question but it's basically ✔️ for me.

Naming: Would DelegatedRole be better than DelegationRole -- maybe it conveys a little bit more information (in that this clearly is the role that is delegated, not the one that is delegating)? I don't feel strongly about it though, just want to make sure we try to find the best names...

tuf/api/metadata.py Outdated Show resolved Hide resolved
@MVrachev
Copy link
Collaborator Author

This looks good to me, thanks.

I left one typo comment and have a naming question but it's basically ✔️ for me.

Naming: Would DelegatedRole be better than DelegationRole -- maybe it conveys a little bit more information (in that this clearly is the role that is delegated, not the one that is delegating)? I don't feel strongly about it though, just want to make sure we try to find the best names...

Yes, I agree DelegatedRole sounds better. I was never in love with the DelegationRole naming but wasn't sure what other options there are.

@MVrachev MVrachev force-pushed the delegation-classes branch 2 times, most recently from ae2d644 to 8519016 Compare May 11, 2021 11:00
Copy link
Member

@jku jku left a comment

Choose a reason for hiding this comment

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

Thanks!

@MVrachev MVrachev force-pushed the delegation-classes branch 2 times, most recently from 9815917 to 198025b Compare May 11, 2021 11:53
In the top level metadata classes, there are complex attributes such as
"meta" in Targets and Snapshot, "key" and "roles" in Root etc.
We want to represent those complex attributes with a class to allow
easier verification and support for metadata with unrecognized fields.
For more context read ADR 0004 and ADR 0008 in the docs/adr folder.

DelegatedRole shares a couple of fields with the Role class and that's
why it inherits it.
I decided to use a separate Delegations class because I thought it will
make it easier to read, verify and add additional helper functions.
Also, I tried to make sure that I test each level of the delegations
representation for support of storing unrecognized fields.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
Stop using Mapping where we actually mean Dict:
Mapping means "we only need a read-only dict" and most of the time
this is not really the case.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
@MVrachev
Copy link
Collaborator Author

Rebased on top of the latest master branch.

@jku jku merged commit 2ef8546 into theupdateframework:develop May 12, 2021
@MVrachev MVrachev deleted the delegation-classes branch May 19, 2021 12:55
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.

2 participants