Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controlplane/internal/service/workflowrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (s *WorkflowRunService) View(ctx context.Context, req *pb.WorkflowRunServic
var verificationResult *pb.WorkflowRunServiceViewResponse_VerificationResult
if req.Verify {
// it might be nil if it doesn't apply
vr, err := s.wrUseCase.Verify(ctx, run)
vr, err := s.wrUseCase.VerifyRun(ctx, run)
if err != nil {
return nil, handleUseCaseErr(err, s.log)
}
Expand Down
21 changes: 18 additions & 3 deletions app/controlplane/pkg/biz/workflowrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,19 @@ func (uc *WorkflowRunUseCase) SaveAttestation(ctx context.Context, id string, en
return nil, fmt.Errorf("extracting predicate: %w", err)
}

// verify attestation (only if chainloop is the signer)
result, err := uc.verifyBundle(ctx, rawContent)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is the logic that makes sure the bundle is verified when keyless signing was used?

if err != nil {
return nil, err
}

// if it's verifiable, make sure it passed
if result != nil && !result.Result {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, so result will be nil if can't be verified? I'd make it more explicit somehow

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes in that case it would return nil, nil. I agree it should return something more explicit.

return nil, NewErrValidation(fmt.Errorf("attestation verification failed: %s", result.FailureReason))
}

// Run some validations on the predicate
// Attestations can include dependent attestations and we want to make sure they exist in the system
// Attestations can include dependent attestations, and we want to make sure they exist in the system
// Find any material of kind attestation and make sure they exist already
for _, m := range predicate.GetMaterials() {
if m.Type == schemaapi.CraftingSchema_Material_ATTESTATION.String() {
Expand Down Expand Up @@ -440,7 +451,11 @@ type VerificationResult struct {
FailureReason string
}

func (uc *WorkflowRunUseCase) Verify(ctx context.Context, run *WorkflowRun) (*VerificationResult, error) {
func (uc *WorkflowRunUseCase) VerifyRun(ctx context.Context, run *WorkflowRun) (*VerificationResult, error) {
return uc.verifyBundle(ctx, run.Attestation.Bundle)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any case where run.Attestation would be empty?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems it will not, makes sense.

}

func (uc *WorkflowRunUseCase) verifyBundle(ctx context.Context, bundle []byte) (*VerificationResult, error) {
tr, err := uc.signingUseCase.GetTrustedRoot(ctx)
if err != nil {
if IsErrNotImplemented(err) {
Expand All @@ -453,7 +468,7 @@ func (uc *WorkflowRunUseCase) Verify(ctx context.Context, run *WorkflowRun) (*Ve
if err != nil {
return nil, fmt.Errorf("parsing roots: %w", err)
}
err = verifier.VerifyBundle(ctx, run.Attestation.Bundle, verifierRoots)
err = verifier.VerifyBundle(ctx, bundle, verifierRoots)
if err != nil {
// if no verification material found, it's not verifiable
if errors.Is(err, verifier.ErrMissingVerificationMaterial) {
Expand Down
Loading