How do I set `pod-security.kubernetes.io/enforce` label in namespace of e2e test framework kubernetes

74 Views Asked by At

I want to know how label can be set while namespace is getting created in e2e. This line of code simply creates a namespace https://github.com/kubernetes/kubernetes/blob/v1.25.0/test/e2e/framework/framework.go#L239 and it picks default pod-security.kubernetes.io/ set which is restricted. I want test framework to create namespace with pod-security.kubernetes.io to be Privileged.

1

There are 1 best solutions below

0
Janos Lenart On

This label is set by an admission controller. Setting it manually will cause the controller to reject your pod.

To get the correct Pod Security Policy (PSP) assigned you need RBAC rules that allows use on that PSP: https://v1-24.docs.kubernetes.io/docs/concepts/security/pod-security-policy/#via-rbac

Also, if when several PSPs can be used with a particular Pod they are applied in lexicographical order: https://v1-24.docs.kubernetes.io/docs/concepts/security/pod-security-policy/#policy-order