Skip to content

Commit ed92f11

Browse files
authored
chore(signing): verify signature on att push (#2606)
Signed-off-by: Jose I. Paris <[email protected]>
1 parent 66029b9 commit ed92f11

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

app/controlplane/internal/service/workflowrun.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func (s *WorkflowRunService) View(ctx context.Context, req *pb.WorkflowRunServic
164164
var verificationResult *pb.WorkflowRunServiceViewResponse_VerificationResult
165165
if req.Verify {
166166
// it might be nil if it doesn't apply
167-
vr, err := s.wrUseCase.Verify(ctx, run)
167+
vr, err := s.wrUseCase.VerifyRun(ctx, run)
168168
if err != nil {
169169
return nil, handleUseCaseErr(err, s.log)
170170
}

app/controlplane/pkg/biz/workflowrun.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)