@@ -297,6 +297,7 @@ func (r *OCIRepositoryReconciler) reconcile(ctx context.Context, obj *sourcev1.O
297
297
// reconcileSource fetches the upstream OCI artifact metadata and content.
298
298
// If this fails, it records v1beta2.FetchFailedCondition=True on the object and returns early.
299
299
func (r * OCIRepositoryReconciler ) reconcileSource (ctx context.Context , obj * sourcev1.OCIRepository , metadata * sourcev1.Artifact , dir string ) (sreconcile.Result , error ) {
300
+ var verifyOpts []remote.Option
300
301
ctxTimeout , cancel := context .WithTimeout (ctx , obj .Spec .Timeout .Duration )
301
302
defer cancel ()
302
303
@@ -308,7 +309,7 @@ func (r *OCIRepositoryReconciler) reconcileSource(ctx context.Context, obj *sour
308
309
conditions .Delete (obj , sourcev1 .SourceVerifiedCondition )
309
310
}
310
311
311
- options := r .craneOptions (ctxTimeout , obj .Spec .Insecure )
312
+ craneOpts := r .craneOptions (ctxTimeout , obj .Spec .Insecure )
312
313
313
314
// Generate the registry credential keychain either from static credentials or using cloud OIDC
314
315
keychain , err := r .keychain (ctx , obj )
@@ -320,7 +321,7 @@ func (r *OCIRepositoryReconciler) reconcileSource(ctx context.Context, obj *sour
320
321
conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Err .Error ())
321
322
return sreconcile .ResultEmpty , e
322
323
}
323
- options = append (options , crane .WithAuthFromKeychain (keychain ))
324
+ craneOpts = append (craneOpts , crane .WithAuthFromKeychain (keychain ))
324
325
325
326
if _ , ok := keychain .(soci.Anonymous ); obj .Spec .Provider != sourcev1 .GenericOCIProvider && ok {
326
327
auth , authErr := oidcAuth (ctxTimeout , obj .Spec .URL , obj .Spec .Provider )
@@ -333,8 +334,15 @@ func (r *OCIRepositoryReconciler) reconcileSource(ctx context.Context, obj *sour
333
334
return sreconcile .ResultEmpty , e
334
335
}
335
336
if auth != nil {
336
- options = append (options , crane .WithAuth (auth ))
337
+ craneOpts = append (craneOpts , crane .WithAuth (auth ))
338
+ verifyOpts = append (verifyOpts , remote .WithAuth (auth ))
339
+ } else {
340
+ // If no auth is configured at all, use anonymous access
341
+ verifyOpts = append (verifyOpts , remote .WithAuthFromKeychain (keychain ))
337
342
}
343
+ } else {
344
+ // we need to make sure not to pass a keychain and an auth option at the same time
345
+ verifyOpts = append (verifyOpts , remote .WithAuthFromKeychain (keychain ))
338
346
}
339
347
340
348
// Generate the transport for remote operations
@@ -348,11 +356,18 @@ func (r *OCIRepositoryReconciler) reconcileSource(ctx context.Context, obj *sour
348
356
return sreconcile .ResultEmpty , e
349
357
}
350
358
if transport != nil {
351
- options = append (options , crane .WithTransport (transport ))
359
+ craneOpts = append (craneOpts , crane .WithTransport (transport ))
360
+ verifyOpts = append (verifyOpts , remote .WithTransport (transport ))
361
+ } else if obj .Spec .Insecure {
362
+ // If no transport is generated, but the repository is marked as insecure,
363
+ // use the default remote transport.
364
+ transport := remote .DefaultTransport .Clone ()
365
+ transport .TLSClientConfig = & tls.Config {InsecureSkipVerify : true }
366
+ verifyOpts = append (verifyOpts , remote .WithTransport (transport ))
352
367
}
353
368
354
369
// Determine which artifact revision to pull
355
- url , err := r .getArtifactURL (obj , options )
370
+ url , err := r .getArtifactURL (obj , craneOpts )
356
371
if err != nil {
357
372
if _ , ok := err .(invalidOCIURLError ); ok {
358
373
e := serror .NewStalling (
@@ -370,7 +385,7 @@ func (r *OCIRepositoryReconciler) reconcileSource(ctx context.Context, obj *sour
370
385
}
371
386
372
387
// Get the upstream revision from the artifact digest
373
- revision , err := r .getRevision (url , options )
388
+ revision , err := r .getRevision (url , craneOpts )
374
389
if err != nil {
375
390
e := serror .NewGeneric (
376
391
fmt .Errorf ("failed to determine artifact digest: %w" , err ),
@@ -401,7 +416,7 @@ func (r *OCIRepositoryReconciler) reconcileSource(ctx context.Context, obj *sour
401
416
} else if ! obj .GetArtifact ().HasRevision (revision ) ||
402
417
conditions .GetObservedGeneration (obj , sourcev1 .SourceVerifiedCondition ) != obj .Generation ||
403
418
conditions .IsFalse (obj , sourcev1 .SourceVerifiedCondition ) {
404
- err := r .verifySignature (ctx , obj , url , keychain )
419
+ err := r .verifySignature (ctx , obj , url , verifyOpts ... )
405
420
if err != nil {
406
421
provider := obj .Spec .Verify .Provider
407
422
if obj .Spec .Verify .SecretRef == nil {
@@ -425,7 +440,7 @@ func (r *OCIRepositoryReconciler) reconcileSource(ctx context.Context, obj *sour
425
440
}
426
441
427
442
// Pull artifact from the remote container registry
428
- img , err := crane .Pull (url , options ... )
443
+ img , err := crane .Pull (url , craneOpts ... )
429
444
if err != nil {
430
445
e := serror .NewGeneric (
431
446
fmt .Errorf ("failed to pull artifact from '%s': %w" , obj .Spec .URL , err ),
@@ -585,15 +600,15 @@ func (r *OCIRepositoryReconciler) digestFromRevision(revision string) string {
585
600
586
601
// verifySignature verifies the authenticity of the given image reference url. First, it tries using a key
587
602
// if a secret with a valid public key is provided. If not, it falls back to a keyless approach for verification.
588
- func (r * OCIRepositoryReconciler ) verifySignature (ctx context.Context , obj * sourcev1.OCIRepository , url string , keychain authn. Keychain ) error {
603
+ func (r * OCIRepositoryReconciler ) verifySignature (ctx context.Context , obj * sourcev1.OCIRepository , url string , opt ... remote. Option ) error {
589
604
ctxTimeout , cancel := context .WithTimeout (ctx , obj .Spec .Timeout .Duration )
590
605
defer cancel ()
591
606
592
607
provider := obj .Spec .Verify .Provider
593
608
switch provider {
594
609
case "cosign" :
595
610
defaultCosignOciOpts := []soci.Options {
596
- soci .WithAuthnKeychain ( keychain ),
611
+ soci .WithRemoteOptions ( opt ... ),
597
612
}
598
613
599
614
ref , err := name .ParseReference (url )
0 commit comments