1
1
//
2
- // Copyright 2024 The Chainloop Authors.
2
+ // Copyright 2024-2025 The Chainloop Authors.
3
3
//
4
4
// Licensed under the Apache License, Version 2.0 (the "License");
5
5
// you may not use this file except in compliance with the License.
@@ -45,17 +45,20 @@ type AttestationStatus struct {
45
45
}
46
46
47
47
type AttestationStatusResult struct {
48
- AttestationID string `json:"attestationID"`
49
- InitializedAt * time.Time `json:"initializedAt"`
50
- WorkflowMeta * AttestationStatusWorkflowMeta `json:"workflowMeta"`
51
- Materials []AttestationStatusResultMaterial `json:"materials"`
52
- EnvVars map [string ]string `json:"envVars"`
53
- RunnerContext * AttestationResultRunnerContext `json:"runnerContext"`
54
- DryRun bool `json:"dryRun"`
55
- Annotations []* Annotation `json:"annotations"`
56
- IsPushed bool `json:"isPushed"`
57
- PolicyEvaluations map [string ][]* PolicyEvaluation `json:"policy_evaluations,omitempty"`
58
- HasPolicyViolations bool `json:"hasPolicyViolations"`
48
+ AttestationID string `json:"attestationID"`
49
+ InitializedAt * time.Time `json:"initializedAt"`
50
+ WorkflowMeta * AttestationStatusWorkflowMeta `json:"workflowMeta"`
51
+ Materials []AttestationStatusResultMaterial `json:"materials"`
52
+ EnvVars map [string ]string `json:"envVars"`
53
+ RunnerContext * AttestationResultRunnerContext `json:"runnerContext"`
54
+ DryRun bool `json:"dryRun"`
55
+ Annotations []* Annotation `json:"annotations"`
56
+ IsPushed bool `json:"isPushed"`
57
+ PolicyEvaluations map [string ][]* PolicyEvaluation `json:"policy_evaluations,omitempty"`
58
+ HasPolicyViolations bool `json:"has_policy_violations"`
59
+ MustBlockOnPolicyViolations bool `json:"must_block_on_policy_violations"`
60
+ // This might only be set if the attestation is pushed
61
+ Digest string `json:"digest"`
59
62
}
60
63
61
64
type AttestationResultRunnerContext struct {
@@ -126,10 +129,11 @@ func (action *AttestationStatus) Run(ctx context.Context, attestationID string,
126
129
ContractRevision : workflowMeta .GetSchemaRevision (),
127
130
ContractName : workflowMeta .GetContractName (),
128
131
},
129
- InitializedAt : toTimePtr (att .InitializedAt .AsTime ()),
130
- DryRun : c .CraftingState .DryRun ,
131
- Annotations : pbAnnotationsToAction (c .CraftingState .InputSchema .GetAnnotations ()),
132
- IsPushed : action .isPushed ,
132
+ InitializedAt : toTimePtr (att .InitializedAt .AsTime ()),
133
+ DryRun : c .CraftingState .DryRun ,
134
+ Annotations : pbAnnotationsToAction (c .CraftingState .InputSchema .GetAnnotations ()),
135
+ IsPushed : action .isPushed ,
136
+ MustBlockOnPolicyViolations : att .GetBlockOnPolicyViolation (),
133
137
}
134
138
135
139
if ! action .skipPolicyEvaluation {
@@ -146,12 +150,10 @@ func (action *AttestationStatus) Run(ctx context.Context, attestationID string,
146
150
return nil , fmt .Errorf ("rendering statement: %w" , err )
147
151
}
148
152
149
- res .PolicyEvaluations , err = action .getPolicyEvaluations (ctx , c , attestationID , statement )
153
+ res .PolicyEvaluations , res . HasPolicyViolations , err = action .getPolicyEvaluations (ctx , c , attestationID , statement )
150
154
if err != nil {
151
155
return nil , fmt .Errorf ("getting policy evaluations: %w" , err )
152
156
}
153
-
154
- res .HasPolicyViolations = len (res .PolicyEvaluations ) > 0
155
157
}
156
158
157
159
if v := workflowMeta .GetVersion (); v != nil {
@@ -200,14 +202,15 @@ func (action *AttestationStatus) Run(ctx context.Context, attestationID string,
200
202
return res , nil
201
203
}
202
204
203
- // getPolicyEvaluations retrieves both material-level and attestation-level policy evaluations
204
- func (action * AttestationStatus ) getPolicyEvaluations (ctx context.Context , c * crafter.Crafter , attestationID string , statement * intoto.Statement ) (map [string ][]* PolicyEvaluation , error ) {
205
+ // getPolicyEvaluations retrieves both material-level and attestation-level policy evaluations and returns if it has violations
206
+ func (action * AttestationStatus ) getPolicyEvaluations (ctx context.Context , c * crafter.Crafter , attestationID string , statement * intoto.Statement ) (map [string ][]* PolicyEvaluation , bool , error ) {
205
207
// grouped by material name
206
208
evaluations := make (map [string ][]* PolicyEvaluation )
209
+ var hasViolations bool
207
210
208
211
// Add attestation-level policy evaluations
209
212
if err := c .EvaluateAttestationPolicies (ctx , attestationID , statement ); err != nil {
210
- return nil , fmt .Errorf ("evaluating attestation policies: %w" , err )
213
+ return nil , false , fmt .Errorf ("evaluating attestation policies: %w" , err )
211
214
}
212
215
213
216
// map evaluations
@@ -217,14 +220,18 @@ func (action *AttestationStatus) getPolicyEvaluations(ctx context.Context, c *cr
217
220
keyName = chainloop .AttPolicyEvaluation
218
221
}
219
222
223
+ if len (v .GetViolations ()) > 0 {
224
+ hasViolations = true
225
+ }
226
+
220
227
if existing , ok := evaluations [keyName ]; ok {
221
228
evaluations [keyName ] = append (existing , policyEvaluationStateToActionForStatus (v ))
222
229
} else {
223
230
evaluations [keyName ] = []* PolicyEvaluation {policyEvaluationStateToActionForStatus (v )}
224
231
}
225
232
}
226
233
227
- return evaluations , nil
234
+ return evaluations , hasViolations , nil
228
235
}
229
236
230
237
// populateMaterials populates the materials in the attestation result regardless of where they are defined
0 commit comments