Repository navigation
Let policy condition expressions return a violation message - #7641
Conversation
Implements ADR 043. A condition expression may return a string instead of a boolean. A non-blank string records a violation with that string as message, a blank string records none. The message is stored on the violation and included in POLICY_VIOLATION and NEW_POLICY_VIOLATIONS_SUMMARY notifications. Signed-off-by: Matt Finkel <finkel.matt@gmail.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 9 |
🟢 Coverage 95.08% diff coverage
Metric Results Coverage variation Report missing for 859ed8e1 Diff coverage ✅ 95.08% diff coverage (70.00%) Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (859ed8e) Report Missing Report Missing Report Missing Head commit (a197621) 45870 40286 87.83% Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#7641) 61 58 95.08% Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%1 Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
nscuro
left a comment
There was a problem hiding this comment.
A few minor adjustments please, otherwise this looks good to go.
A matching vulnerability policy usually applies a suppression. Treating any non-blank string as a match could suppress findings by accident, so only boolean results are accepted. This also removes the unchecked result type special case from the compiler. Signed-off-by: Matt Finkel <finkel.matt@gmail.com>
Matches the other fields in the policy violation section. Signed-off-by: Matt Finkel <finkel.matt@gmail.com>
The same cases are covered at the resource layer by PolicyConditionResourceTest and VulnPoliciesResourceTest. Signed-off-by: Matt Finkel <finkel.matt@gmail.com>
The review asked only for the text type to become plain_text. A bold label would render as literal asterisks in plain text, so it is removed. Signed-off-by: Matt Finkel <finkel.matt@gmail.com>
Description
Policy condition expressions may now return a
stringinstead of abool. A non-blank string records a violation and uses the string as the violation message. A blank string records no violation. Boolean expressions behave as before.The message is stored on the violation and included in
POLICY_VIOLATIONandNEW_POLICY_VIOLATIONS_SUMMARYnotifications, including the default email, Slack, Teams, and Mattermost templates.This lets a policy explain what matched, for example which CVE or which license, without the consumer re-deriving it from the subject.
Implements ADR 043 (#7322).
Addressed Issue
Refs #6553. A follow-up PR will have the legacy condition builders (EPSS, severity, CWE, vulnerability ID, license, license group) generate string-returning expressions so existing policies get messages too.
Additional Details
COMPONENTpolicies. Expressions must returnboolorstring, otherwise the API rejects the condition.VULNERABILITYpolicies stay unchecked, as today.POLICYVIOLATION.TEXTchanges fromVARCHARtoTEXT(no table rewrite in Postgres).NEW_POLICY_VIOLATIONSnotification.RETURNING (xmax = 0)distinguishes inserted from updated rows.cel.bindis enabled on the compiler to make string construction less repetitive. Runtime evaluation failures are unchanged: logged, treated as not violated.messagefields on thePolicyViolationandNewPolicyViolationsSummarySubject.Violationprotobuf messages.Docs PR: DependencyTrack/docs#304
Checklist
This PR fixes a defect, and I have provided tests to verify that the fix is effectivedocs/adr/