text
stringlengths
0
59.1k
`staging` subdirectory of this repository checkout. For example, if you've
checked out Kubernetes as
```console
$ git clone https://github.com/kubernetes/kubernetes
```
and this examples repository next to it as
```console
$ git clone https://github.com/kubernetes/examples
```
create symlink
```console
$ ( cd kubernetes && ln -s ../examples/staging examples )
```
### Policies
The first step to enforcing cluster constraints via PSP is to create your policies. In this
example we will use two policies, `restricted` and `privileged`. The `privileged` policy allows any type of pod.
The `restricted` policy only allows limited users, groups, volume types, and does not allow host access or privileged containers.
```yaml
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
name: privileged
spec:
fsGroup:
rule: RunAsAny
privileged: true
runAsUser:
rule: RunAsAny
seLinux:
rule: RunAsAny
supplementalGroups:
rule: RunAsAny
volumes:
- '*'
allowedCapabilities:
- '*'
hostPID: true
hostIPC: true
hostNetwork: true
hostPorts:
- min: 1
max: 65536
---
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
name: restricted
spec:
privileged: false
fsGroup:
rule: RunAsAny
runAsUser:
rule: MustRunAsNonRoot
seLinux:
rule: RunAsAny
supplementalGroups:
rule: RunAsAny
volumes:
- 'emptyDir'
- 'secret'
- 'downwardAPI'
- 'configMap'
- 'persistentVolumeClaim'
- 'projected'
hostPID: false
hostIPC: false
hostNetwork: false
```
To create these policies run
```
$ kubectl --server=https://127.0.0.1:6443 --token=foo/system:masters create -f staging/podsecuritypolicy/rbac/policies.yaml
podsecuritypolicy "privileged" created
podsecuritypolicy "restricted" created
```
### Roles and bindings
In order to create a pod, either the creating user or the service account
specified by the pod must be authorized to use a `PodSecurityPolicy` object
that allows the pod, within the pod's namespace.
That authorization is determined by the ability to perform the `use` verb
on a particular `podsecuritypolicies` resource, at the scope of the pod's namespace.
The `use` verb is a special verb that grants access to use a policy while not permitting any
other access.
Note that a user with superuser permissions within a namespace (access to `*` verbs on `*` resources)
would be allowed to use any PodSecurityPolicy within that namespace.
For this example, we'll first create RBAC `ClusterRoles` that enable access to `use` specific policies.
1. `restricted-psp-user`: this role allows the `use` verb on the `restricted` policy only
2. `privileged-psp-user`: this role allows the `use` verb on the `privileged` policy only