Skip to content

Comments

Metadata API: preserve Role.keyids order#1481

Merged
jku merged 1 commit intotheupdateframework:developfrom
MVrachev:fix-role-keyids-order
Jul 15, 2021
Merged

Metadata API: preserve Role.keyids order#1481
jku merged 1 commit intotheupdateframework:developfrom
MVrachev:fix-role-keyids-order

Conversation

@MVrachev
Copy link
Collaborator

@MVrachev MVrachev commented Jul 5, 2021

Fixes #1478

We made Role.keyids a set because the keyids are supposed
to be unique and this still makes sense.

However, the data should also preserve order
(when deserialized and serialized) and currently, it does not.
This is fairly serious since writing signed data potentially modifies
the data (making the signature invalid).

The simplest solution (as proposed by Jussi) is to make keyids
a property and there to enforce keyids uniqueness and preserve the
order by using a list instead of a set.

Description of the changes being introduced by the pull request:

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

@MVrachev MVrachev force-pushed the fix-role-keyids-order branch 2 times, most recently from 497a6e5 to db55ccf Compare July 5, 2021 17:36
@jku
Copy link
Member

jku commented Jul 9, 2021

@MVrachev can you please comment on Teodoras suggestion (comment was made in the issue)?

I think the idea was that we could keep using the set if we make sure that on serialization we always sort the the output. This has some corner cases as well (like if your using the API to process keyids somehow, the order isn't guaranteed) but if that's the only issue then maybe that's a better way?

@MVrachev
Copy link
Collaborator Author

MVrachev commented Jul 9, 2021

Yes, I started answering, but it seems I haven't sent my response.
It sounds reasonable and it won't add complexity with the additional property and checks that have to be made in my current suggestions.
I will update the pr with those suggestions.

We made Role.keyids a set because the keyids are supposed
to be unique and this still makes sense.

However, the data should also preserve order
(when deserialized and serialized) and currently, it does not.
This is fairly serious since writing signed data potentially modifies
the data (making the signature invalid).

The simplest solution (as proposed by Teodora) is to sort the
set during serialization and that would ensure the order of the items.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
@MVrachev MVrachev force-pushed the fix-role-keyids-order branch from db55ccf to df9f3df Compare July 9, 2021 13:51
@MVrachev
Copy link
Collaborator Author

MVrachev commented Jul 9, 2021

Yes, it looks a lot better.
Great suggestion @sechkova!

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'm trying to think if there's any case where in the API we would need the ordered keyids... but I don't think we ever do. So this looks right to me, thanks!

@jku jku merged commit 23e4f5c into theupdateframework:develop Jul 15, 2021
@MVrachev MVrachev deleted the fix-role-keyids-order branch July 19, 2021 13:36
MVrachev pushed a commit to MVrachev/tuf that referenced this pull request Jul 28, 2021
Test metadata dataset containing containers of zero or more
elements can be serialized into objects.

Here is the status for the different use cases:
Root keys:
- many keys: added
Root roles:
- many roles: added
Root role keyids:
- many keids: already added in theupdateframework#1481
MetaFile hashes:
- many hashes: already tested
- zero hashes: added. Testing as invalid test case.
Delegation keys:
- many keys: added
Delegation role keyids:
- many keyids: added
Delegation role paths:
- many paths: already tested
Delegation role path_hash_prefixes:
- many path_hash_path_prefixes: already tested

According to the spec having an empty container for any of these cases:
- Root keys
- Root roles
- Root role keyids
- Delegation keys
- DelegationRole keyids
- DelegationRole paths
- DelegationRole path_hash_prefixes
is not allowed, but for the purpose of interactive object construction
we don't block those use-cases.
Still, we don't want to add tests, because we don't want to
advertise this behavior.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
MVrachev pushed a commit to MVrachev/tuf that referenced this pull request Jul 28, 2021
Test metadata (de)serialization with input data containing containers
with zero or more elements.

Here is the status for the different use cases:
Root keys:
- many keys: added
Root roles:
- many roles: added
Root role keyids:
- many keids: already added in theupdateframework#1481
MetaFile hashes:
- many hashes: already tested
- zero hashes: added. Testing as invalid test case.
Delegation keys:
- many keys: added
Delegation role keyids:
- many keyids: added
Delegation role paths:
- many paths: already tested
Delegation role path_hash_prefixes:
- many path_hash_path_prefixes: already tested

According to the spec having an empty container for any of these cases:
- Root keys
- Root roles
- Root role keyids
- Delegation keys
- DelegationRole keyids
- DelegationRole paths
- DelegationRole path_hash_prefixes
is not allowed, but for the purpose of interactive object construction
we don't block those use-cases.
We don't want to add tests, because we don't want to
advertise this behavior.

In the future, we are going to add validation that those cases don't
occur which will be called when serializing the object back to
bytes/dictionary/file.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
MVrachev pushed a commit to MVrachev/tuf that referenced this pull request Jul 28, 2021
Test metadata (de)serialization with input data containing containers
with zero or more elements.

Here is the status for the different use cases:
Root keys:
- many keys: added
Root roles:
- many roles: added
Root role keyids:
- many keids: already added in theupdateframework#1481
MetaFile hashes:
- many hashes: already tested
- zero hashes: added. Testing as invalid test case.
Delegation keys:
- many keys: added
Delegation role keyids:
- many keyids: added
Delegation role paths:
- many paths: already tested
Delegation role path_hash_prefixes:
- many path_hash_path_prefixes: already tested

According to the spec having an empty container for any of these cases:
- Root keys
- Root roles
- Root role keyids
- Delegation keys
- DelegationRole keyids
- DelegationRole paths
- DelegationRole path_hash_prefixes
is not allowed, but for the purpose of interactive object construction
we don't block those use-cases.
We don't want to add tests, because we don't want to
advertise this behavior.

In the future, we are going to add validation that those cases don't
occur which will be called when serializing the object back to
bytes/dictionary/file.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
MVrachev pushed a commit to MVrachev/tuf that referenced this pull request Aug 6, 2021
Test metadata (de)serialization with input data containing containers
with zero or more elements.

Here is the status for the different use cases:
Root keys:
- many keys: added
Root roles:
- many roles: added
Root role keyids:
- many keids: already added in theupdateframework#1481
MetaFile hashes:
- many hashes: already tested
- zero hashes: added. Testing as invalid test case.
Delegation keys:
- many keys: added
Delegation role keyids:
- many keyids: added
Delegation role paths:
- many paths: already tested
Delegation role path_hash_prefixes:
- many path_hash_path_prefixes: already tested

According to the spec having an empty container for any of these cases:
- Root keys
- Root roles
- Root role keyids
- Delegation keys
- DelegationRole keyids
- DelegationRole paths
- DelegationRole path_hash_prefixes
is not allowed, but for the purpose of interactive object construction
we don't block those use-cases.
We don't want to add tests, because we don't want to
advertise this behavior.

In the future, we are going to add validation that those cases don't
occur which will be called when serializing the object back to
bytes/dictionary/file.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
MVrachev pushed a commit to MVrachev/tuf that referenced this pull request Aug 19, 2021
Test metadata (de)serialization with input data containing containers
with zero or more elements.

Here is the status for the different use cases:
Root keys:
- many keys: added
Root roles:
- many roles: added
Root role keyids:
- many keids: already added in theupdateframework#1481
MetaFile hashes:
- many hashes: already tested
- zero hashes: added. Testing as invalid test case.
Timestamp meta:
- zero elements: already tested
- many elements: added
Snapshot meta:
- zero items: added
- many items: added
Delegation keys:
- many keys: added
Delegation role keyids:
- many keyids: added
Delegation role paths:
- many paths: already tested
Delegation role path_hash_prefixes:
- many path_hash_path_prefixes: already tested
Delegation roles:
- zero roles: added
- multiple roles: added
Targets targets:
- zero items: already tested
- multiple items: added

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
MVrachev pushed a commit to MVrachev/tuf that referenced this pull request Aug 20, 2021
Test metadata (de)serialization with input data containing containers
with zero or more elements.

Here is the status for the different use cases:
Root keys:
- many keys: added
Root roles:
- many roles: added
Root role keyids:
- many keids: already added in theupdateframework#1481
MetaFile hashes:
- many hashes: already tested
- zero hashes: added. Testing as invalid test case.
Timestamp meta:
- zero elements: already tested
- many elements: added
Snapshot meta:
- zero items: added
- many items: added
Delegation keys:
- many keys: added
Delegation role keyids:
- many keyids: added
Delegation role paths:
- many paths: already tested
Delegation role path_hash_prefixes:
- many path_hash_path_prefixes: already tested
Delegation roles:
- zero roles: added
- multiple roles: added
Targets targets:
- zero items: already tested
- multiple items: added

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
MVrachev pushed a commit to MVrachev/tuf that referenced this pull request Aug 20, 2021
Test metadata (de)serialization with input data containing containers
with zero or more elements.

Here is the status for the different use cases:
Root keys:
- many keys: added
Root roles:
- many roles: added
Root role keyids:
- many keids: already added in theupdateframework#1481
MetaFile hashes:
- many hashes: already tested
- zero hashes: added. Testing as invalid test case.
Timestamp meta:
- zero elements: already tested
- many elements: added
Snapshot meta:
- zero items: added
- many items: added
Delegation keys:
- many keys: added
Delegation role keyids:
- many keyids: added
Delegation role paths:
- many paths: already tested
Delegation role path_hash_prefixes:
- many path_hash_path_prefixes: already tested
Delegation roles:
- zero roles: added
- multiple roles: added
Targets targets:
- zero items: already tested
- multiple items: added

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
MVrachev pushed a commit to MVrachev/tuf that referenced this pull request Aug 25, 2021
Test metadata (de)serialization with input data containing containers
with zero or more elements.

Here is the status for the different use cases:
Root keys:
- many keys: added
Root roles:
- many roles: added
Root role keyids:
- many keids: already added in theupdateframework#1481
MetaFile hashes:
- many hashes: already tested
- zero hashes: added. Testing as invalid test case.
Timestamp meta:
- zero elements: already tested
- many elements: added
Snapshot meta:
- zero items: added
- many items: added
Delegation keys:
- many keys: added
Delegation role keyids:
- many keyids: added
Delegation role paths:
- many paths: already tested
Delegation role path_hash_prefixes:
- many path_hash_path_prefixes: already tested
Delegation roles:
- zero roles: added
- multiple roles: added
Targets targets:
- zero items: already tested
- multiple items: added

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
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.

Metadata API: Role keyids is not ordered

2 participants