Security Context Constraints (SCCs)
Red Hat OpenShift provides security context constraints (SCCs), a security mechanism that limits the access from a running pod in OpenShift to the host environment.
SCCs control the following host resources:
Running privileged containers
Requesting extra capabilities for a container
Using host directories as volumes
Changing the SELinux context of a container
Changing the user ID
Some community-developed containers might require relaxed security context constraints to access resources that are forbidden by default, such as file systems or sockets, or to access an SELinux context.
Cluster administrators can run the following command to list the SCCs that OpenShift defines:
[user@host ~]$ oc get scc
OpenShift provides the following default SCCs:
For additional information about an SCC, use the oc describe command:
[user@host ~]$ oc describe scc anyuid
Name: anyuid
Priority: 10
Access:
Users: <none>
Groups: system:cluster-admins
Settings:
...output omitted...
Most pods that OpenShift creates use the restricted-v2 SCC, which provides limited access to resources that are external to OpenShift.
Use the oc describe command to view the security context constraint that a pod uses.
[user@host ~]$ oc describe pod console-5df4fcbb47-67c52 \
-n openshift-console | grep scc
openshift.io/scc: restricted-v2
Container images that are downloaded from public container registries, such as Docker Hub, might fail to run when using the restricted-v2 SCC.
For example, a container image that requires running as a specific user ID can fail because the restricted-v2 SCC runs the container by using a random user ID.
A container image that listens on port 80 or on port 443 can fail for a related reason.
The random user ID that the restricted-v2 SCC uses cannot start a service that listens on a privileged network port (port numbers that are less than 1024).
Use the scc-subject-review subcommand to list all the security context constraints that can overcome the limitations that hinder the container:
[user@host ~]$ oc get deployment deployment-name -o yaml | \
oc adm policy scc-subject-review -f -
The anyuid SCC defines the run as user strategy to be RunAsAny, which means that the pod can run as any available user ID in the container.
With this strategy, containers that require a specific user can run the commands by using a specific user ID.
To change the container to run with a different SCC, you must create a service account that is bound to a pod.
Use the oc create serviceaccount command to create the service account, and use the -n option if the service account must be created in a different namespace from the current one:
[user@host ~]$ oc create serviceaccount service-account-name
To associate the service account with an SCC, use the oc adm policy command.
Identify a service account by using the -z option, and use the -n option if the service account exists in a different namespace from the current one:
[user@host ~]$ oc adm policy add-scc-to-user SCC -z service-account
Important
Only cluster administrators can assign an SCC to a service account or remove an SCC from a service account.
Allowing pods to run with a less restrictive SCC can make your cluster less secure.
Use with caution.
Change an existing deployment or deployment configuration to use the service account by using the oc set serviceaccount command:
[user@host ~]$ oc set serviceaccount deployment/deployment-name \
service-account-name
If the command succeeds, then the pods that are associated with the deployment or deployment configuration redeploy.