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
Copy file name to clipboardExpand all lines: website/docs/export.md
+121-4Lines changed: 121 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -41,11 +41,13 @@ data:
41
41
- `config`field is a json object that configures how the connection is made. E.g. which queue messages should be sent to.
42
42
43
43
#### Available drivers
44
-
Dapr: https://dapr.io/
44
+
45
+
- Dapr: Export violations using pubsub model provided with [Dapr](https://dapr.io/)
46
+
- Disk: Export violations to file system.
45
47
46
48
### Quick start with exporting violations using Dapr and Redis
47
49
48
-
#### Prerequisites
50
+
#### Prerequisites for Dapr
49
51
50
52
1. Install Dapr
51
53
@@ -130,10 +132,10 @@ Dapr: https://dapr.io/
130
132
```
131
133
132
134
:::important
133
-
Please make sure `fake-subscriber` image is built and available in your cluster. Dockerfile to build image for `fake-subscriber` is under [gatekeeper/test/fake-subscriber](https://github.com/open-policy-agent/gatekeeper/tree/master/test/export/fake-subscriber).
135
+
Please make sure `fake-subscriber` image is built and available in your cluster. Dockerfile to build image for `fake-subscriber` is under [gatekeeper/test/export/fake-subscriber](https://github.com/open-policy-agent/gatekeeper/tree/master/test/export/fake-subscriber).
134
136
:::
135
137
136
-
#### Configure Gatekeeper with Export enabled
138
+
#### Configure Gatekeeper with Export enabled with Dapr
137
139
138
140
1. Create Gatekeeper namespace, and create Dapr pubsub component and Redis secret in Gatekeeper's namespace (`gatekeeper-system` by default). Please make sure to update `gatekeeper-system` namespace for the next steps if your cluster's Gatekeeper namespace is different.
2. Update `gatekeeper-audit` deployment to add `emptyDir` volume.
225
+
226
+
```yaml
227
+
volumes:
228
+
- emptyDir: {}
229
+
name: tmp-violations
230
+
```
231
+
232
+
:::tip
233
+
You can replace emptyDir to use PVC or any other types of volumes.
234
+
:::
235
+
236
+
3. Update `gatekeeper-audit` deployment to add `volumeMount` to `manager` container.
237
+
238
+
```yaml
239
+
volumeMounts:
240
+
- mountPath: /tmp/violations
241
+
name: tmp-violations
242
+
```
243
+
244
+
4. Update `gatekeeper-audit` deployment to add a `sidecar` reader container.
245
+
246
+
```yaml
247
+
volumeMounts:
248
+
- mountPath: /tmp/violations
249
+
name: tmp-violations
250
+
- name: go-sub
251
+
image: <your_img_name:tag>
252
+
imagePullPolicy: Never
253
+
securityContext:
254
+
allowPrivilegeEscalation: false
255
+
capabilities:
256
+
drop:
257
+
- ALL
258
+
readOnlyRootFilesystem: true
259
+
runAsGroup: 999
260
+
runAsNonRoot: true
261
+
runAsUser: 1000
262
+
seccompProfile:
263
+
type: RuntimeDefault
264
+
volumeMounts:
265
+
- mountPath: /tmp/violations
266
+
name: tmp-violations
267
+
```
268
+
269
+
#### Configure Gatekeeper with Export enabled to Disk
270
+
271
+
1. Update `gatekeeper-audit` deployment to add following flags
272
+
273
+
```yaml
274
+
...
275
+
- --enable-violation-export=true
276
+
- --audit-connection=audit
277
+
- --audit-channel=audit
278
+
...
279
+
```
280
+
281
+
2. Deploy Gatekeeper charts with aforementioned changes.
282
+
283
+
:::tip
284
+
You can use below command that uses a rule defined in [Makefile](https://github.com/open-policy-agent/gatekeeper/blob/master/Makefile) to deploy gatekeeper that mounts emptyDir with sidecar reader container.
285
+
286
+
287
+
make deploy IMG=gatekeeper-e2e:latest IMG=<gatekeeper_image> EXPORT_BACKEND=disk FAKE_READER_IMAGE=<your_reader_image>
288
+
:::
289
+
290
+
**Note:** Verify that after the audit pod is running there is a Dapr sidecar injected and running along side `manager` container.
291
+
292
+
3. Create connection config to establish a connection.
293
+
294
+
```shell
295
+
kubectl apply -f - <<EOF
296
+
apiVersion: v1
297
+
kind: ConfigMap
298
+
metadata:
299
+
name: audit
300
+
namespace: gatekeeper-system
301
+
data:
302
+
driver: "disk"
303
+
config: |
304
+
{
305
+
"path": "/tmp/violations",
306
+
"maxAuditResults": 3
307
+
}
308
+
309
+
EOF
310
+
```
311
+
312
+
**Note:** Name of the connection configMap must match the value of `--audit-connection` for it to be used by audit to export violation. At the moment, only one connection config can exists for audit.
313
+
314
+
4. Create the constraint templates and constraints, and make sure audit ran by checking constraints. If constraint status is updated with information such as `auditTimeStamp` or `totalViolations`, then audit has ran at least once. Additionally, populated `TOTAL-VIOLATIONS` field for all constraints while listing constraints also indicates that audit has ran at least once.
315
+
316
+
```log
317
+
kubectl get constraint
318
+
NAME ENFORCEMENT-ACTION TOTAL-VIOLATIONS
319
+
pod-must-have-test 0
320
+
```
321
+
322
+
5. Finally, check the sidecar reader logs to see the violations written.
2025/03/05 00:37:16 {"id":"2025-03-05T00:37:13Z","details":{"missing_labels":["test"]},"eventType":"violation_audited","group":"constraints.gatekeeper.sh","version":"v1beta1","kind":"K8sRequiredLabels","name":"pod-must-have-test","message":"you must provide labels: {\"test\"}","enforcementAction":"deny","resourceAPIVersion":"v1","resourceKind":"Pod","resourceNamespace":"nginx","resourceName":"nginx-deployment-2-79479fc6db-7qbnm","resourceLabels":{"app":"nginx-ingress","app.kubernetes.io/component":"controller","pod-template-hash":"79479fc6db"}}
327
+
```
328
+
212
329
### Violations
213
330
214
331
The audit pod exports violations in following format:
0 commit comments