MCPcopy Create free account
hub / github.com/conforma/cli / CreateAndPushImageSignatureReferrer

Function CreateAndPushImageSignatureReferrer

acceptance/image/image.go:377–427  ·  view source on GitHub ↗

CreateAndPushImageSignatureReferrer creates a signature for a named image using OCI Referrers API

(ctx context.Context, imageName string, keyName string)

Source from the content-addressed store, hash-verified

375
376// CreateAndPushImageSignatureReferrer creates a signature for a named image using OCI Referrers API
377func CreateAndPushImageSignatureReferrer(ctx context.Context, imageName string, keyName string) (context.Context, error) {
378 var state *imageState
379 ctx, err := testenv.SetupState(ctx, &state)
380 if err != nil {
381 return ctx, err
382 }
383
384 if _, ok := state.ReferrerSignatures[imageName]; ok {
385 // we already created the referrer signature
386 return ctx, nil
387 }
388
389 _, digest, digestImage, err := getImageDigestAndRef(ctx, imageName)
390 if err != nil {
391 return ctx, err
392 }
393
394 signer, err := crypto.SignerWithKey(ctx, keyName)
395 if err != nil {
396 return ctx, err
397 }
398
399 sigData, err := createSignatureData(ctx, imageName, digestImage, signer)
400 if err != nil {
401 return ctx, err
402 }
403
404 digestRef, err := getDigestRefForImage(ctx, imageName, digest)
405 if err != nil {
406 return ctx, err
407 }
408
409 // Attach signature using OCI Referrers API
410 err = cosignRemote.WriteReferrer(
411 digestRef,
412 "application/vnd.dev.cosign.simplesigning.v1+json",
413 []v1.Layer{sigData.signatureLayer},
414 sigData.annotations,
415 cosignRemote.WithRemoteOptions(remote.WithContext(ctx)),
416 )
417 if err != nil {
418 return ctx, fmt.Errorf("failed to write signature referrer: %w", err)
419 }
420
421 // NOTE: We store the subject image digest here for deduplication purposes only.
422 // This is NOT the referrer artifact's digest.
423 state.ReferrerSignatures[imageName] = digestRef.String()
424 state.ReferrerImageSignatures[imageName] = sigData.signatureStruct
425
426 return ctx, nil
427}
428
429// CreateAndPushAttestation for a named image in the Context creates an attestation
430// image, same as `cosign attest` or Tekton Chains would, and pushes it to the stub

Callers

nothing calls this directly

Calls 7

SetupStateFunction · 0.92
SignerWithKeyFunction · 0.92
getImageDigestAndRefFunction · 0.85
createSignatureDataFunction · 0.85
getDigestRefForImageFunction · 0.85
ErrorfMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected