Kubernetes Admission Webhook
Overviewâ
Casbin K8s-Gatekeeper is a Kubernetes admission webhook that uses Casbin for authorization. You define models and policies declaratively to allow or deny operations on any Kubernetes resourceâno custom code in the webhook. Maintained by the Casbin community: github.com/apache/casbin-k8s-gatekeeper.
Basic exampleâ
Example: deny deployments that use images with a specific tag, using only config:
Model:
[request_definition]
r = obj
[policy_definition]
p = obj,eft
[policy_effect]
e = !some(where (p.eft == deny))
[matchers]
m = r.obj.Request.Namespace == "default" && r.obj.Request.Resource.Resource =="deployments" && \
contain(split(accessWithWildcard(${OBJECT}.Spec.Template.Spec.Containers , "*", "Image"),":",1) , p.obj)
Policy:
p, "1.14.1",deny
This uses standard Casbin ACL language, which should be straightforward if you've read the introductory chapters.
Casbin K8s-Gatekeeper offers several advantages:
- Simple to useâwrite ACL configurations instead of extensive code
- Supports live configuration updates without plugin restarts
- Flexibleâapply arbitrary rules to any Kubernetes resource using
kubectl gatekeeper - Simplifies Kubernetes admission webhook implementationâno need to understand webhook internals or write webhook code. Just define constraints and write Casbin ACL.
- Community-maintainedâcontact us with questions or issues
1.1 How Casbin K8s-Gatekeeper Worksâ
K8s-Gatekeeper is an admission webhook for Kubernetes that uses Casbin to enforce custom access control rules, preventing unwanted operations on Kubernetes resources.
Casbin is an efficient open-source access control library supporting various authorization models. For details, see the Overview.
Admission webhooks in Kubernetes are HTTP callbacks that receive and process admission requests. K8s-Gatekeeper is a ValidatingAdmissionWebhook that accepts or rejects admission requests. Admission requests are HTTP requests describing operations on Kubernetes resources (e.g., creating or deleting a deployment). For more information, see the Kubernetes documentation.