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

Function createAndPushAttestationInternal

acceptance/image/image.go:447–597  ·  view source on GitHub ↗

createAndPushAttestationInternal is the internal implementation that supports both SLSA v0.2 and v1

(ctx context.Context, imageName, keyName string, patches *godog.Table, useV1 bool)

Source from the content-addressed store, hash-verified

445
446// createAndPushAttestationInternal is the internal implementation that supports both SLSA v0.2 and v1
447func createAndPushAttestationInternal(ctx context.Context, imageName, keyName string, patches *godog.Table, useV1 bool) (context.Context, error) {
448 var state *imageState
449 ctx, err := testenv.SetupState(ctx, &state)
450 if err != nil {
451 return ctx, err
452 }
453
454 if state.Attestations[imageName] != "" {
455 // we already created the attestation
456 return ctx, nil
457 }
458
459 image, digest, _, err := getImageDigestAndRef(ctx, imageName)
460 if err != nil {
461 return ctx, err
462 }
463
464 var statement any
465
466 if useV1 {
467 // SLSA v1.0
468 statement, err = attestation.CreateV1StatementFor(imageName, image)
469 if err != nil {
470 return ctx, err
471 }
472 } else {
473 // SLSA v0.2
474 v02Statement, err := attestation.CreateStatementFor(imageName, image)
475 if err != nil {
476 return ctx, err
477 }
478
479 statement, err = applyPatches(v02Statement, patches)
480 if err != nil {
481 return ctx, err
482 }
483 }
484
485 signedAttestation, err := attestation.SignStatement(ctx, keyName, statement)
486 if err != nil {
487 return ctx, err
488 }
489
490 // Extract signature information from the signed attestation
491 var sig *cosign.Signatures
492 sig, err = unmarshallSignatures(signedAttestation)
493 if err != nil {
494 return ctx, err
495 }
496 if sig == nil {
497 return ctx, fmt.Errorf("failed to extract signature from attestation: no signatures found")
498 }
499
500 state.AttestationSignatures[imageName] = Signature{
501 KeyID: sig.KeyID,
502 Signature: sig.Sig,
503 }
504

Callers 3

CreateAndPushAttestationFunction · 0.85

Calls 15

SetupStateFunction · 0.92
CreateV1StatementForFunction · 0.92
CreateStatementForFunction · 0.92
SignStatementFunction · 0.92
SignerWithKeyFunction · 0.92
getImageDigestAndRefFunction · 0.85
applyPatchesFunction · 0.85
unmarshallSignaturesFunction · 0.85
uploadToTransparencyLogFunction · 0.85
ErrorfMethod · 0.65

Tested by

no test coverage detected