-
Notifications
You must be signed in to change notification settings - Fork 155
Handle signing and attesting blobs #1395
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
Merged
Merged
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 |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| // Copyright 2025 The Tekton Authors | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package oci | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "net/http/httptest" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/google/go-containerregistry/pkg/name" | ||
| "github.com/google/go-containerregistry/pkg/registry" | ||
| "github.com/google/go-containerregistry/pkg/v1/random" | ||
| "github.com/google/go-containerregistry/pkg/v1/remote" | ||
| "github.com/google/go-containerregistry/pkg/v1/types" | ||
| intoto "github.com/in-toto/attestation/go/v1" | ||
| "github.com/tektoncd/chains/pkg/chains/signing" | ||
| "github.com/tektoncd/chains/pkg/chains/storage/api" | ||
| logtesting "knative.dev/pkg/logging/testing" | ||
| ) | ||
|
|
||
| func TestAttestationStorer_Store(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| writeToRegistry func(*testing.T, string) name.Digest | ||
| wantErr error | ||
| }{ | ||
| { | ||
| name: "image manifest", | ||
| writeToRegistry: func(t *testing.T, registryName string) name.Digest { | ||
| t.Helper() | ||
| img, err := random.Image(1024, 2) | ||
| if err != nil { | ||
| t.Fatalf("failed to create random image: %s", err) | ||
| } | ||
| imgDigest, err := img.Digest() | ||
| if err != nil { | ||
| t.Fatalf("failed to get image digest: %v", err) | ||
| } | ||
| ref, err := name.NewDigest(fmt.Sprintf("%s/test/img@%s", registryName, imgDigest)) | ||
| if err != nil { | ||
| t.Fatalf("failed to parse digest: %v", err) | ||
| } | ||
| if err := remote.Write(ref, img); err != nil { | ||
| t.Fatalf("failed to write image to mock registry: %v", err) | ||
| } | ||
| return ref | ||
| }, | ||
| }, | ||
| { | ||
| name: "image layer", | ||
| writeToRegistry: func(t *testing.T, registryName string) name.Digest { | ||
| t.Helper() | ||
| layer, err := random.Layer(1024, types.OCILayer) | ||
| if err != nil { | ||
| t.Fatalf("failed to create random layer: %v", err) | ||
| } | ||
| layerDigest, err := layer.Digest() | ||
| if err != nil { | ||
| t.Fatalf("failed to get layer digest: %v", err) | ||
| } | ||
| ref, err := name.NewDigest(fmt.Sprintf("%s/test/img@%s", registryName, layerDigest)) | ||
| if err != nil { | ||
| t.Fatalf("failed to parse digest: %v", err) | ||
| } | ||
| if err := remote.WriteLayer(ref.Repository, layer); err != nil { | ||
| t.Fatalf("failed to write layer to mock registry: %v", err) | ||
| } | ||
| return ref | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| s := httptest.NewServer(registry.New()) | ||
| defer s.Close() | ||
| registryName := strings.TrimPrefix(s.URL, "http://") | ||
|
|
||
| ref := tt.writeToRegistry(t, registryName) | ||
|
|
||
| storer, err := NewAttestationStorer(WithTargetRepository(ref.Repository)) | ||
| if err != nil { | ||
| t.Fatalf("failed to create storer: %v", err) | ||
| } | ||
|
|
||
| ctx := logtesting.TestContextWithLogger(t) | ||
| _, err = storer.Store(ctx, &api.StoreRequest[name.Digest, *intoto.Statement]{ | ||
| Artifact: ref, | ||
| Payload: &intoto.Statement{}, | ||
| Bundle: &signing.Bundle{}, | ||
| }) | ||
|
|
||
| if err != nil { | ||
| t.Fatalf("error during Store(): %s", err) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
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 |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| // Copyright 2025 The Tekton Authors | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package oci | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "net/http/httptest" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/google/go-containerregistry/pkg/name" | ||
| "github.com/google/go-containerregistry/pkg/registry" | ||
| "github.com/google/go-containerregistry/pkg/v1/random" | ||
| "github.com/google/go-containerregistry/pkg/v1/remote" | ||
| "github.com/google/go-containerregistry/pkg/v1/types" | ||
| "github.com/tektoncd/chains/pkg/chains/formats/simple" | ||
| "github.com/tektoncd/chains/pkg/chains/signing" | ||
| "github.com/tektoncd/chains/pkg/chains/storage/api" | ||
| logtesting "knative.dev/pkg/logging/testing" | ||
| ) | ||
|
|
||
| func TestSimpleStorer_Store(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| writeToRegistry func(*testing.T, string) name.Digest | ||
| }{ | ||
| { | ||
| name: "image manifest", | ||
| writeToRegistry: func(t *testing.T, registryName string) name.Digest { | ||
| t.Helper() | ||
| img, err := random.Image(1024, 2) | ||
| if err != nil { | ||
| t.Fatalf("failed to create random image: %s", err) | ||
| } | ||
| imgDigest, err := img.Digest() | ||
| if err != nil { | ||
| t.Fatalf("failed to get image digest: %v", err) | ||
| } | ||
| ref, err := name.NewDigest(fmt.Sprintf("%s/test/img@%s", registryName, imgDigest)) | ||
| if err != nil { | ||
| t.Fatalf("failed to parse digest: %v", err) | ||
| } | ||
| if err := remote.Write(ref, img); err != nil { | ||
| t.Fatalf("failed to write image to mock registry: %v", err) | ||
| } | ||
| return ref | ||
| }, | ||
| }, | ||
| { | ||
| name: "image layer", | ||
| writeToRegistry: func(t *testing.T, registryName string) name.Digest { | ||
| t.Helper() | ||
| layer, err := random.Layer(1024, types.OCILayer) | ||
| if err != nil { | ||
| t.Fatalf("failed to create random layer: %s", err) | ||
| } | ||
| layerDigest, err := layer.Digest() | ||
| if err != nil { | ||
| t.Fatalf("failed to get layer digest: %v", err) | ||
| } | ||
| ref, err := name.NewDigest(fmt.Sprintf("%s/test/img@%s", registryName, layerDigest)) | ||
| if err != nil { | ||
| t.Fatalf("failed to parse digest: %v", err) | ||
| } | ||
| if err := remote.WriteLayer(ref.Repository, layer); err != nil { | ||
| t.Fatalf("failed to write layer to mock registry: %v", err) | ||
| } | ||
| return ref | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| s := httptest.NewServer(registry.New()) | ||
| defer s.Close() | ||
| registryName := strings.TrimPrefix(s.URL, "http://") | ||
|
|
||
| ref := tt.writeToRegistry(t, registryName) | ||
|
|
||
| storer, err := NewSimpleStorerFromConfig(WithTargetRepository(ref.Repository)) | ||
| if err != nil { | ||
| t.Fatalf("failed to create storer: %v", err) | ||
| } | ||
|
|
||
| ctx := logtesting.TestContextWithLogger(t) | ||
| _, err = storer.Store(ctx, &api.StoreRequest[name.Digest, simple.SimpleContainerImage]{ | ||
| Artifact: ref, | ||
| Payload: simple.NewSimpleStruct(ref), | ||
| Bundle: &signing.Bundle{}, | ||
| }) | ||
|
|
||
| if err != nil { | ||
| t.Fatalf("error during Store(): %s", err) | ||
| } | ||
| }) | ||
| } | ||
| } |
16 changes: 16 additions & 0 deletions
16
vendor/github.com/google/go-containerregistry/pkg/v1/random/doc.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
116 changes: 116 additions & 0 deletions
116
vendor/github.com/google/go-containerregistry/pkg/v1/random/image.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.
Any chance we can assert the output anyway ?
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.
I don't think that's important. It looks like the Store method is half-baked and always returns
&api.StoreResponse{}.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.
Yeah I did check that, but thought if we can assert the logs, but that should be fine as we are check if the error is nil or not