-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcontainer-allowed-ports.rego
26 lines (24 loc) · 1.06 KB
/
container-allowed-ports.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
package admission
import data.k8s.matches
###############################################################################
#
# Policy : Container allowed ports
# e.g. should listen on 443
#
###############################################################################
deny[{
"id": "container-allowed-ports", # identifies type of violation
"resource": {
"kind": "pods", # identifies kind of resource
"namespace": namespace, # identifies namespace of resource
"name": name # identifies name of resource
},
"resolution": {"message": msg}, # provides human-readable message to display
}] {
matches[["pods", namespace, name, matched_pod]]
container = matched_pod.spec.containers[_]
port = container.ports[_]
format_int(port.containerPort, 10, portstr)
not re_match("^(443|9090)$", portstr)
msg := sprintf("invalid container port %v for container %v", [portstr, container.name])
}