Skip to content

verify: raise MetadataError instead of IndexError for trusted roots with no tlogs (#1822) - #1870

Open
agu2347 wants to merge 1 commit into
sigstore:mainfrom
agu2347:fix-verifier-no-tlogs-metadataerror
Open

verify: raise MetadataError instead of IndexError for trusted roots with no tlogs (#1822)#1870
agu2347 wants to merge 1 commit into
sigstore:mainfrom
agu2347:fix-verifier-no-tlogs-metadataerror

Conversation

@agu2347

@agu2347 agu2347 commented Aug 12, 2026

Copy link
Copy Markdown

Bug

Verifier.__init__ raises an unhandled IndexError when given a trusted_root with no transparency logs, instead of a documented sigstore.errors exception.

Fixes #1822

Context

Per @woodruffw's comment on the issue: this is intentional (a Sigstore instance is expected to have at least one tlog), but "we could turn that into a more structured error." Verifier documents its failures as VerificationError (or subclasses), so a caller catching only that gets an unhandled crash.

Fix

TrustedRoot already has an established pattern for this exact situation -- rekor_keyring(), ct_keyring(), and get_fulcio_certs() all raise MetadataError when required data is missing from the trusted root (e.g. "Did not find any Rekor keys in trusted root", "Fulcio certificates not found in trusted root"). This PR applies the same pattern to Verifier.__init__: check trusted_root._inner.tlogs before indexing into it, and raise MetadataError("No transparency logs found in trusted root") instead of letting the IndexError propagate.

Testing

Added two unit tests to test/unit/verify/test_verifier.py, using pretend.stub for trusted_root to avoid any network dependency (matching the file's existing style for non-network tests):

  • test_verifier_init_no_transparency_logs -- a trusted_root with an empty tlogs list raises MetadataError.
  • test_verifier_init_with_transparency_logs -- a trusted_root with a tlogs entry still constructs successfully and picks its base_url, proving the new guard doesn't affect the happy path.

Verified: pytest test/unit --skip-staging -m "not production" passes 177/177 (175 existing + 2 new), 28 skipped (network-marked). Reverting just sigstore/verify/verifier.py reproduces the exact reported IndexError in the new negative test while the positive test still passes, confirming this is a genuine regression guard. ruff format --check, ruff check, and mypy sigstore/verify/verifier.py (the project's actual make lint gate) are all clean.

…ith no tlogs (sigstore#1822)

`Verifier.__init__` picks a Rekor base URL via
`trusted_root._inner.tlogs[0].base_url`. If the given `trusted_root` has
no transparency log entries, this raises a bare `IndexError` instead of
a `sigstore.errors` exception.

`Verifier` otherwise documents its failures as `VerificationError` (or
subclasses), and callers that only catch that get an unhandled crash.
This mirrors the existing, established pattern in `TrustedRoot` itself
(`rekor_keyring` / `ct_keyring` / `get_fulcio_certs` all raise
`MetadataError` when required trusted-root data is missing) -- per
@woodruffw's comment on the issue, this is intentional (a Sigstore
instance is expected to have at least one tlog) but should surface as "a
more structured error" rather than an unhandled IndexError.

Added two unit tests to test_verifier.py:
  * `Verifier(trusted_root=...)` raises `MetadataError` for a
    `trusted_root` with an empty `tlogs` list
  * `Verifier(trusted_root=...)` still succeeds and picks the first
    tlog's `base_url` when `tlogs` is non-empty, proving the new guard
    doesn't affect the happy path

Fixes sigstore#1822
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.

Verifier.__init__ raises unhandled IndexError when the trusted root has no transparency logs

1 participant