Skip to content

Commit 8dc3992

Browse files
authored
fix(api): handle old attestation formats during validation push (#2612)
Signed-off-by: Miguel Martinez <[email protected]>
1 parent e07700f commit 8dc3992

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

app/controlplane/pkg/biz/workflowrun.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,14 +323,18 @@ func (uc *WorkflowRunUseCase) SaveAttestation(ctx context.Context, id string, en
323323
}
324324

325325
// verify attestation (only if chainloop is the signer)
326-
result, err := uc.verifyBundle(ctx, rawContent)
326+
validation, err := uc.verifyBundle(ctx, rawContent)
327327
if err != nil {
328-
return nil, err
328+
if !errors.Is(err, verifier.ErrInvalidBundle) {
329+
return nil, err
330+
}
331+
// invalid bundle is expected for old attestations so we skip validation
332+
uc.logger.Warn("received an old attestation format, not a bundle: attestation verification skipped", "error", err)
329333
}
330334

331335
// 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))
336+
if validation != nil && !validation.Result {
337+
return nil, NewErrValidation(fmt.Errorf("attestation verification failed: %s", validation.FailureReason))
334338
}
335339

336340
// Run some validations on the predicate
@@ -475,6 +479,10 @@ func (uc *WorkflowRunUseCase) verifyBundle(ctx context.Context, bundle []byte) (
475479
return nil, nil
476480
}
477481

482+
if errors.Is(err, verifier.ErrInvalidBundle) {
483+
return nil, err
484+
}
485+
478486
return &VerificationResult{Result: false, FailureReason: err.Error()}, nil
479487
}
480488
return &VerificationResult{Result: true}, nil

pkg/attestation/verifier/verifier.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type TrustedRoot struct {
3838
}
3939

4040
var ErrMissingVerificationMaterial = errors.New("missing material")
41+
var ErrInvalidBundle = errors.New("invalid bundle")
4142

4243
func VerifyBundle(ctx context.Context, bundleBytes []byte, tr *TrustedRoot) error {
4344
if bundleBytes == nil {
@@ -47,7 +48,7 @@ func VerifyBundle(ctx context.Context, bundleBytes []byte, tr *TrustedRoot) erro
4748
bundle := new(protobundle.Bundle)
4849
// unmarshal and validate
4950
if err := protojson.Unmarshal(bundleBytes, bundle); err != nil {
50-
return fmt.Errorf("invalid bundle: %w", err)
51+
return fmt.Errorf("%w: %w", err, ErrInvalidBundle)
5152
}
5253

5354
// fix for old attestations

0 commit comments

Comments
 (0)