-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathk8sManifest.yaml
50 lines (50 loc) · 1.23 KB
/
k8sManifest.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
---
apiVersion: templates.gatekeeper.sh/v1beta1
kind: ConstraintTemplate
metadata:
name: k8snonrootuser
namespace: gatekeeper-system
spec:
crd:
spec:
names:
kind: K8sNonRootUser
targets:
- target: admission.k8s.gatekeeper.sh
rego: |
package k8snonrootuser
violation[{"msg": msg}] {
input.object.kind == "Pod"
input.object.spec.securityContext.runAsNonRoot == false
msg := sprintf("securityContext.runAsNonRoot is set to %v", [input.object.spec.securityContext.runAsNonRoot])
}
violation[{"msg": msg}] {
input.object.kind == "Pod"
input.object.spec.securityContext.runAsUser <= 1
msg := sprintf("Current user UID is %v and required UID should be > 1 ", [input.object.spec.securityContext.runAsUser])
}
---
apiVersion: constraints.gatekeeper.sh/v1beta1
kind: K8sNonRootUser
metadata:
name: non-root-user-all-namespaces
namespace: gatekeeper-system
spec:
match:
kinds:
- apiGroups: [""]
kinds: ["Pod"]
---
apiVersion: v1
kind: Pod
metadata:
namespace: nginx
name: nginx
labels:
app: nginx
spec:
securityContext:
runAsNonRoot: false
containers:
- name: nginx
image: nginx:latest