Skip to content

Commit db1aa5b

Browse files
authored
Correct example redaction for secrets (#290)
Previously, this example configuration would only redact the data field in the configmap, but not redact the copy of the data field stored in the "kubectl.kubernetes.io/last-applied-configuration" annotation used by some Kubernetes API clients like kubectl. This could lead to secrets being disclosed in the audit messages sent to the example elastic search.
1 parent 387c373 commit db1aa5b

File tree

1 file changed

+72
-69
lines changed

1 file changed

+72
-69
lines changed

Diff for: examples/full-elastic-stack/k8s/kube-audit-rest.yaml

+72-69
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
---
32
apiVersion: v1
43
kind: ConfigMap
@@ -36,11 +35,15 @@ data:
3635
# redact the actual value of a secret
3736
3837
if .request.requestKind.kind == "Secret" {
38+
# Redact the secret data
3939
del(.request.object.data)
4040
.request.object.data.redacted = "REDACTED"
4141
del(.request.oldObject.data)
4242
.request.oldObject.data.redacted = "REDACTED"
4343
44+
# Remove the previously set secret data - Not bothering to parse it as this annotation shouldn't ever be needed
45+
del(.request.object.metadata.annotations.["kubectl.kubernetes.io/last-applied-configuration"])
46+
del(.request.oldObject.metadata.annotations.["kubectl.kubernetes.io/last-applied-configuration"])
4447
}
4548
filter-spam:
4649
inputs:
@@ -96,69 +99,69 @@ spec:
9699
spec:
97100
automountServiceAccountToken: false
98101
containers:
99-
- image: ghcr.io/richardoc/kube-audit-rest:ad68f71978e8cd610b5b06769fab301cf9ee74d0-distroless@sha256:2444c1207156681c4ed04e7bb02662820c9bfb31b50e8fe5b0112b3f8f577d42
100-
imagePullPolicy: IfNotPresent
101-
name: kube-audit-rest
102-
resources:
103-
requests:
104-
cpu: "2m"
105-
memory: "10Mi"
106-
limits:
107-
cpu: "1"
108-
memory: "32Mi"
109-
ports:
110-
- containerPort: 9090
111-
protocol: TCP
112-
name: https
113-
- containerPort: 55555
114-
protocol: TCP
115-
name: metrics
116-
volumeMounts:
117-
- name: certs
118-
mountPath: "/etc/tls"
119-
readOnly: true
120-
- name: tmp
121-
mountPath: "/tmp"
122-
securityContext:
123-
allowPrivilegeEscalation: false
124-
readOnlyRootFilesystem: true
125-
capabilities:
126-
drop:
127-
- ALL
128-
- name: vector
129-
image: docker.io/timberio/vector:0.33.0-distroless-static@sha256:90e14483720ea7dfa5c39812a30f37d3bf3a94b6611787a0d14055b8ac31eb1f
130-
resources:
131-
requests:
132-
cpu: "2m"
133-
memory: "10Mi"
134-
limits:
135-
cpu: "2"
136-
memory: "512Mi"
137-
env:
138-
- name: ESP
139-
valueFrom:
140-
secretKeyRef:
141-
name: elasticsearch-kube-audit-rest-es-elastic-user
142-
key: elastic
143-
volumeMounts:
144-
- name: tmp
145-
mountPath: "/tmp"
146-
readOnly: true
147-
- name: vector-config
148-
mountPath: "/etc/vector/"
149-
readOnly: true
102+
- image: ghcr.io/richardoc/kube-audit-rest:ad68f71978e8cd610b5b06769fab301cf9ee74d0-distroless@sha256:2444c1207156681c4ed04e7bb02662820c9bfb31b50e8fe5b0112b3f8f577d42
103+
imagePullPolicy: IfNotPresent
104+
name: kube-audit-rest
105+
resources:
106+
requests:
107+
cpu: "2m"
108+
memory: "10Mi"
109+
limits:
110+
cpu: "1"
111+
memory: "32Mi"
112+
ports:
113+
- containerPort: 9090
114+
protocol: TCP
115+
name: https
116+
- containerPort: 55555
117+
protocol: TCP
118+
name: metrics
119+
volumeMounts:
120+
- name: certs
121+
mountPath: "/etc/tls"
122+
readOnly: true
123+
- name: tmp
124+
mountPath: "/tmp"
125+
securityContext:
126+
allowPrivilegeEscalation: false
127+
readOnlyRootFilesystem: true
128+
capabilities:
129+
drop:
130+
- ALL
131+
- name: vector
132+
image: docker.io/timberio/vector:0.33.0-distroless-static@sha256:90e14483720ea7dfa5c39812a30f37d3bf3a94b6611787a0d14055b8ac31eb1f
133+
resources:
134+
requests:
135+
cpu: "2m"
136+
memory: "10Mi"
137+
limits:
138+
cpu: "2"
139+
memory: "512Mi"
140+
env:
141+
- name: ESP
142+
valueFrom:
143+
secretKeyRef:
144+
name: elasticsearch-kube-audit-rest-es-elastic-user
145+
key: elastic
146+
volumeMounts:
147+
- name: tmp
148+
mountPath: "/tmp"
149+
readOnly: true
150+
- name: vector-config
151+
mountPath: "/etc/vector/"
152+
readOnly: true
150153
restartPolicy: Always
151154
terminationGracePeriodSeconds: 30
152155
volumes:
153-
- name: certs
154-
secret:
155-
secretName: kube-audit-rest
156-
- name: tmp
157-
emptyDir:
158-
sizeLimit: 2Gi # Based on default of 3 files at 500Mi
159-
- name: vector-config
160-
configMap:
161-
name: vector-config
156+
- name: certs
157+
secret:
158+
secretName: kube-audit-rest
159+
- name: tmp
160+
emptyDir:
161+
sizeLimit: 2Gi # Based on default of 3 files at 500Mi
162+
- name: vector-config
163+
configMap:
164+
name: vector-config
162165
---
163166
apiVersion: v1
164167
kind: Service
@@ -168,14 +171,14 @@ metadata:
168171
name: kube-audit-rest
169172
spec:
170173
ports:
171-
- name: https
172-
port: 443
173-
protocol: TCP
174-
targetPort: https
175-
- name: metrics
176-
port: 55555
177-
protocol: TCP
178-
targetPort: metrics
174+
- name: https
175+
port: 443
176+
protocol: TCP
177+
targetPort: https
178+
- name: metrics
179+
port: 55555
180+
protocol: TCP
181+
targetPort: metrics
179182
selector:
180183
app: kube-audit-rest
181184
sessionAffinity: None

0 commit comments

Comments
 (0)