|
| 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