We dig down into what OPA is, how it works with Kubernetes. We focus on how to start consuming it, and some of the things that you discover about your security posture after you start creating declarative OPA policies.
package kubernetes.admission
deny[msg] {
#Calling kind twice because the pod is nested in the AdmissionReview object
input.request.kind.kind == "Pod"
c := input.request.object.spec.containers[i]
c.securityContext.privileged
msg := sprintf("Privileged container is not allowed: %v, securityContext: %v", [c.name, c.securityContext])
}
{
"kind": "AdmissionReview",
"request": {
"kind": {
"kind": "Pod",
"version": "v1"
},
"object": {
"metadata": {
"name": "kfiles-app"
},
"spec": {
"containers": [
{
"name": "pause",
"image": "k8s.gcr.io/pause",
"securityContext": {
"privileged": false
}
}
]
}
}
}
}