-
Notifications
You must be signed in to change notification settings - Fork 157
feat: embed Rekor bundle in OCI attestation layer annotations #1610
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
Open
ab-ghosh
wants to merge
1
commit into
tektoncd:main
Choose a base branch
from
ab-ghosh:feat/embed-rekor-bundle-oci-attestation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ import ( | |
|
|
||
| "github.com/hashicorp/go-multierror" | ||
| intoto "github.com/in-toto/attestation/go/v1" | ||
| cbundle "github.com/sigstore/cosign/v2/pkg/cosign/bundle" | ||
| "github.com/tektoncd/chains/pkg/artifacts" | ||
| "github.com/tektoncd/chains/pkg/chains/annotations" | ||
| "github.com/tektoncd/chains/pkg/chains/formats" | ||
|
|
@@ -142,6 +143,18 @@ func (o *ObjectSigner) Sign(ctx context.Context, tektonObj objects.TektonObject) | |
| // Extract all the "things" to be signed. | ||
| // We might have a few of each type (several binaries, or images) | ||
| objects := signableType.ExtractObjects(ctx, tektonObj) | ||
|
|
||
| // Create the Rekor client once before iterating over objects since it is | ||
| // stateless and config-driven. | ||
| var tlogClient rekorClient | ||
| if shouldUploadTlog(cfg, tektonObj) { | ||
| var err error | ||
| tlogClient, err = getRekor(cfg.Transparency.URL) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| // Go through each object one at a time. | ||
| for _, obj := range objects { | ||
|
|
||
|
|
@@ -186,6 +199,29 @@ func (o *ObjectSigner) Sign(ctx context.Context, tektonObj objects.TektonObject) | |
| } | ||
| measureMetrics(ctx, metrics.SignedMessagesCount, o.Recorder) | ||
|
|
||
| // Upload to Rekor before storage so the bundle is available for OCI attestation annotations. | ||
| // On upload failure, storage proceeds but the bundle annotation will be absent — | ||
| // consumers that rely on the bundle for offline verification will get an attestation without it. | ||
| var rekorBundle *cbundle.RekorBundle | ||
| if tlogClient != nil { | ||
| entry, err := tlogClient.UploadTlog(ctx, signer, signature, rawPayload, signer.Cert(), string(payloadFormat)) | ||
| if err != nil { | ||
| logger.Warnf("error uploading entry to tlog: %v", err) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PLease document this behaviour, if an error occur, it doesnt block storage but bundle will be unavailable." Consumers that rely on the bundle annotation being present will silently get an attestation without a bundle. |
||
| o.recordError(ctx, signableType, metrics.TlogError) | ||
| merr = multierror.Append(merr, err) | ||
| } else { | ||
| logger.Infof("Uploaded entry to %s with index %d", cfg.Transparency.URL, *entry.LogIndex) | ||
| extraAnnotations[annotations.ChainsTransparencyAnnotation] = fmt.Sprintf("%s/api/v1/log/entries?logIndex=%d", cfg.Transparency.URL, *entry.LogIndex) | ||
| rekorBundle = cbundle.EntryToBundle(entry) | ||
| if rekorBundle != nil { | ||
| logger.Infof("Resolved Rekor bundle for offline verification (logIndex: %d)", rekorBundle.Payload.LogIndex) | ||
| } else { | ||
| logger.Warn("Rekor entry missing verification data, skipping bundle for offline verification") | ||
| } | ||
| measureMetrics(ctx, metrics.PayloadUploadedCount, o.Recorder) | ||
| } | ||
| } | ||
|
|
||
| // Now store those! | ||
| for _, backend := range sets.List[string](signableType.StorageBackend(cfg)) { | ||
| b, ok := o.Backends[backend] | ||
|
|
@@ -203,6 +239,7 @@ func (o *ObjectSigner) Sign(ctx context.Context, tektonObj objects.TektonObject) | |
| Cert: signer.Cert(), | ||
| Chain: signer.Chain(), | ||
| PayloadFormat: payloadFormat, | ||
| RekorBundle: rekorBundle, | ||
| } | ||
| if err := b.StorePayload(ctx, tektonObj, rawPayload, string(signature), storageOpts); err != nil { | ||
| logger.Error(err) | ||
|
|
@@ -213,24 +250,6 @@ func (o *ObjectSigner) Sign(ctx context.Context, tektonObj objects.TektonObject) | |
| } | ||
| } | ||
|
|
||
| if shouldUploadTlog(cfg, tektonObj) { | ||
| rekorClient, err := getRekor(cfg.Transparency.URL) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| entry, err := rekorClient.UploadTlog(ctx, signer, signature, rawPayload, signer.Cert(), string(payloadFormat)) | ||
| if err != nil { | ||
| logger.Warnf("error uploading entry to tlog: %v", err) | ||
| o.recordError(ctx, signableType, metrics.TlogError) | ||
| merr = multierror.Append(merr, err) | ||
| } else { | ||
| logger.Infof("Uploaded entry to %s with index %d", cfg.Transparency.URL, *entry.LogIndex) | ||
| extraAnnotations[annotations.ChainsTransparencyAnnotation] = fmt.Sprintf("%s/api/v1/log/entries?logIndex=%d", cfg.Transparency.URL, *entry.LogIndex) | ||
| measureMetrics(ctx, metrics.PayloadUploadedCount, o.Recorder) | ||
| } | ||
| } | ||
|
|
||
| } | ||
| if merr.ErrorOrNil() != nil { | ||
| if retryErr := annotations.HandleRetry(ctx, tektonObj, o.Pipelineclientset, extraAnnotations); retryErr != nil { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a sentence that this applies to attestations only (in-toto / DSSE-wrapped SLSA); simplesigning (OCI image signature via simplesigning format) does not currently embed the bundle. Without this, users may set up Fulcio+Rekor+OCI storage, observe that cosign verify (not verify-attestation) doesn't find the bundle, and be confused.