Skip to content

Commit 6a62c95

Browse files
authored
feat: expose policy evaluation info through API (#1770)
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
1 parent 65f701b commit 6a62c95

15 files changed

+779
-399
lines changed

app/cli/cmd/workflow_workflow_run_describe.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2024 The Chainloop Authors.
2+
// Copyright 2024-2025 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -157,6 +157,12 @@ func workflowRunDescribeTableOutput(run *action.WorkflowRunItemFull) error {
157157
}
158158
}
159159

160+
gt.AppendRow(table.Row{"Policies violation strategy", att.PolicyEvaluationStatus.Strategy})
161+
if att.PolicyEvaluationStatus.Strategy == action.PolicyViolationBlockingStrategyEnforced {
162+
gt.AppendRow(table.Row{"Run Blocked", att.PolicyEvaluationStatus.Blocked})
163+
gt.AppendRow(table.Row{"Policy enforcement bypassed", att.PolicyEvaluationStatus.Bypassed})
164+
}
165+
160166
evs := att.PolicyEvaluations[chainloop.AttPolicyEvaluation]
161167
if len(evs) > 0 {
162168
gt.AppendRow(table.Row{"Policies", "------"})

app/cli/internal/action/workflow_run_describe.go

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2024 The Chainloop Authors.
2+
// Copyright 2024-2025 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -57,6 +57,15 @@ type WorkflowRunAttestationItem struct {
5757
Digest string `json:"digest"`
5858
// Policy violations
5959
PolicyEvaluations map[string][]*PolicyEvaluation `json:"policy_evaluations,omitempty"`
60+
// Policy evaluation status
61+
PolicyEvaluationStatus *PolicyEvaluationStatus `json:"policy_evaluation_status,omitempty"`
62+
}
63+
64+
type PolicyEvaluationStatus struct {
65+
Strategy string `json:"strategy"`
66+
Bypassed bool `json:"bypassed"`
67+
Blocked bool `json:"blocked"`
68+
HasViolations bool `json:"has_violations"`
6069
}
6170

6271
type Material struct {
@@ -204,6 +213,8 @@ func (action *WorkflowRunDescribe) Run(ctx context.Context, opts *WorkflowRunDes
204213
evaluations[k] = evs
205214
}
206215

216+
policyEvaluationStatus := attestation.GetPolicyEvaluationStatus()
217+
207218
item.Attestation = &WorkflowRunAttestationItem{
208219
Envelope: envelope,
209220
statement: statement,
@@ -212,6 +223,12 @@ func (action *WorkflowRunDescribe) Run(ctx context.Context, opts *WorkflowRunDes
212223
Annotations: annotations,
213224
Digest: attestation.DigestInCasBackend,
214225
PolicyEvaluations: evaluations,
226+
PolicyEvaluationStatus: &PolicyEvaluationStatus{
227+
Strategy: policyEvaluationStatus.Strategy,
228+
Bypassed: policyEvaluationStatus.Bypassed,
229+
Blocked: policyEvaluationStatus.Blocked,
230+
HasViolations: policyEvaluationStatus.HasViolations,
231+
},
215232
}
216233

217234
return item, nil

app/controlplane/api/controlplane/v1/response_messages.pb.go

+502-392
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/api/controlplane/v1/response_messages.proto

+8
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ message AttestationItem {
9696
repeated Material materials = 5;
9797
map<string, string> annotations = 6;
9898
map<string, PolicyEvaluations> policy_evaluations = 8;
99+
PolicyEvaluationStatus policy_evaluation_status = 9;
100+
101+
message PolicyEvaluationStatus {
102+
string strategy = 1;
103+
bool bypassed = 2;
104+
bool blocked = 3;
105+
bool has_violations = 4;
106+
}
99107

100108
message EnvVariable {
101109
string name = 1;

app/controlplane/api/gen/frontend/controlplane/v1/response_messages.ts

+130
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/api/gen/jsonschema/controlplane.v1.AttestationItem.PolicyEvaluationStatus.jsonschema.json

+26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/api/gen/jsonschema/controlplane.v1.AttestationItem.PolicyEvaluationStatus.schema.json

+26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/api/gen/jsonschema/controlplane.v1.AttestationItem.jsonschema.json

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/api/gen/jsonschema/controlplane.v1.AttestationItem.schema.json

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/internal/service/attestation.go

+8
Original file line numberDiff line numberDiff line change
@@ -433,13 +433,21 @@ func bizAttestationToPb(att *biz.Attestation) (*cpAPI.AttestationItem, error) {
433433
return nil, fmt.Errorf("error extracting materials from attestation: %w", err)
434434
}
435435

436+
policyEvaluationStatus := predicate.GetPolicyEvaluationStatus()
437+
436438
return &cpAPI.AttestationItem{
437439
Envelope: encodedAttestation,
438440
EnvVars: extractEnvVariables(predicate.GetEnvVars()),
439441
DigestInCasBackend: att.Digest,
440442
Materials: materials,
441443
Annotations: predicate.GetAnnotations(),
442444
PolicyEvaluations: extractPolicyEvaluations(predicate.GetPolicyEvaluations()),
445+
PolicyEvaluationStatus: &cpAPI.AttestationItem_PolicyEvaluationStatus{
446+
Strategy: string(policyEvaluationStatus.Strategy),
447+
Bypassed: policyEvaluationStatus.Bypassed,
448+
Blocked: policyEvaluationStatus.Blocked,
449+
HasViolations: policyEvaluationStatus.HasViolations,
450+
},
443451
}, nil
444452
}
445453

app/controlplane/internal/service/workflowrun.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2024 The Chainloop Authors.
2+
// Copyright 2024-2025 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)