Skip to content

Commit f4bc154

Browse files
authored
docs: [five-c] add usage and configuration documentation #416 (#557)
Signed-off-by: tdruez <tdruez@aboutcode.org>
1 parent 95b316e commit f4bc154

7 files changed

Lines changed: 332 additions & 8 deletions
154 KB
Loading
50.7 KB
Loading
247 KB
Loading
21.7 KB
Loading

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Welcome to the very start of your DejaCode journey!
4040

4141
reference-data-models
4242
reference-vulnerability-management
43+
reference-policy-rules
4344
reference-1
4445
reference-2
4546
reference-3-cravex

docs/integrations-webhook.rst

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,36 @@ Webhooks can be used to:
2020
- Push updates to a monitoring or reporting dashboard
2121
- Synchronize status changes with an external ticketing system
2222
- Trigger automation in CI/CD pipelines
23+
- Alert a Slack channel when new policy violations are detected or resolved
24+
- Notify security teams when new vulnerability data is available
2325

2426
Available events
2527
----------------
2628

27-
The following events can be configured as webhook triggers:
29+
The following events can be configured as webhook triggers.
30+
31+
**Request events**
2832

2933
- ``request.added`` — A new request is created
3034
- ``request.updated`` — An existing request is modified
3135
- ``request_comment.added`` — A comment is added to a request
32-
- ``vulnerability.data_update`` — Vulnerability data is updated
36+
37+
**Vulnerability events**
38+
39+
- ``vulnerability.data_update`` — Vulnerability data is updated (daily refresh or
40+
package import)
41+
42+
**Policy events**
43+
44+
- ``policy.violation_detected`` — One or more new policy violations are detected
45+
during a rule evaluation run
46+
- ``policy.violation_resolved`` — One or more policy violations are resolved during
47+
a rule evaluation run
48+
49+
**User events**
50+
51+
- ``user.locked_out`` — A user account is locked out following failed login attempts
52+
- ``user.added_or_updated`` — A user account is created or modified
3353

3454
.. note::
3555

@@ -60,15 +80,14 @@ with the event payload.
6080
Payload structure
6181
-----------------
6282

63-
The default webhook payload is JSON-formatted and contains at least:
83+
DejaCode uses two payload formats depending on the event type.
6484

65-
- ``hook`` — The data related to the webhook, like event name, e.g. ``request.created``
66-
- ``data`` — Object containing event-specific data
85+
**Structured payload** (request events)
6786

68-
If **extra payload** is defined, it is merged into the JSON body.
69-
If **extra headers** are defined, they are added to the HTTP request.
87+
Request events use a structured JSON format containing a ``hook`` object with webhook
88+
metadata and a ``data`` object with the full serialized resource.
7089

71-
Example payload::
90+
Example payload for ``request.added``::
7291

7392
{
7493
"hook": {
@@ -107,6 +126,32 @@ Example payload::
107126
}
108127
}
109128

129+
**Text payload** (vulnerability and policy events)
130+
131+
Vulnerability and policy events use a simpler format with a single ``text`` field
132+
containing a human-readable summary of the event.
133+
134+
Example payload for ``vulnerability.data_update``::
135+
136+
{
137+
"text": "[DejaCode] New vulnerabilities detected!\n42 vulnerabilities affecting 7 packages"
138+
}
139+
140+
Example payload for ``policy.violation_detected``::
141+
142+
{
143+
"text": "[DejaCode] Policy violations detected for MyApp 2.0\n- Vulnerability Detected: 3 violation(s)\n- Vulnerability Stale: 1 violation(s)"
144+
}
145+
146+
Example payload for ``policy.violation_resolved``::
147+
148+
{
149+
"text": "[DejaCode] 2 policy violation(s) resolved for MyApp 2.0"
150+
}
151+
152+
If **extra payload** is defined on the webhook, it is merged into the JSON body.
153+
If **extra headers** are defined, they are added to the HTTP request.
154+
110155
Security considerations
111156
-----------------------
112157

docs/reference-policy-rules.rst

Lines changed: 278 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,278 @@
1+
.. _reference_policy_rules:
2+
3+
Policy Rules Engine
4+
===================
5+
6+
DejaCode includes a **Policy Rules Engine** that continuously evaluates configurable
7+
compliance rules against your products and records violations. It provides a structured
8+
way to detect, track, and resolve compliance issues across usage policies, license
9+
coverage, and vulnerability exposure.
10+
11+
When a rule is triggered, DejaCode records a **policy violation** with a count of the
12+
affected packages and the detection date. Violations are automatically resolved when the
13+
underlying condition is corrected.
14+
15+
All rules are **disabled by default**. Each dataspace activates and configures the
16+
rules that are relevant to its compliance program via the **Dataspace Configuration**
17+
form.
18+
19+
1. Built-in Rules
20+
-----------------
21+
22+
Eight rules are available out of the box, organized into two categories: policy-based
23+
rules and vulnerability-based rules.
24+
25+
**Policy-based rules**
26+
27+
.. list-table::
28+
:header-rows: 1
29+
30+
* - Rule type
31+
- Label
32+
- Severity
33+
- Description
34+
* - ``usage_policy_error``
35+
- **Usage Policy Error**
36+
- Error
37+
- Detects packages assigned a usage policy flagged with an error compliance alert.
38+
* - ``usage_policy_warning``
39+
- **Usage Policy Warning**
40+
- Warning
41+
- Detects packages assigned a usage policy flagged with a warning compliance alert.
42+
* - ``license_policy_error``
43+
- **License Policy Error**
44+
- Error
45+
- Detects packages whose licenses are assigned a usage policy flagged with an error
46+
compliance alert.
47+
* - ``license_policy_warning``
48+
- **License Policy Warning**
49+
- Warning
50+
- Detects packages whose licenses are assigned a usage policy flagged with a warning
51+
compliance alert.
52+
* - ``license_coverage_gap``
53+
- **License Coverage Gap**
54+
- Warning
55+
- Detects packages with no license expression.
56+
57+
**Vulnerability-based rules**
58+
59+
.. list-table::
60+
:header-rows: 1
61+
62+
* - Rule type
63+
- Label
64+
- Severity
65+
- Description
66+
* - ``vulnerability_detected``
67+
- **Vulnerability Detected**
68+
- Error
69+
- Detects packages with at least one known vulnerability. Supports an optional
70+
``min_risk_score`` parameter to restrict detection to vulnerabilities above a
71+
minimum risk score.
72+
* - ``vulnerability_unresolved``
73+
- **Vulnerability Unresolved**
74+
- Warning
75+
- Detects packages with known vulnerabilities that have no completed triage analysis
76+
(i.e., no analysis in a terminal state: resolved, resolved_with_pedigree, or
77+
not_affected).
78+
* - ``vulnerability_stale``
79+
- **Vulnerability Stale**
80+
- Error
81+
- Detects packages with high-risk vulnerabilities that have remained unaddressed
82+
beyond a configurable number of days. Supports ``max_days`` and ``min_risk_score``
83+
parameters.
84+
85+
.. seealso::
86+
Refer to :ref:`reference_vulnerability_management` for background on vulnerability
87+
fields such as risk score used by the vulnerability-based rules.
88+
89+
**Severity levels** determine how violations are displayed in the compliance tab:
90+
91+
- **Error** rules are highlighted in red and indicate a critical compliance issue
92+
requiring immediate attention.
93+
- **Warning** rules are highlighted in yellow and indicate a condition that requires
94+
attention but does not necessarily block a release.
95+
96+
2. Violation Lifecycle
97+
----------------------
98+
99+
Each policy violation is a record associated with a product and a rule type. Its
100+
lifecycle follows these states:
101+
102+
- **Detected**: the violation is created the first time a rule evaluation finds the
103+
condition triggered. The ``detected_date`` is set at this point and never changes.
104+
- **Active**: the violation remains active as long as the condition persists across
105+
subsequent evaluations.
106+
- **Resolved**: when a rule evaluation finds the condition is no longer triggered, the
107+
violation is marked resolved and a ``resolved_date`` is recorded.
108+
- **Re-activated**: if the condition recurs after being resolved, the existing violation
109+
record is updated in place (the original ``detected_date`` is preserved).
110+
111+
Only **active (unresolved)** violations are shown in the compliance tab and returned
112+
by the REST API.
113+
114+
3. Configuration
115+
----------------
116+
117+
Policy rules are configured per dataspace using the ``policy_rules_config`` JSON field
118+
in the **Dataspace Configuration** form, accessible from the Admin interface under
119+
**Dataspaces > Dataspace configurations**.
120+
121+
.. image:: images/reference-policy-rules/dataspace-configuration-policy-rules-config.jpg
122+
123+
Each entry in the JSON object is keyed by the rule type and supports three options:
124+
125+
.. list-table::
126+
:header-rows: 1
127+
128+
* - Key
129+
- Description
130+
* - ``is_active``
131+
- Boolean. Set to ``true`` to enable the rule. Defaults to ``false`` (disabled).
132+
* - ``threshold``
133+
- Integer. Violations are only recorded when the count strictly exceeds this value.
134+
Defaults to ``0``, meaning any violation triggers the rule.
135+
* - ``parameters``
136+
- Object. Rule-specific parameters (see parameter reference below).
137+
138+
**Example configuration**::
139+
140+
{
141+
"usage_policy_error": {
142+
"is_active": true
143+
},
144+
"license_coverage_gap": {
145+
"is_active": true,
146+
"threshold": 2
147+
},
148+
"vulnerability_detected": {
149+
"is_active": true,
150+
"parameters": {
151+
"min_risk_score": 7.0
152+
}
153+
},
154+
"vulnerability_stale": {
155+
"is_active": true,
156+
"parameters": {
157+
"max_days": 14,
158+
"min_risk_score": 8.0
159+
}
160+
}
161+
}
162+
163+
.. note::
164+
Rules that are omitted from the configuration, or that do not have ``is_active``
165+
set to ``true``, are skipped during evaluation and any previously open violations
166+
for those rules are automatically resolved.
167+
168+
3.1 Rule Parameters
169+
^^^^^^^^^^^^^^^^^^^
170+
171+
The following parameters are supported by rules that accept them:
172+
173+
**Vulnerability Detected** (``vulnerability_detected``)
174+
175+
- ``min_risk_score`` (float, 0.0-10.0): only flag packages with at least one
176+
vulnerability whose risk score is greater than or equal to this value. When omitted,
177+
any vulnerability triggers the rule regardless of score.
178+
179+
**Vulnerability Stale** (``vulnerability_stale``)
180+
181+
- ``max_days`` (integer): maximum number of days a high-risk vulnerability may remain
182+
without a completed analysis before the package is flagged. Defaults to ``30``.
183+
- ``min_risk_score`` (float, 0.0-10.0): only consider vulnerabilities whose risk score
184+
is greater than or equal to this value. Defaults to ``8.0``.
185+
186+
4. Evaluation
187+
-------------
188+
189+
4.1 Automatic Evaluation
190+
^^^^^^^^^^^^^^^^^^^^^^^^^
191+
192+
Rules are re-evaluated automatically in the background (via the task queue) whenever
193+
any of the following changes occur:
194+
195+
- A **product** is saved.
196+
- A **package is added to or removed from** a product.
197+
- A **package** record is updated (for example, a new vulnerability is linked to it).
198+
- The **Dataspace Configuration** is saved, which triggers re-evaluation of all
199+
products in the dataspace.
200+
201+
4.2 Manual Re-evaluation
202+
^^^^^^^^^^^^^^^^^^^^^^^^^
203+
204+
Rules can also be re-evaluated on demand in two ways:
205+
206+
- From the **Product Administration** form in the Admin interface, using the
207+
**Evaluate policy rules** bulk action on the product list.
208+
- From the **compliance tab** of a product detail page, using the re-evaluate button
209+
next to the policy violations panel.
210+
211+
.. image:: images/reference-policy-rules/manual-reevaluation-button.jpg
212+
:width: 400
213+
214+
5. Compliance Tab
215+
-----------------
216+
217+
.. image:: images/reference-policy-rules/compliance-tab-policy-violations.jpg
218+
219+
The **Compliance** tab on each product detail page displays an overview of active
220+
policy violations. For each triggered rule, the table shows:
221+
222+
- The rule label and severity (color-coded badge).
223+
- The rule description.
224+
- The number of packages **in violation**, linked to the product inventory pre-filtered
225+
to show only those packages.
226+
- The **detection date** of the violation.
227+
228+
The badge count in the panel header reflects the total number of triggered rules. Its
229+
color is red if at least one error-severity rule is triggered, yellow if only
230+
warning-severity rules are triggered.
231+
232+
Clicking the **info icon** next to the panel title opens a modal listing all configured
233+
rules with their current status (Triggered, OK, or Disabled).
234+
235+
.. image:: images/reference-policy-rules/compliance-tab-policy-rules.jpg
236+
:width: 500
237+
:align: center
238+
239+
6. Webhook Notifications
240+
------------------------
241+
242+
The policy rules engine fires webhook events when violations change state. These can be
243+
used to integrate DejaCode compliance alerts into external workflows such as Slack,
244+
ticketing systems, or CI/CD pipelines.
245+
246+
Two events are available:
247+
248+
- ``policy.violation_detected``: fired when one or more **new** violations are detected
249+
during an evaluation run. The payload includes the product name and a summary of
250+
triggered rules with their violation counts.
251+
- ``policy.violation_resolved``: fired when violations are resolved during an evaluation
252+
run. The payload includes the product name and the number of violations resolved.
253+
254+
.. seealso::
255+
:ref:`integrations_webhook` for instructions on configuring webhook endpoints and
256+
event subscriptions.
257+
258+
7. REST API
259+
-----------
260+
261+
Active policy violations for a product are accessible via the REST API at::
262+
263+
GET /api/v2/products/{uuid}/policy_violations/
264+
265+
The response is a list of active (unresolved) violations, each including:
266+
267+
- ``rule_type``: the rule identifier (e.g., ``vulnerability_detected``).
268+
- ``rule_label``: the human-readable rule name.
269+
- ``rule_description``: a short description of what the rule detects.
270+
- ``rule_severity``: ``"error"`` or ``"warning"``.
271+
- ``violation_count``: the number of packages currently in violation.
272+
- ``detected_date``: when the violation was first recorded.
273+
274+
Only active (unresolved) violations are returned by this endpoint.
275+
276+
.. seealso::
277+
Refer to the **API documentation** from the :guilabel:`Tools` menu for detailed
278+
guidance on authentication and available endpoints.

0 commit comments

Comments
 (0)