Skip to content

Commit ec9b775

Browse files
committed
fix(oci): pass remote options to SignedUnknown calls
- Ensure SignedUnknown uses the same remote options as SignedEntity - Fix insecure registry support for unknown/missing images - Improve test coverage for secure vs insecure mode validation
1 parent 590d65d commit ec9b775

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

pkg/chains/storage/oci/attestation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (s *AttestationStorer) Store(ctx context.Context, req *api.StoreRequest[nam
6363
se, err := ociremote.SignedEntity(req.Artifact, ociremote.WithRemoteOptions(s.remoteOpts...))
6464
var entityNotFoundError *ociremote.EntityNotFoundError
6565
if errors.As(err, &entityNotFoundError) {
66-
se = ociremote.SignedUnknown(req.Artifact)
66+
se = ociremote.SignedUnknown(req.Artifact, ociremote.WithRemoteOptions(s.remoteOpts...))
6767
} else if err != nil {
6868
return nil, errors.Wrap(err, "getting signed image")
6969
}

pkg/chains/storage/oci/oci_test.go

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -246,27 +246,33 @@ func TestBackend_StorePayload(t *testing.T) {
246246

247247
// TestBackend_StorePayload_Insecure tests the StorePayload functionality with both secure and insecure configurations.
248248
// It verifies that:
249-
// 1. In secure mode, the backend should reject connections to untrusted registries
250-
// 2. In insecure mode, the backend should attempt to connect but fail due to missing image
249+
// 1. In secure mode, the backend should reject connections to untrusted registries due to TLS certificate verification failure
250+
// 2. In insecure mode, the backend should successfully connect and upload signatures, bypassing TLS verification
251251
func TestBackend_StorePayload_Insecure(t *testing.T) {
252252
// Setup test registry with self-signed certificate
253253
s, registryURL := setupTestRegistry(t)
254254
defer s.Close()
255255

256256
testCases := []struct {
257-
name string
258-
insecure bool
259-
wantErrMsg string
257+
name string
258+
insecure bool
259+
wantErr bool
260+
wantErrMsg string
261+
description string
260262
}{
261263
{
262-
name: "secure mode - should reject untrusted registry",
263-
insecure: false,
264-
wantErrMsg: "tls: failed to verify certificate: x509:",
264+
name: "secure mode with untrusted certificate",
265+
insecure: false,
266+
wantErr: true,
267+
wantErrMsg: "tls: failed to verify certificate: x509:",
268+
description: "Should reject connection to registry with self-signed certificate",
265269
},
266270
{
267-
name: "insecure mode - should attempt connection but fail due to missing image",
268-
insecure: true,
269-
wantErrMsg: "getting signed image: entity not found in registry",
271+
name: "insecure mode bypassing TLS verification",
272+
insecure: true,
273+
wantErr: false,
274+
wantErrMsg: "",
275+
description: "Should successfully connect and upload signature despite untrusted certificate",
270276
},
271277
}
272278

@@ -311,12 +317,17 @@ func TestBackend_StorePayload_Insecure(t *testing.T) {
311317
PayloadFormat: formats.PayloadTypeSimpleSigning,
312318
})
313319

314-
if err == nil {
315-
t.Error("expected error but got nil")
316-
return
317-
}
318-
if !strings.Contains(err.Error(), tc.wantErrMsg) {
319-
t.Errorf("error message mismatch\ngot: %v\nwant: %v", err, tc.wantErrMsg)
320+
// Validate test results based on expected outcome
321+
if tc.wantErr {
322+
if err == nil {
323+
t.Errorf("%s: expected error but got nil", tc.description)
324+
return
325+
}
326+
if tc.wantErrMsg != "" && !strings.Contains(err.Error(), tc.wantErrMsg) {
327+
t.Errorf("%s: error message mismatch\ngot: %v\nwant: %v", tc.description, err, tc.wantErrMsg)
328+
}
329+
} else if err != nil {
330+
t.Errorf("%s: expected success but got error: %v", tc.description, err)
320331
}
321332
})
322333
}

pkg/chains/storage/oci/simple.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (s *SimpleStorer) Store(ctx context.Context, req *api.StoreRequest[name.Dig
5959
se, err := ociremote.SignedEntity(req.Artifact, ociremote.WithRemoteOptions(s.remoteOpts...))
6060
var entityNotFoundError *ociremote.EntityNotFoundError
6161
if errors.As(err, &entityNotFoundError) {
62-
se = ociremote.SignedUnknown(req.Artifact)
62+
se = ociremote.SignedUnknown(req.Artifact, ociremote.WithRemoteOptions(s.remoteOpts...))
6363
} else if err != nil {
6464
return nil, errors.Wrap(err, "getting signed image")
6565
}

0 commit comments

Comments
 (0)