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

bug: ResetTargetsDelegations changes delegations.roles to null value: deserialization error #402

Closed
asraa opened this issue Sep 28, 2022 · 0 comments · Fixed by #410
Closed
Assignees

Comments

@asraa
Copy link
Contributor

asraa commented Sep 28, 2022

Currently, if you use repo.ResetTargetsDelegations, the targets delegation looks like:

    "delegations": {
      "keys": {},
      "roles": null
    }

The null in the roles field, while valid JSON, is not handled properly by other TUF clients. For example, python-tuf will through a deserialization error:

Traceback (most recent call last):
  File "/home/asraa/git/python-tuf/tuf/api/serialization/json.py", line 37, in deserialize
    metadata_obj = Metadata.from_dict(json_dict)
  File "/home/asraa/git/python-tuf/tuf/api/metadata.py", line 198, in from_dict
    signed=cast(T, inner_cls.from_dict(metadata.pop("signed"))),
  File "/home/asraa/git/python-tuf/tuf/api/metadata.py", line 1960, in from_dict
    delegations = Delegations.from_dict(delegations_dict)
  File "/home/asraa/git/python-tuf/tuf/api/metadata.py", line 1695, in from_dict
    return cls(keys_res, roles_res, succinct_roles_info, delegations_dict)
  File "/home/asraa/git/python-tuf/tuf/api/metadata.py", line 1630, in __init__
    raise ValueError("One of roles and succinct_roles must be set")
ValueError: One of roles and succinct_roles must be set

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/asraa/git/python-tuf/client-test.py", line 27, in <module>
    updater.refresh()
  File "/home/asraa/git/python-tuf/tuf/ngclient/updater.py", line 129, in refresh
    self._load_targets(Targets.type, Root.type)
  File "/home/asraa/git/python-tuf/tuf/ngclient/updater.py", line 395, in _load_targets
    delegated_targets = self._trusted_set.update_delegated_targets(
  File "/home/asraa/git/python-tuf/tuf/ngclient/_internal/trusted_metadata_set.py", line 417, in update_delegated_targets
    new_delegate = Metadata[Targets].from_bytes(data)
  File "/home/asraa/git/python-tuf/tuf/api/metadata.py", line 264, in from_bytes
    return deserializer.deserialize(data)
  File "/home/asraa/git/python-tuf/tuf/api/serialization/json.py", line 40, in deserialize
    raise DeserializationError("Failed to deserialize JSON") from e
tuf.api.serialization.DeserializationError: Failed to deserialize JSON

Let's fix this to use an empty array instead? Or simply remove the entire delegations. This fixes the problem:

diff --git a/repo.go b/repo.go
index cce0020..8b38d50 100644
--- a/repo.go
+++ b/repo.go
@@ -698,8 +698,7 @@ func (r *Repo) ResetTargetsDelegationsWithExpires(delegator string, expires time
                return fmt.Errorf("error getting delegator (%q) metadata: %w", delegator, err)
        }
 
-       t.Delegations = &data.Delegations{}
-       t.Delegations.Keys = make(map[string]*data.PublicKey)
+       t.Delegations = nil
 
        t.Expires = expires.Round(time.Second)

with thedelegations JSON object removed.

cc @ethan-lowman-dd @joshuagl

Detected in sigstore/root-signing#410

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

Successfully merging a pull request may close this issue.

1 participant