@@ -322,8 +322,19 @@ func (uc *WorkflowRunUseCase) SaveAttestation(ctx context.Context, id string, en
322322 return nil , fmt .Errorf ("extracting predicate: %w" , err )
323323 }
324324
325+ // verify attestation (only if chainloop is the signer)
326+ result , err := uc .verifyBundle (ctx , rawContent )
327+ if err != nil {
328+ return nil , err
329+ }
330+
331+ // if it's verifiable, make sure it passed
332+ if result != nil && ! result .Result {
333+ return nil , NewErrValidation (fmt .Errorf ("attestation verification failed: %s" , result .FailureReason ))
334+ }
335+
325336 // Run some validations on the predicate
326- // Attestations can include dependent attestations and we want to make sure they exist in the system
337+ // Attestations can include dependent attestations, and we want to make sure they exist in the system
327338 // Find any material of kind attestation and make sure they exist already
328339 for _ , m := range predicate .GetMaterials () {
329340 if m .Type == schemaapi .CraftingSchema_Material_ATTESTATION .String () {
@@ -440,7 +451,11 @@ type VerificationResult struct {
440451 FailureReason string
441452}
442453
443- func (uc * WorkflowRunUseCase ) Verify (ctx context.Context , run * WorkflowRun ) (* VerificationResult , error ) {
454+ func (uc * WorkflowRunUseCase ) VerifyRun (ctx context.Context , run * WorkflowRun ) (* VerificationResult , error ) {
455+ return uc .verifyBundle (ctx , run .Attestation .Bundle )
456+ }
457+
458+ func (uc * WorkflowRunUseCase ) verifyBundle (ctx context.Context , bundle []byte ) (* VerificationResult , error ) {
444459 tr , err := uc .signingUseCase .GetTrustedRoot (ctx )
445460 if err != nil {
446461 if IsErrNotImplemented (err ) {
@@ -453,7 +468,7 @@ func (uc *WorkflowRunUseCase) Verify(ctx context.Context, run *WorkflowRun) (*Ve
453468 if err != nil {
454469 return nil , fmt .Errorf ("parsing roots: %w" , err )
455470 }
456- err = verifier .VerifyBundle (ctx , run . Attestation . Bundle , verifierRoots )
471+ err = verifier .VerifyBundle (ctx , bundle , verifierRoots )
457472 if err != nil {
458473 // if no verification material found, it's not verifiable
459474 if errors .Is (err , verifier .ErrMissingVerificationMaterial ) {
0 commit comments