Skip to content

Commit ca2b646

Browse files
authored
chore(policies): log policy violations (chainloop-dev#1102)
Signed-off-by: Jose I. Paris <[email protected]>
1 parent 8bb4104 commit ca2b646

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

internal/attestation/crafter/crafter.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,8 @@ func (c *Crafter) addMaterial(ctx context.Context, m *schemaapi.CraftingSchema_M
577577
if err != nil {
578578
return fmt.Errorf("error applying policies to material: %w", err)
579579
}
580+
// log policy violations
581+
policies.LogPolicyViolations(policyResults, c.logger)
580582
// store policy results
581583
c.CraftingState.Attestation.PolicyEvaluations = append(c.CraftingState.Attestation.PolicyEvaluations, policyResults...)
582584

internal/attestation/renderer/renderer.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ func (ab *AttestationRenderer) Render(ctx context.Context) (*dsse.Envelope, erro
113113
if err != nil {
114114
return nil, fmt.Errorf("applying policies to statement: %w", err)
115115
}
116+
// log policy violations
117+
policies.LogPolicyViolations(policyResults, &ab.logger)
116118

117119
// insert attestation level policy results into statement
118120
if err = addPolicyResults(statement, policyResults); err != nil {

pkg/policies/policies.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,3 +316,14 @@ func LoadPolicyScriptFromSpec(spec *v1.Policy) (*engine.Policy, error) {
316316
Source: content,
317317
}, nil
318318
}
319+
320+
func LogPolicyViolations(evaluations []*v12.PolicyEvaluation, logger *zerolog.Logger) {
321+
for _, policyEval := range evaluations {
322+
if len(policyEval.Violations) > 0 {
323+
logger.Warn().Msgf("found policy violations (%s) for %s", policyEval.Name, policyEval.MaterialName)
324+
for _, v := range policyEval.Violations {
325+
logger.Warn().Msgf(" - %s", v.Message)
326+
}
327+
}
328+
}
329+
}

0 commit comments

Comments
 (0)