Home > OS >  Enforce a domain pattern that a service can use
Enforce a domain pattern that a service can use

Time:06-25

I have a multi-tenant Kubernetes cluster. On it I have an nginx reverse proxy with load balancer and the domain *.example.com points to its IP.

Now, several namespaces are essentially grouped together as project A and project B (according to the different users).

How, can I ensure that any service in a namespace with label project=a, can have any domain like my-service.project-a.example.com, but not something like my-service.project-b.example.com or my-service.example.com? Please keep in mind, that I use NetworkPolicies to isolate the communication between the different projects, though communication with the nginx namespace and the reverse proxy is always possible.

Any ideas would be very welcome.

CodePudding user response:

If you want to enforce this rule on k8s object such as configmap or ingress, I think you can use something like OPA

In Kubernetes, Admission Controllers enforce semantic validation of objects during create, update, and delete operations. With OPA you can enforce custom policies on Kubernetes objects without recompiling or reconfiguring the Kubernetes API server.

reference

CodePudding user response:

Alternative to other answer, you may use validation webhook to enfore by any parameter present in the request. Example, name,namespace, annotations, spec etc.

The validation webhook could be a service running in the cluster or External to cluster. This service would essentially make a logical decision based on the logic we put. For every request Sent by user, api server send a review request to the webhook and the validation webhook would either approve or reject the review.

You can read more about it here, more descriptive post by me here.

  • Related