-
Notifications
You must be signed in to change notification settings - Fork 28
/
policy-privileged-pod-check.rego
44 lines (35 loc) · 1.15 KB
/
policy-privileged-pod-check.rego
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
package kubernetes.admission.policy_privileged_pod
policy_metadata = {
# Set MagTape Policy Info
"name": "policy-privileged-pod",
"severity": "HIGH",
"errcode": "MT2001",
"targets": {"Deployment", "StatefulSet", "DaemonSet", "Pod"},
}
servicetype = input.request.kind.kind
matches {
# Verify request object type matches targets
policy_metadata.targets[servicetype]
}
deny[info] {
# Find container spec
containers := find_containers(servicetype, policy_metadata)
# Check for Privileged SecurityContext in container spec
container := containers[_]
name := container.name
container.securityContext.privileged
msg = sprintf("[FAIL] %v - Found privileged Security Context for container \"%v\" (%v)", [policy_metadata.severity, name, policy_metadata.errcode])
info := {
"name": policy_metadata.name,
"severity": policy_metadata.severity,
"errcode": policy_metadata.errcode,
"msg": msg,
}
}
# find_containers accepts a value (k8s object type) and returns the container spec
find_containers(type, metadata) = input.request.object.spec.containers {
type == "Pod"
}
else = input.request.object.spec.template.spec.containers {
metadata.targets[type]
}