Skip to content

Fix duplicate .att/.sig OCI layers for same digest type hints#1601

Merged
tekton-robot merged 1 commit into
tektoncd:mainfrom
ab-ghosh:fix-duplicate-oci-layers-1596
May 26, 2026
Merged

Fix duplicate .att/.sig OCI layers for same digest type hints#1601
tekton-robot merged 1 commit into
tektoncd:mainfrom
ab-ghosh:fix-duplicate-oci-layers-1596

Conversation

@ab-ghosh

@ab-ghosh ab-ghosh commented Mar 28, 2026

Copy link
Copy Markdown
Member

Changes

When a Task declares the same OCI image through multiple type-hint formats, produces duplicate layers in the .att and/or .sig manifests.

This fixes the issue at two levels:

  1. Extraction-level dedup — Added a seen map in ExtractOCIImagesFromResults to skip already-extracted digests across all type-hint parsing loops.
  2. Storage-level dedup — Before appending a new layer in AttestationStorer.Store and SimpleStorer.Store, check if a layer with the same content digest already exists. This handles the case where independent signable types (TaskRunArtifact and OCIArtifact) both store to the same .att/.sig tag.

Fixes #1596

Submitter Checklist

As the author of this PR, please check off the items in this checklist:

  • Has Docs included if any changes are user facing
  • Has Tests included if any functionality added or changed
  • Follows the commit message standard
  • Meets the Tekton contributor standards (including
    functionality, content, code)
  • Release notes block below has been updated with any user facing changes (API changes, bug fixes, changes requiring upgrade notices or deprecation warnings)
  • Release notes contains the string "action required" if the change requires additional action from users switching to the new release

Release Notes

Fix: prevent duplicate .sig layers when a Task image is reported via multiple result type-hints

@tekton-robot tekton-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 28, 2026
@ab-ghosh ab-ghosh force-pushed the fix-duplicate-oci-layers-1596 branch from 84b9ba9 to 0151950 Compare March 28, 2026 18:58
@anithapriyanatarajan

Copy link
Copy Markdown
Contributor

/approve

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 1, 2026
@anithapriyanatarajan anithapriyanatarajan removed the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 1, 2026
@anithapriyanatarajan

Copy link
Copy Markdown
Contributor

/kind bug

@tekton-robot tekton-robot added the kind/bug Categorizes issue or PR as related to a bug. label Apr 1, 2026
@ab-ghosh

ab-ghosh commented Apr 1, 2026

Copy link
Copy Markdown
Member Author

/cc @jkhelil

@infernus01 infernus01 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small NIT.

Comment thread pkg/artifacts/signable.go
continue
}
if seen[dgst.DigestStr()] {
continue

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT - Adding a log line for eg. logger.Debugf("Skipping duplicate digest %s", dgst.DigestStr()) would help people understand why an image wasn't processed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion, addressed.

Comment thread pkg/artifacts/signable.go
continue
}
if seen[dgst.DigestStr()] {
continue

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same NIT here.

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 2, 2026
@ab-ghosh ab-ghosh force-pushed the fix-duplicate-oci-layers-1596 branch from 0151950 to 7d970c4 Compare April 2, 2026 08:27
@infernus01

Copy link
Copy Markdown
Member

/lgtm

@tekton-robot

Copy link
Copy Markdown

@infernus01: changing LGTM is restricted to collaborators

Details

In response to this:

/lgtm

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Comment thread pkg/artifacts/signable.go Outdated
logger.Errorf("error getting digest: %v", err)
continue
}
if seen[dgst.DigestStr()] {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ab-ghosh dgst.DigestStr() returns only sha256:xxx, stripping the repository name entirely. This means two legitimately different images that happen to produce the same content digest (e.g., a mirrored image gcr.io/my/img@sha256:abc and quay.io/my/img@sha256:abc) will be silently deduplicated, dropping one of them from the signing set. so could you consider dgst.Name() that uses the full repo@SHA256:XYZ. Also please include test case addressing this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's right, thanks for the suggestion. I have updated it to use dgst.Name() and also added a test case to cover this scenario.

@tekton-robot tekton-robot removed the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 10, 2026
@ab-ghosh ab-ghosh force-pushed the fix-duplicate-oci-layers-1596 branch from 7d970c4 to 6a97a81 Compare April 13, 2026 07:06
@anithapriyanatarajan

Copy link
Copy Markdown
Contributor

@ab-ghosh - with #1578 merged now, could we check the feasibility to dedup any image url /digest that could be duplicated with a TR that has results:

results:

  • name: IMAGE_DIGEST
  • name: IMAGE_URL
  • name: build-image-ARTIFACT_OUTPUTS
    type: object
    properties:
    uri: {}
    digest: {}
    isBuildArtifact: {}

Please consider this task definition as a sample - https://gist.github.com/anithapriyanatarajan/1650aeb3ebdbcea05d4a9baef649507c#file-gistfile1-txt-L123-L190

@ab-ghosh ab-ghosh force-pushed the fix-duplicate-oci-layers-1596 branch 2 times, most recently from d0d5463 to edf93b1 Compare April 22, 2026 12:48
@ab-ghosh

Copy link
Copy Markdown
Member Author

Added dedup for the ARTIFACT_OUTPUTS. Also added unit test which covers the exact scenario from your sample task (same image in both IMAGE_URL/IMAGE_DIGEST and build-image-ARTIFACT_OUTPUTS)

  When a Task declares the same OCI image through multiple type-hint
  formats (IMAGE_URL/IMAGE_DIGEST, IMAGES, and *ARTIFACT_OUTPUTS),
  Chains produces duplicate layers in cosign .att/.sig manifests.
  This adds dedup at two levels:

  1. Extraction: track seen digests in ExtractOCIImagesFromResults to
     avoid returning the same digest from different type-hint formats
  2. Storage: check existing layers in AttestationStorer and SimpleStorer
     before appending, preventing duplicates from independent signable
     types (TaskRunArtifact + OCIArtifact) storing to the same tag

  Also adds debug logging when existing layer checks fail instead of
  silently swallowing errors.

  Fixes tektoncd#1596
@ab-ghosh ab-ghosh force-pushed the fix-duplicate-oci-layers-1596 branch from edf93b1 to b0a0331 Compare April 22, 2026 12:52
@anithapriyanatarajan

Copy link
Copy Markdown
Contributor

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label May 11, 2026
@ab-ghosh

Copy link
Copy Markdown
Member Author

/cc @jkhelil

@anithapriyanatarajan

Copy link
Copy Markdown
Contributor

/approve

Approving this PR based after feature testing on a kind cluster following steps here - https://gist.github.com/anithapriyanatarajan/81fc8c92ceccf760ce74f40c7b30a2f9

@tekton-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: anithapriyanatarajan, infernus01

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [anithapriyanatarajan]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 26, 2026
@tekton-robot tekton-robot merged commit 3fbaa94 into tektoncd:main May 26, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicate .att / .sig layers when multiple type hints resolve to the same digest

4 participants