text stringlengths 0 59.1k |
|---|
We can then create role bindings to grant those permissions. |
* A `RoleBinding` would grant those permissions within a particular namespace |
* A `ClusterRoleBinding` would grant those permissions across all namespaces |
In this example, we will create `ClusterRoleBindings` to grant the roles to groups cluster-wide. |
1. `privileged-psp-user`: this group is bound to the `privileged-psp-user` role and `restricted-psp-user` role which gives users |
in this group access to both policies. |
1. `restricted-psp-user`: this group is bound to the `restricted-psp-user` role. |
1. `system:authenticated`: this is a system group for any authenticated user. It is bound to the `edit` |
role which is already provided by the cluster. |
To create these roles and bindings run |
``` |
$ kubectl --server=https://127.0.0.1:6443 --token=foo/system:masters create -f staging/podsecuritypolicy/rbac/roles.yaml |
clusterrole "restricted-psp-user" created |
clusterrole "privileged-psp-user" created |
$ kubectl --server=https://127.0.0.1:6443 --token=foo/system:masters create -f staging/podsecuritypolicy/rbac/bindings.yaml |
clusterrolebinding "privileged-psp-users" created |
clusterrolebinding "restricted-psp-users" created |
clusterrolebinding "edit" created |
``` |
## Testing access |
### Restricted user can create non-privileged pods |
Create the pod |
``` |
$ kubectl --server=https://127.0.0.1:6443 --token=foo/restricted-psp-users create -f staging/podsecuritypolicy/rbac/pod.yaml |
pod "nginx" created |
``` |
Check the PSP that allowed the pod |
``` |
$ kubectl get pod nginx -o yaml | grep psp |
kubernetes.io/psp: restricted |
``` |
### Restricted user cannot create privileged pods |
Delete the existing pod |
``` |
$ kubectl delete pod nginx |
pod "nginx" deleted |
``` |
Create the privileged pod |
``` |
$ kubectl --server=https://127.0.0.1:6443 --token=foo/restricted-psp-users create -f staging/podsecuritypolicy/rbac/pod_priv.yaml |
Error from server (Forbidden): error when creating "staging/podsecuritypolicy/rbac/pod_priv.yaml": pods "nginx" is forbidden: unable to validate against any pod security policy: [spec.containers[0].securityContext.privileged: Invalid value: true: Privileged containers are not allowed] |
``` |
### Privileged user can create non-privileged pods |
``` |
$ kubectl --server=https://127.0.0.1:6443 --token=foo/privileged-psp-users create -f staging/podsecuritypolicy/rbac/pod.yaml |
pod "nginx" created |
``` |
Check the PSP that allowed the pod. |
``` |
$ kubectl get pod nginx -o yaml | egrep "psp|privileged" |
kubernetes.io/psp: privileged |
``` |
In the versions prior 1.9 this could be the `restricted` or `privileged` PSP |
since both allow for the creation of non-privileged pods. Starting from 1.9 |
release, the `privileged` PSP will always be used as it accepts the pod as-is |
(without defaulting/mutating). |
### Privileged user can create privileged pods |
Delete the existing pod |
``` |
$ kubectl delete pod nginx |
pod "nginx" deleted |
``` |
Create the privileged pod |
``` |
$ kubectl --server=https://127.0.0.1:6443 --token=foo/privileged-psp-users create -f staging/podsecuritypolicy/rbac/pod_priv.yaml |
pod "nginx" created |
``` |
Check the PSP that allowed the pod. |
``` |
$ kubectl get pod nginx -o yaml | egrep "psp|privileged" |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.