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

ngclient should cope better with broken repos #2195

Closed
jku opened this issue Nov 27, 2022 · 0 comments · Fixed by #2197
Closed

ngclient should cope better with broken repos #2195

jku opened this issue Nov 27, 2022 · 0 comments · Fixed by #2197

Comments

@jku
Copy link
Member

jku commented Nov 27, 2022

  • a delegation exists in a repository
  • but the delegated roles metadata is not in the repository and not included in the snapshot
  • Updater.get_targetinfo() is called with a path that is delegated to this nonexistent role

this currently leads to following error. We should fail with a RepositoryError of some kind instead.

Traceback (most recent call last):
  File "/home/jkukkonen/src/python-tuf/tuf/ngclient/updater.py", line 381, in _load_targets
    data = self._load_local_metadata(role)
  File "/home/jkukkonen/src/python-tuf/tuf/ngclient/updater.py", line 277, in _load_local_metadata
    with open(os.path.join(self._dir, f"{encoded_name}.json"), "rb") as f:
FileNotFoundError: [Errno 2] No such file or directory: '/home/jkukkonen/.local/share/tuf-upload-example/d412c05c/secrole.json'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  [... unrelated application stack race removed ...]
    updater.get_targetinfo(targetname)
  File "/home/jkukkonen/src/python-tuf/tuf/ngclient/updater.py", line 171, in get_targetinfo
    return self._preorder_depth_first_walk(target_path)
  File "/home/jkukkonen/src/python-tuf/tuf/ngclient/updater.py", line 436, in _preorder_depth_first_walk
    targets = self._load_targets(role_name, parent_role).signed
  File "/home/jkukkonen/src/python-tuf/tuf/ngclient/updater.py", line 392, in _load_targets
    metainfo = self._trusted_set.snapshot.signed.meta[f"{role}.json"]
KeyError: 'secrole.json'

jku added a commit to jku/python-tuf that referenced this issue Nov 28, 2022
If role is delegated but missing from snapshot, we currently raise a
undocumented KeyError: a generic RepositoryError seems better as callers
are expected to handle it (and adding a more specific error seems
useless as this is a repository software bug, not just expired metadata or
something).

The same check is also done later in TrustedMetadataSet but I think
keeping the check in both is clearest.

Fixes theupdateframework#2195

Signed-off-by: Jussi Kukkonen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant