What is ValidatingAdmissionPolicy and why does it matter?
AdvancedConceptKubernetes Security
Answer
A built-in, in-process admission policy (GA in Kubernetes 1.30) using CEL expressions. No webhook, no extra deployment, no network hop, so no webhook-outage failure mode.
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata: { name: require-nonroot }
spec:
failurePolicy: Fail
matchConstraints:
resourceRules:
- apiGroups: ["apps"]
apiVersions: ["v1"]
operations: ["CREATE", "UPDATE"]
resources: ["deployments"]
validations:
- expression: >-
has(object.spec.template.spec.securityContext) &&
has(object.spec.template.spec.securityContext.runAsNonRoot) &&
object.spec.template.spec.securityContext.runAsNonRoot == true
message: "runAsNonRoot must be true"
It needs a ValidatingAdmissionPolicyBinding with validationActions: [Deny] (or Warn, Audit) to take effect. It cannot mutate or call external data, so Kyverno and Gatekeeper still cover those cases.
More on Kubernetes Security
What are the 4Cs of cloud native security?BeginnerWhat happens to a request between `kubectl apply` and etcd from a security point of view?IntermediateExplain Role, ClusterRole, RoleBinding and ClusterRoleBinding.BeginnerHow do you check what a user or service account is allowed to do?BeginnerWhich RBAC permissions are effectively cluster-admin in disguise?AdvancedHow do service account tokens work now, and what is `automountServiceAccountToken`?Intermediate