Skip to content

Metadata API: Role keyids is not ordered #1478

Closed

Description

@jku

We made Role.keyids a set because the keyids are supposed to be unique -- 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).

  • We should have tests that deserialize/serialize metadata with more than one item in each container (like roles keyids) to notice issues like this -- this should be easy now that the serialization tests exist
  • We should fix the issue with Role.keyids -- my assumption is that the issue is Set not being ordered but I'm not 100% on that

Activity

  1. JustinCappos commented on Jul 3, 2021

    @JustinCappos
    Member
  2. jku commented on Jul 5, 2021

    @jku
    MemberAuthor

    The serialization test case is indeed easy: this fails test_role_serialization() almost always:

    "many keyids": '{"keyids": ["a", "b", "c", "d", "e"], "threshold": 1}',
    

    So I think the easiest solution is:

    • revert the decision to use Set for Role.keyids -- python does not have an OrderedSet and using a Dict for this looks really weird
    • instead make the attribute a private _keyids: List[str] and add a public property keyids: List[str] (with getter/setter)
    • enforce uniqueness in the setter, and use the setter in deserialiation
  3. sechkova commented on Jul 6, 2021

    @sechkova
    Contributor

    Here is the commit making signatures deterministic by sorting the set of signing keys in case this may help: 846604a

    But in this case keys would have to be the same sorted set on serialization and deserialization so it may not be the best solution.

  4. jku commented on Jul 6, 2021

    @jku
    MemberAuthor

    I'm sure sorted() is reliable in its sort but the return value is not a set (it's a list) -- so we won't get the benefits we were hoping for by using a set (namely the API safety in that adding non-unique keyids would be very difficult).

    Edit: or maybe you mean we could use set but always serialize using sorted? That might work...

  5. added
    backlog
    on Jul 7, 2021
  6. added this to the Sprint 4 milestone on Jul 7, 2021
  7. removed
    backlog
    on Jul 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions