Writing Kubernetes Admission Policies
π Introduction
ποΈ The Admission Review Input Shape
{
"review": {
"operation": "CREATE",
"kind": {
"group": "apps",
"version": "v1",
"kind": "Deployment"
},
"object": {
// the Kubernetes resource being created/updated
},
"oldObject": {
// previous version (for UPDATE operations)
},
"userInfo": {
"username": "system:serviceaccount:ci:deployer",
"groups": ["system:serviceaccounts"]
}
},
"parameters": {
// values from the Constraint instance
}
}π§± Policy 1: Required Labels
πΌοΈ Policy 2: Approved Image Registries
π·οΈ Policy 3: No Latest Tag
π Policy 4: Pod Security β No Root Containers
π Policy 5: Resource Limits Required
π Policy 6: Disallow HostNetwork
π¬ Debugging Policies
1. Check audit violations
2. Test the Rego logic directly
3. Use dryrun enforcement
π Gatekeeper Library
π§ What's Next
π References
Last updated