Repository navigation
fix(cli): fail attestation verify when the bundle was never verified #3398
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
jiparis
merged 1 commit into
chainloop-dev:main
from
jiparis:jiparis/attestation-verify-exit-code
Sep 4, 2026
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
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,143 @@ | ||
| // | ||
| // Copyright 2026 The Chainloop 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 action | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "net" | ||
| "os" | ||
| "testing" | ||
|
|
||
| pb "github.com/chainloop-dev/chainloop/app/controlplane/api/controlplane/v1" | ||
| "github.com/rs/zerolog" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| "google.golang.org/grpc" | ||
| "google.golang.org/grpc/codes" | ||
| "google.golang.org/grpc/credentials/insecure" | ||
| "google.golang.org/grpc/status" | ||
| "google.golang.org/grpc/test/bufconn" | ||
| ) | ||
|
|
||
| // caKeyID is the authority key identifier of testdata/ca.pub, the CA that signed | ||
| // the certificate embedded in the valid test bundles. | ||
| const caKeyID = "2a522d9652e0933d2a1237c395bc116e012f86dffff13122da59f76e0d2abe27" | ||
|
|
||
| func TestAttestationVerifyRun(t *testing.T) { | ||
| testCases := []struct { | ||
| name string | ||
| bundle string | ||
| // withTrustedRoot serves the test CA as trusted root, otherwise the | ||
| // signing service replies Unimplemented, simulating a control plane | ||
| // with no signing CA configured. | ||
| withTrustedRoot bool | ||
| expectErr string | ||
| // expectNotVerifiable asserts the error is the sentinel telling the | ||
| // bundle was never verified, as opposed to failing verification. | ||
| expectNotVerifiable bool | ||
| }{ | ||
| { | ||
| name: "valid bundle is verified", | ||
| bundle: "testdata/bundle_valid.json", | ||
| withTrustedRoot: true, | ||
| }, | ||
| { | ||
| name: "bundle without verification material fails", | ||
| bundle: "testdata/bundle_valid_nomaterial.json", | ||
| withTrustedRoot: true, | ||
| expectErr: "verification material", | ||
| expectNotVerifiable: true, | ||
| }, | ||
| { | ||
| name: "no trusted root configured fails", | ||
| bundle: "testdata/bundle_valid.json", | ||
| expectErr: "trusted root", | ||
| expectNotVerifiable: true, | ||
| }, | ||
| { | ||
| name: "tampered bundle fails verification", | ||
| bundle: "testdata/bundle_invalid.json", | ||
| withTrustedRoot: true, | ||
| expectErr: "bundle verification failed", | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range testCases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| opts := &ActionsOpts{ | ||
| CPConnection: newSigningServiceConn(t, tc.withTrustedRoot), | ||
| Logger: zerolog.Nop(), | ||
| } | ||
|
|
||
| err := NewAttestationVerifyAction(opts).Run(context.Background(), tc.bundle) | ||
| if tc.expectErr == "" { | ||
| assert.NoError(t, err) | ||
| return | ||
| } | ||
|
|
||
| require.Error(t, err) | ||
| assert.Contains(t, err.Error(), tc.expectErr) | ||
| assert.Equal(t, tc.expectNotVerifiable, errors.Is(err, ErrAttestationNotVerifiable)) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // fakeSigningService serves the test CA as trusted root, or replies Unimplemented | ||
| // when none is configured. | ||
| type fakeSigningService struct { | ||
| pb.UnimplementedSigningServiceServer | ||
| trustedRoot *pb.GetTrustedRootResponse | ||
| } | ||
|
|
||
| func (s *fakeSigningService) GetTrustedRoot(context.Context, *pb.GetTrustedRootRequest) (*pb.GetTrustedRootResponse, error) { | ||
| if s.trustedRoot == nil { | ||
| return nil, status.Error(codes.Unimplemented, "trusted root not available") | ||
| } | ||
|
|
||
| return s.trustedRoot, nil | ||
| } | ||
|
|
||
| func newSigningServiceConn(t *testing.T, withTrustedRoot bool) *grpc.ClientConn { | ||
| t.Helper() | ||
|
|
||
| svc := &fakeSigningService{} | ||
| if withTrustedRoot { | ||
| ca, err := os.ReadFile("testdata/ca.pub") | ||
| require.NoError(t, err) | ||
| svc.trustedRoot = &pb.GetTrustedRootResponse{ | ||
| Keys: map[string]*pb.CertificateChain{caKeyID: {Certificates: []string{string(ca)}}}, | ||
| } | ||
| } | ||
|
|
||
| l := bufconn.Listen(1 << 20) | ||
| srv := grpc.NewServer() | ||
| pb.RegisterSigningServiceServer(srv, svc) | ||
| go func() { _ = srv.Serve(l) }() | ||
|
|
||
| conn, err := grpc.NewClient("passthrough:///bufnet", | ||
| grpc.WithContextDialer(func(ctx context.Context, _ string) (net.Conn, error) { return l.DialContext(ctx) }), | ||
| grpc.WithTransportCredentials(insecure.NewCredentials()), | ||
| ) | ||
| require.NoError(t, err) | ||
|
|
||
| t.Cleanup(func() { | ||
| conn.Close() | ||
| srv.Stop() | ||
| }) | ||
|
|
||
| return conn | ||
| } |
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,17 @@ | ||
| { | ||
| "mediaType": "application/vnd.dev.sigstore.bundle+json;version=0.3", | ||
| "verificationMaterial": { | ||
|
jiparis marked this conversation as resolved.
|
||
| "certificate": { | ||
| "rawBytes": "MIIDtzCCAZ+gAwIBAgIUHfh44qKz/2gMfB9BpJea03EW5SowDQYJKoZIhvcNAQELBQAwXjELMAkGA1UEBhMCRVMxEzARBgNVBAgMClNvbWUtU3RhdGUxEjAQBgNVBAoMCUNoYWlubG9vcDESMBAGA1UECwwJY2hhaW5sb29wMRIwEAYDVQQDDAljaGFpbmxvb3AwHhcNMjUwMjEyMDkxOTEzWhcNMjUwMjEyMDkyOTEzWjAvMS0wKwYDVQQKEyQxOGMzZjc4Mi00OTM2LTQ2MzAtYWI4ZC0yMGI1MTEzNjY2OTkwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAATKeTBItaVgTUP55i2Xh4ygIvWeeQGGezrb1xee1k/h3COyK37D/xR+uo8/wBnti02rWJmsZQtOq7CZwONU48n6o2cwZTAOBgNVHQ8BAf8EBAMCB4AwEwYDVR0lBAwwCgYIKwYBBQUHAwMwHQYDVR0OBBYEFN8DZs+da6GELfQB1YuAfNay2rXPMB8GA1UdIwQYMBaAFKDk5Tdk8eOOMf/+GDw+62HNH6XKMA0GCSqGSIb3DQEBCwUAA4ICAQBwFFmXUNEB5yvD96iFclWxPhiCC+nGSrZl/Mq3emOQD31jkSgvH+SBkoLOG+CUwN3GANmSP99hQjcQUZW7WTvlrScUNVKmhKoODhlwajjbZ/FHK4JcKRX+2JlCPAauRiP2Z5ZSTqQT0CySs/eDdffMxzG6bzRJN/+fQheKbdnHwFgIuF2QD3TDPhXj8D7mHalWNAf4Urq7tR+8GJj9LhQwz5ioqBLBN5FxngpVZGcKX+B+jbGXij/s8Zn8PXJFQ+YtFu65++AGVWS0HpPMUDH6n/M/oInmh/jYworVr0qCMYmohVR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ib20tcHJlc2VudCJ9XX1dfSwgInBvbGljeUhhc1Zpb2xhdGlvbnMiOnRydWUsICJydW5uZXJUeXBlIjoiUlVOTkVSX1RZUEVfVU5TUEVDSUZJRUQifX0=", | ||
| "payloadType": "application/vnd.in-toto+json", | ||
| "signatures": [ | ||
| { | ||
| "sig": "TUVVQ0lCR09pQkVOdDVGQ3l6OUp2d2tGaVRpZzgvQWN2YmJoNG0ycnJnd0trODg4QWlFQTA3YUdyMUk2MndaY0RaNGdWNTJBb0pCUXRUdVg3Mi9TRU4xOVdLZWdvNzA9" | ||
| } | ||
| ] | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.