You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| `excludedNamespaces` | *(empty)* | List of namespace globs patterns to exclude from processing. Each pattern is converted into a --namespace=!<pattern> CLI argument passed to the operator Deployment. Reports from these namespaces will be ignored (optional). |
131
+
| `transformation.enabled` | `false` | Enable the transformation hook to modify reports before upload. |
132
+
| `transformation.scriptConfigMap` | *(empty)* | Name of a ConfigMap containing the transformation script. |
133
+
| `transformation.scriptFilename` | `transform.py` | Filename of the script within the ConfigMap. |
134
+
| `transformation.interpreter` | `python3` | Command used to execute the script (e.g., `python3`, `bash`, `jq`). |
135
+
| `transformation.scanType` | `Generic Findings Import` | The DefectDojo scanner type (parser) to use if the transformation is successful. |
130
136
131
137
### A note on eval
132
138
@@ -141,6 +147,45 @@ evaluated and used as the engagement name.
141
147
If you set defectDojoEngagementName to `body["report"]["artifact"]["tag"]`,
142
148
then the engagement will get the name of the specified image-tag.
143
149
150
+
## Transformation Hook
151
+
152
+
The transformation hook allows you to manipulate the report data exactly as you need it before it reaches DefectDojo. Common use cases include:
153
+
* Custom deduplication logic.
154
+
* Enriching findings with specific labels from the scanned image.
155
+
* Filtering out specific findings.
156
+
157
+
### How it works
158
+
The operator serializes the raw Trivy report to a JSON string and pipes it into your script's `stdin`. Your script must write the final modified JSON to `stdout`.
159
+
160
+
If the script exits with code `0`, the operator uses the modified content and switches the DefectDojo `scan_type` to the one configured in `transformation.scanType`. If the script fails, the operator automatically falls back to sending the original report with the default "Trivy Operator Scan" type.
161
+
162
+
### Example: Using JQ
163
+
To simply remove a specific field from the report, you can use `jq` as your interpreter:
164
+
165
+
```yaml
166
+
transformation:
167
+
enabled: true
168
+
interpreter: "jq"
169
+
scriptConfigMap: "jq-transform-cm"
170
+
scriptFilename: "filter.jq"
171
+
scanType: "Generic Findings Import"
172
+
```
173
+
174
+
### Example: Custom Shell Script
175
+
If you need more complex logic, use a shell script:
`trivy-dojo-report-operator` is a Kubernetes operator that automates the export of security reports from the Trivy Operator to DefectDojo. It is built using Python and the Kopf (Kubernetes Operator Pythonic Framework) framework.
5
+
6
+
## Architecture
7
+
8
+
The operator acts as a bridge between the Kubernetes cluster's security state (managed by Trivy) and the vulnerability management system (DefectDojo).
9
+
10
+
### "Agents" (Handlers)
11
+
12
+
The system consists of the following event handlers (agents) defined in `src/handlers.py`:
13
+
14
+
1.**Startup Agent (`configure`)**
15
+
-**Type:**`@kopf.on.startup()`
16
+
-**Responsibility:** Initializes the operator configuration, setting timeouts for watching resources to prevent connection drops, and configuring the persistence storage mechanism (`StatusDiffBaseStorage`) to handle large resource objects efficiently without overloading Kubernetes annotations.
-**Trigger:** Creation of Trivy-generated Custom Resources (CRs). The specific resources watched are configurable, but typically include:
21
+
-`vulnerabilityreports.aquasecurity.github.io`
22
+
-`configauditreports.aquasecurity.github.io`
23
+
-`exposedsecretreports.aquasecurity.github.io`
24
+
-`infraassessmentreports.aquasecurity.github.io`
25
+
-`rbacassessmentreports.aquasecurity.github.io`
26
+
-**Responsibility:**
27
+
-**Extraction:** Extracts the full manifest of the created report.
28
+
-**Transformation:** Converts the Kubernetes object into a JSON-compatible dictionary.
29
+
-**Context Resolution:** dynamic evaluation of DefectDojo engagement parameters (Product Type, Product, Environment, Engagement Name) using the logic in `settings.py`.
30
+
-**Transmission:** Uploads the report to the DefectDojo API (`/api/v2/import-scan/`) using the `requests` library.
31
+
-**Observability:** Records Prometheus metrics, including processing time (`request_processing_seconds`) and request counters (`requests_total`).
32
+
33
+
## Configuration
34
+
35
+
The agents are configured via environment variables (loaded in `src/settings.py` and `src/env_vars.py`), controlling:
36
+
37
+
-**Connectivity:** DefectDojo URL (`DEFECT_DOJO_URL`) and API Key (`DEFECT_DOJO_API_KEY`).
38
+
-**Scope:** optional filtering by Kubernetes Label (`LABEL`, `LABEL_VALUE`).
39
+
-**Import Logic:**
40
+
-`DEFECT_DOJO_ACTIVE`: Whether findings are marked as active.
41
+
-`DEFECT_DOJO_VERIFIED`: Whether findings are marked as verified.
42
+
-`DEFECT_DOJO_CLOSE_OLD_FINDINGS`: Whether to close old findings in DefectDojo.
43
+
-`DEFECT_DOJO_PUSH_TO_JIRA`: Whether to push findings to Jira.
44
+
45
+
## Deployment
46
+
47
+
The operator is packaged as a Docker container and deployed via a Helm chart located in the `charts/` directory.
0 commit comments