Skip to content

lalyos/k8s-ns-admission

Repository files navigation

Docker Automated build

Namespace Validaing Admission Webhook

This is a Validating Admission Webhook for k8s. It is validating namespaces create/delete operations, checking name prefixes. The intent is to let the user1 ServiceAccount be able to create/delete any namespace with names starting with user1-

Usage

To deploy the validating admission webhook, just run this one-liner:

kubectl apply -f https://raw.githubusercontent.com/lalyos/k8s-ns-admission/master/deploy-webhook-job.yaml 

Most admission webhook examples requires you to do a lot of manual steps regarding certificate creation. That is all taken care by the job:

  • creates a service account to give certificate relatades access to the job
  • creates a certificate req for the webhook's https endpoint
  • let api-server sign the csr
  • save the cert/key into a secret
  • create a svc/deployment for the webhook (using the generated cert as mounted volume)
  • creates the ValidatingWebhookConfiguration
  • tests the webhook by creating and deleteing a ns "delme"

tl;dr

For k8s workshops you might want to provide isolated workspace for each participant. Let's say you create a separate namespace for each of them. To restrict them to only that specific namespace, we can use RBAC. You can create a ServiceAccount with an appropriate Role to give full access to namespaced resources (pod,deployment,svc,job ...)

But how can they learn to work with namespaces? We might want to give access to user1 to create/delete any namespace with names starting with user1-. Unfortunately RBAC Roles doesnt support pattern based roles. For details see: k8s#56582

Then you might think, lets just give them 1 single predefined ns to create, like user1-play. Therefoe lets create a ClusterRole which gives access to namespaces resources restricted by resourceNames: ["user1-play"]. Unfortunately its not possible, as there is a sidenote in RBAC docs

Notably, if resourceNames are set, then the verb must not be list, watch, create, or delete

References

code is proudly stolen from:

relevant docs:

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published