Skip to content

fix: honor --attachment-tag-prefix in cosign clean - #5060

Open
hamodywe wants to merge 1 commit into
sigstore:mainfrom
hamodywe:fix/clean-attachment-tag-prefix
Open

fix: honor --attachment-tag-prefix in cosign clean#5060
hamodywe wants to merge 1 commit into
sigstore:mainfrom
hamodywe:fix/clean-attachment-tag-prefix

Conversation

@hamodywe

Copy link
Copy Markdown

Fixes #4344.

Summary

cosign clean --attachment-tag-prefix=<p> deleted the unprefixed attachments instead of the prefixed ones it was asked to remove.

CleanCmd builds its own ociremote options:

ociRemoteOpts := ociremote.WithRemoteOptions(remoteOpts...)

That carries the registry/transport options but never RefOpts.TagPrefix, so SignatureTag, AttestationTag, SBOMTag and ResolveDigest all resolve the default sha256-<digest>.sig|.att|.sbom tags. sign/attest do apply the prefix when they push those tags, so clean was looking at a different set of tags than the ones it created.

This applies the prefix when it is set, leaving the no-prefix path byte-identical.

Why it is worth fixing a deprecated flag

The flag is deprecated in favour of OCI referrers, but the failure mode is deleting an attachment the caller never named, and a registry delete is not recoverable. That seemed worth a small fix rather than leaving it until removal.

Scope

Deliberately narrow: only the prefix is threaded through. I did not switch CleanCmd to regOpts.ClientOpts() even though that would be the tidier call, because it would additionally start honouring COSIGN_REPOSITORY here — a behaviour change that overlaps #5037/#5033, where the target-registry semantics are still being defined. Happy to fold that in if you would rather it moved in one step.

Tests

cmd/cosign/cli/clean_test.go covers both directions: with --attachment-tag-prefix=cve- the resolved tags are cve-sha256-….sig|.att|.sbom, and with no prefix they stay exactly as before. Both fail against the pre-fix behaviour for the prefixed case and pass after.

go build ./cmd/..., go vet ./cmd/cosign/cli/ and the new tests are clean locally.

CleanCmd built its own ociremote options with only WithRemoteOptions, so
the tag prefix was never applied. SignatureTag, AttestationTag, SBOMTag
and ResolveDigest then resolved the default sha256-<digest>.sig/.att/.sbom
tags, and a clean run that passed --attachment-tag-prefix deleted the
unprefixed attachments instead of the ones it named.

sign and attest apply the prefix when they push these tags, so clean has
to apply it when it resolves them.

Deleting an attachment the caller did not name is not recoverable, which
is why this is worth fixing even though the flag is deprecated in favour
of OCI referrers.

Fixes sigstore#4344

Signed-off-by: hamodywe <iosapk.org@gmail.com>
@hamodywe
hamodywe requested a review from a team as a code owner August 16, 2026 02:32
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.

--attachment-tag-prefix is ignored during cosign clean

1 participant