Skip to content

Relying on mandatory DelegatedRole.name attribute when TAP 15 describes it as optional #1943

Closed

Description

@MVrachev

Description of issue or feature request:
We are working to implement TAP 15 (see #1909).
There it's said that:

If the succinct_hash_delegations field is present in a delegation, the name field will not be used as a rolename, and so is not required.

meaning that the DelegatedRole.name attribute is not required.
That seems to be a problem for us as until now we are relying on its existence to uniquely identify roles:
(see Delegations.from_dict() implementation)

def from_dict(cls, delegations_dict: Dict[str, Any]) -> "Delegations":

One solution to this problem could be providing an additional ID number that will serve as a unique identifier for roles.
This approach is widely used by databases.

But then we have the next question what to do about DelegatedRole.to_dict() where we currently provide name:

"name": self.name,

In summary what we should do is:

  • decide what unique identifier to use for delegated roles inside Delegations
  • decide what to do with DelegatedRole.to_dict

Activity

  1. lukpueh commented on Apr 6, 2022

    @lukpueh
    Member

    Yes, we definitely still need distinct names for each "bin-n" role, otherwise the client can't download the targets metadata needed for a target in a bin. The challenge with TAP 15 is that the delegating targets metadata does not list all its delegatees anymore, but rather a number (delegation_hash_prefix_len) that allows to compute how many delegatees (bins) there are.

    Currently, the idea is to compute the name for each bin using a configured prefix bin_name_prefix together with the bin index. See theupdateframework/taps#132 for some remaining discussions about the name.

  2. MVrachev commented on Apr 6, 2022

    @MVrachev
    CollaboratorAuthor

    Currently, the idea is to compute the name for each bin using a configured prefix bin_name_prefix together with the bin index. See theupdateframework/taps#132 for some remaining discussions about the name.

    The problem is that it's possible to have DelegatedRoles objects without a name attribute set and the calculation of the bin index requires a target path...

  3. lukpueh commented on Apr 6, 2022

    @lukpueh
    Member

    I think the problem is that DelegatedRole so far was used for exactly one delegated role, but with TAP 15 there would only be one DelegatedRole object for all bin-n roles.

  4. MVrachev commented on Apr 6, 2022

    @MVrachev
    CollaboratorAuthor

    I think the problem is that DelegatedRole so far was used for exactly one delegated role, but with TAP 15 there would only be one DelegatedRole object for all bin-n roles.

    Yes, you are correct!
    I think the solution then is clear:

    1. when we don't use succinct_hash_delegations role names are provided and everything works the same way as it does now - Delegations.roles attribute is a Dict[str, DelegatedRole].
    2. if we use succinct_hash_delegations then Delegations.roles attribute becomes only DelegatedRole.

    This means that Delegation.roles will be of type Union[Dict[str, DelegatedRole], DelegatedRole] and we would have to add a couple of more if checks here and there to comply with mypy.

  5. self-assigned this
    on Apr 6, 2022
  6. jku commented on Apr 7, 2022

    @jku
    Member

    if we use succinct_hash_delegations then Delegations.roles attribute becomes only DelegatedRole.

    The idea that a delegations dictionary that contains a succinct delegation can only contain that delegation and no others seems reasonable but I don't think it comes from TAP 15? Note that I'm not opposed to making implementation restrictions, just want to be clear when we do those.

    A quick unfinished alternative idea: Internally use special DelegatedRole.name = "" for succinct delegation (and prevent that being otherwise used). This would change the requirement to "delegations dictionary can contain a maximum of one succinct delegation but could contain other normal delegations: these can be ordered by normal means".

  7. jku commented on Apr 7, 2022

    @jku
    Member

    Yet more alternatives: use the first bin-n-name as the roles dictionary key

    • this allows even multiple succinct delegations in the same delegations dictionary
    • using the bin-name seems safe since we already implictly require the repository to not have conflicts with bin-names

    This dictionary key would obviously be just an implementation detail: the serialized format would be as described in tap15

  8. MVrachev commented on Apr 7, 2022

    @MVrachev
    CollaboratorAuthor

    if we use succinct_hash_delegations then Delegations.roles attribute becomes only DelegatedRole.

    The idea that a delegations dictionary that contains a succinct delegation can only contain that delegation and no others seems reasonable but I don't think it comes from TAP 15? Note that I'm not opposed to making implementation restrictions, just want to be clear when we do those.

    You are correct! I assumed only DelegatedRole could exist when succinct_hash_delegations are used, but when you look closer to the proposed delegations scheme:

    { "keys" : {
           KEYID : KEY,
           ... },
       "roles" : [{
           ("name": ROLENAME,)
           "keyids" : [ KEYID, ... ] ,
           "threshold" : THRESHOLD,
           ("path_hash_prefixes" : [ HEX_DIGEST, ... ], |
           "paths" : [ PATHPATTERN, ... ], |
           "succinct_hash_delegations" : {
             "delegation_hash_prefix_len" : BIT_LENGTH,
             "bin_name_prefix" : NAME_PREFIX
           })
           "terminating": TERMINATING,
       }, ... ]
     }
    

    you see that after the delegated role describing the succinct hash information there is ... meaning there could be more than one.

    A quick unfinished alternative idea: Internally use special DelegatedRole.name = "" for succinct delegation (and prevent that being otherwise used). This would change the requirement to "delegations dictionary can contain a maximum of one succinct delegation but could contain other normal delegations: these can be ordered by normal means".

    I think I prefer this idea more than the one with the usage of bin-n-name prefix as the rolename.
    Given that TAP 15 hinted that DelegatedRole.name is unused in the case of existing succinct hash delegatations I think it makes more sense to have it that way.

    Yet more alternatives: use the first bin-n-name as the roles dictionary key

    • this allows even multiple succinct delegations in the same delegations dictionary

    I am not sure you will ever need to use multiple succinct hash delegations.
    I only see it as a possible complication with no real benefit.
    Given that you can have 2^32 - 1 bins there are more than enough and even then you can continue delegating more levels downwards.

    • using the bin-name seems safe since we already implictly require the repository to not have conflicts with bin-names

    This dictionary key would obviously be just an implementation detail: the serialized format would be as described in tap15

    Still, if we decide to use bin-name how do you imagine this to happen?
    Probably the same way we did with normal hash bin delegations?

  9. MVrachev commented on Apr 7, 2022

    @MVrachev
    CollaboratorAuthor

    @lukpueh what do you think about Jussi's suggestions?
    @lukpueh and @jku I hope we can soon have a consensus on how to solve this issue as it's blocking my progress on TAP 15 as mypy warnings appeared,

  10. jku commented on Apr 8, 2022

    @jku
    Member

    I am not sure you will ever need to use multiple succinct hash delegations.
    I only see it as a possible complication with no real benefit.

    That is indeed valid feedback for the TAP itself... even combining normal delegations and succinct ones feels quite weird.

    But strictly speaking the format in the TAP is currently designed to allow multiple succinct delegations so we'll have to at least document this diversion if we implement it that way.

    @mnm678 maybe has an opinion on combining a succinct delegation with either another succinct delegation or normal delegations -- what was the TAP intention here?

  11. jku commented on Apr 8, 2022

    @jku
    Member

    I wanted to make one thing clear:

    • requiring a role name is just an implementation detail in python-tuf -- we can change that if needed, and that's not a huge issue
    • however, I also don't understand why it was made optional: this makes implementations more difficult to code just to save a few bytes

    so one option is that python-tuf keeps requiring a role name and we suggest a modification to the TAP.

  12. MVrachev commented on Apr 8, 2022

    @MVrachev
    CollaboratorAuthor

    I think it makes sense that name is missing when succinct_hash_delegations is used.
    If it does exist when succinct_hash_delegations is used It's won't bring any semantical value and it could be lead to confusion about which to use Delegated.name or Delegated_get_rolename(the new API call I am adding for TAP 15) when you want to get the name of the delegated role responsible for a target.

    I would love to hear @mnm678 about that.

  13. mnm678 commented on Apr 8, 2022

    @mnm678
    Contributor

    This is a great discussion!

    @mnm678 maybe has an opinion on combining a succinct delegation with either another succinct delegation or normal delegations -- what was the TAP intention here?

    The TAP purposefully left the option for multiple succinct delegations, as at the time I didn't see the need to restrict this. There may be a case when a repository would have multiple succinct delegations signed by different keys (especially a large repository like DockerHub). But if this is a sticking point for the implementation, I don't think it's very important and it hasn't specifically been requested. @trishankatdatadog has some of the real-world use cases for this TAP and so might have an opinion there.

    name was left out for succinct hash delegations as it's not necessary for determining the next metadata file to download. However, they way this is worded "the name field will not be used as a rolename, and so is not required" does leave it open for implementations to use this field internally. So I think identifying these either through a rolename of "" or a rolename of the first bin-n-name would be in line with the TAP (though I have a personal preference of "" as it seems harder to confuse).

    In general, I think it's fine to implement TAP 15 with a couple of additional restrictions if that leads to simpler code. We can even suggest these adaptions in the TAP.

  14. trishankatdatadog commented on Apr 8, 2022

    @trishankatdatadog
    Contributor

    Sorry, haven't had time to fully follow everything, but why can't implementations like python-tuf do the following?

    Inside Delegations.from_dict(), you would have internal helper methods that would know how to handle the different types of delegations. If regular hashed-bin/targets delegations, you get the name for free. Otherwise, the helper for succinct hashed delegations knows how to do it.

    Am I missing something?

  15. MVrachev commented on Apr 8, 2022

    @MVrachev
    CollaboratorAuthor

    Sorry, haven't had time to fully follow everything, but why can't implementations like python-tuf do the following?

    Inside Delegations.from_dict(), you would have internal helper methods that would know how to handle the different types of delegations. If regular hashed-bin/targets delegations, you get the name for free. Otherwise, the helper for succinct hashed delegations knows how to do it.

    Am I missing something?

    The problem comes from the fact that we store delegated roles as a dictionary attribute inside the Delegations class.
    In this dictionary, the keys are the delegated role names and values are DelegatedRole objects or Dict[str, DelegatedRole]
    According to TAP 15 if succinct hash delegations are used then name becomes an optional attribute meaning we no longer have a key for that dictionary.

    Summarized, the solutions proposed what to do when succinct hash delegation is used are as follows:

    1. make roles a Union or Union[Dict[str, DelegatedRole], DelegatedRole] meaning that in the case of succinct hash delegations we will no longer allow any other roles (which is a constrain not required from TAP 15)
    2. use the special delegated role name "" denoting the delegated role with the succinct hash delegations info. The other roles are forbidden from using the "" as a role name, but they can coexist with the succinct hash delegation role
    3. using the first bin-n-name or (if I understood correctly) constructing a name from the succinct_hash_delegations["bin_name_prefix"] and the first bin name. Looking into the TAP 15 example this would be alice.hbd-00.

    I think I am for option 2. It doesn't limit anything. There is a reasonable special value that can be used and there is no reason why anyone will explicitly want a delegated role with the name "".

  16. 16 remaining items

  17. jku commented on May 2, 2022

    @jku
    Member

    A solution to this would be to make this TAP part of a major version change.

    This certainly does it but I don't think it's necessary: If succinct delegations are not used, the old clients would still work fine with any of the formats we've discussed. Bumping major version would mean they would be made artificially incompatible which feels quite drastic.

    I think it would be acceptable if the spec major version stays the same, but we just document that old clients will not work if repository uses succinct delegations (and then we really make sure that the format we design can't accidentally half-work with old clients like I described earlier).

  18. MVrachev commented on May 9, 2022

    @MVrachev
    CollaboratorAuthor

    Why don't we take a literal step back here? Maybe, and Jussi suggests this in his last comment, the reason why implementing this is tricky is because the metadata format in TAP 15 is tricky. Maybe (putting on my ER-modeler hat) the "succinct hash delegation object" is just too different from "delegation role" objects? What about this alternative format:

    {
      "keys" : {
          KEYID : KEY,
          ...
      },
      "roles" : [
        {
          "name": ROLENAME,
          "keyids" : [ KEYID, ... ] ,
          "threshold" : THRESHOLD,
          ("path_hash_prefixes" : [ HEX_DIGEST, ... ] |
          "paths" : [ PATHPATTERN, ... ]),
          "terminating": TERMINATING,
        }, ...
      ],
      "succinct_hash_delegations": [ # better name pending
        {
          "keyids" : [ KEYID, ... ],
          "threshold" : THRESHOLD,
          "terminating": TERMINATING,
          "delegation_hash_prefix_len" : BIT_LENGTH, # better name pending
          "bin_name_prefix" : NAME_PREFIX # better name pending
        }, ... 
      ]
    }

    I am aware that the objects share keyids, threshold,terminating fields, but a non-normalized data definition seems preferable to mutual exclusive relationships between multiple fields. And in code we could summarize them in a common parent class for DelegatedRole and DelegatedBins (better name pending).

    I have implemented @lukpueh suggestion from the comment here https://github.com/MVrachev/tuf/tree/new-suggestion.

    In my prototype, I have additionally decided that:

    • roles and succinct_hash_delegations attributes in the Delegations class are mutually exclusive
    • there could be only one succinct_hash_delegations
    • I didn't create a new common class between DelegatedRole and SuccinctHashDelegation classes as I didn't notice any meaningful improvements

    @jku, @lukpueh, @mnm678 what do you think?

  19. jku commented on May 10, 2022

    @jku
    Member

    Some initial comments:

    • it's not obviously "less code", in fact it's 100 lines more (not necessarily bad, just pointing it out)
    • The core SW design decision seems to be to make Delegations more important: it has an API now
    • a lot of the complexity has moved to Delegations serialization, this seems natural and "easy" to understand
    • I think the Delegations API requires work but it seems like it is viable. Some comments on that
      • get_all_delegations internally finds roles to return the roles names -- this name is then used by calling code to find the same role... seems needlessly complex
      • find_delegated_role return value Optional[Union[DelegatedRole, SuccinctHashDelegations]] is definitely a code smell.
      • find_delegated_role runs a for-loop (via the iterator) potentially 4 billion times. The loop seems unnecessary
    • add_key() and remove_key() suddenly became quite complex, I did not expect that. The APIs now don't make complete sense either -- why does the caller supply a rolename if it's then not used for anything? I don't have great suggestions, just pointing out an issue

    Any comments on how complex this felt to implement vs the other approach @MVrachev ? Assuming we manage to polish the API, I feel like this looks a little more manageable to me -- the complexity is now contained in places where I expect it (although the key management issues are an unfortunate side effect).

  20. MVrachev commented on May 11, 2022

    @MVrachev
    CollaboratorAuthor

    Some initial comments from me as well on the prototype based on Lukas suggestion:

    it's not obviously "less code", in fact it's 100 lines more (not necessarily bad, just pointing it out)

    Agree, I spent a good amount of time optimizing the code and making it smaller.
    For example, I wanted to escape of the need of an additional class common for DelegatedRole and SuccinctHashDelegation. It seemed a waste given that Role already has keyid and threshold in it and the only missing common argument was terminating .

    get_all_delegations internally finds roles to return the roles names -- this name is then used by calling code to find the same role... seems needlessly complex

    Agree, I wanted to simplify it, but I wasn't sure how as if I just return succinct hash delegation instead of the name then I will add the first bin role name to be visited instead of the actual bin name reponsible for that target path.

    find_delegated_role return value Optional[Union[DelegatedRole, SuccinctHashDelegations]] is definitely a code smell.

    Yep, agree it looks ugly when I am not using a common class between those two. I can't say I just return Role as Role doesn't have terminating which we later use in preoreder_depth_first_search.

    add_key() and remove_key() suddenly became quite complex, I did not expect that. The APIs now don't make complete sense either -- why does the caller supply a rolename if it's then not used for anything? I don't have great suggestions, just pointing out an issue

    Yes, the suddenly added complexity of those two API calls probably shows that those functions tries to cover a more generic case than it should.

    Any comments on how complex this felt to implement vs the other approach @MVrachev ?

    It felt that in some places I had to add more code just to make sure I am handling all cases related that only one of roles and succinct_hash_delegations can be set. There are many examples of this like Targets.add_key, Targets.remove_key() and RepositorySimulator which now needs a new call add_succinct_hash_info_to_delegations.

    Assuming we manage to polish the API, I feel like this looks a little more manageable to me -- the complexity is now contained in places where I expect it (although the key management issues are an unfortunate side effect).

    I have a feeling that this is a more logical design to rely on Delegations to do the heavy lifting.
    Using DelegatedRole for succinct_hash_delegation felt little unatural.

  21. jku commented on May 12, 2022

    @jku
    Member

    get_all_delegations internally finds roles to return the roles names -- this name is then used by calling code to find the same role... seems needlessly complex

    Agree, I wanted to simplify it, but I wasn't sure how as if I just return succinct hash delegation instead of the name then I will add the first bin role name to be visited instead of the actual bin name reponsible for that target path.

    find_delegated_role return value Optional[Union[DelegatedRole, SuccinctHashDelegations]] is definitely a code smell.

    Yep, agree it looks ugly when I am not using a common class between those two. I can't say I just return Role as Role doesn't have terminating which we later use in preoreder_depth_first_search.

    There could be some alternative design here...

    Throwing suggestions on the wall: terminating is only needed once in updater so what if you return a tuple of optional rolename, terminating from get_all_delegations()? Then find_delegated_role() is no longer needed outside metadata.py so you could try refactoring the one remaining use case inside metadata.py...

  22. MVrachev commented on May 16, 2022

    @MVrachev
    CollaboratorAuthor

    There could be some alternative design here...

    Throwing suggestions on the wall: terminating is only needed once in updater so what if you return a tuple of optional rolename, terminating from get_all_delegations()? Then find_delegated_role() is no longer needed outside metadata.py so you could try refactoring the one remaining use case inside metadata.py...

    There was a TAP 15 design meeting. What we have decided is summarized here: theupdateframework/taps#154 (review).

    We have decided to drop the terminating field from succinct hash delegations.

  23. added a commit that references this issue on May 17, 2022
  24. MVrachev commented on Jun 17, 2022

    @MVrachev
    CollaboratorAuthor

    We have decided that succinct hash delegations will be part of the Delegations object and as such it's no longer connected to DelegatedRole and the problem described in this issue description.
    Closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

discussion

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions