Last active
November 25, 2020 17:03
-
-
Save developer-guy/e7aec722c4f61f32d0cc03c2a42b144c to your computer and use it in GitHub Desktop.
OPA Gatekeeper Restrict Privileged Containers within Deployment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: templates.gatekeeper.sh/v1beta1 | |
kind: ConstraintTemplate | |
metadata: | |
name: noprivileged | |
spec: | |
crd: | |
spec: | |
names: | |
kind: NoPrivileged | |
listKind: NoPrivilegedList | |
plural: NoPrivileged | |
singular: NoPrivilegeds | |
targets: | |
- target: admission.k8s.gatekeeper.sh | |
rego: | | |
package noprivileged | |
violation[{"msg": msg, "details": {}}] { | |
c := input.review.object.spec.template.spec.containers[_] | |
c.securityContext.privileged | |
msg := sprintf("Privileged container is not allowed: %v, securityContext: %v", [c.name, c.securityContext]) | |
} | |
input_containers[c] { | |
c := input.review.object.spec.template.spec.containers[_] | |
} | |
input_containers[c] { | |
c := input.review.object.spec.template.spec.initContainers[_] | |
} | |
--- | |
apiVersion: constraints.gatekeeper.sh/v1beta1 | |
kind: NoPrivileged | |
metadata: | |
name: noprivileged | |
spec: | |
match: | |
kinds: | |
- apiGroups: ["apps"] | |
apiVersions: ["v1","v1beta1"] | |
kinds: ["Deployment"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Helpful links down below: