About security context constraints
You can use security context constraints (SCCs) to control permissions for pods by defining what actions a pod can perform, what resources it can access, and what conditions it must meet to be accepted into the system.
Security context constraints allow an administrator to control:
-
Whether a pod can run privileged containers with the
allowPrivilegedContainerflag -
Whether a pod is constrained with the
allowPrivilegeEscalationflag -
The capabilities that a container can request
-
The use of host directories as volumes
-
The SELinux context of the container
-
The container user ID
-
The use of host namespaces and networking
-
The allocation of an
FSGroupthat owns the pod volumes -
The configuration of allowable supplemental groups
-
Whether a container requires write access to its root file system
-
The usage of volume types
-
The configuration of allowable
seccompprofiles
|
|
Do not set the |
Default security context constraints
The cluster contains several default security context constraints (SCCs) as described in the table below. Additional SCCs might be installed when you install Operators or other components to Red Hat OpenShift Container Platform.
|
|
Do not modify the default SCCs. Customizing the default SCCs can lead to issues when some of the platform pods deploy or Red Hat OpenShift Container Platform is upgraded. Additionally, the default SCC values are reset to the defaults during some cluster upgrades, which discards all customizations to those SCCs. Instead of modifying the default SCCs, create and modify your own SCCs as needed. For detailed steps, see Creating security context constraints. |
| Security context constraint | Description | ||||
|---|---|---|---|---|---|
|
Provides all features of the |
||||
|
Allows access to all host namespaces but still requires pods to be run with a UID and SELinux context that are allocated to the namespace.
|
||||
|
Provides all the features of the
|
||||
|
Allows using host networking and host ports but still requires pods to be run with a UID and SELinux context that are allocated to the namespace.
|
||||
|
Like the
|
||||
|
Like the
This SCC allows a user to run a container engine inside of an Red Hat OpenShift Container Platform pod. |
||||
|
Used for the Prometheus node exporter.
|
||||
|
Provides all features of the |
||||
|
Like the
|
||||
|
Allows access to all privileged and host features and the ability to run as any user, any group, any FSGroup, and with any SELinux context.
The
|
||||
|
Denies access to all host features and requires pods to be run with a UID, and SELinux context that are allocated to the namespace. The
In clusters that were upgraded from Red Hat OpenShift Container Platform 4.10 or earlier, this SCC is available for use by any authenticated user. The |
||||
|
Like the
This SCC is used by default for authenticated users. |
||||
|
Like the
This is the most restrictive SCC provided by a new installation and will be used by default for authenticated users.
|
Security context constraints settings
Security context constraints (SCCs) are composed of settings and strategies that control the security features a pod has access to. These settings fall into three categories:
| Category | Description |
|---|---|
Controlled by a boolean |
Fields of this type default to the most restrictive value. For example,
|
Controlled by an allowable set |
Fields of this type are checked against the set to ensure their value is allowed. |
Controlled by a strategy |
Items that have a strategy to generate a value provide:
|
CRI-O has the following default list of capabilities that are allowed for each container of a pod:
-
CHOWN -
DAC_OVERRIDE -
FSETID -
FOWNER -
SETGID -
SETUID -
SETPCAP -
NET_BIND_SERVICE -
KILL
The containers use the capabilities from this default list, but pod manifest authors can alter the list by requesting additional capabilities or removing some of the default behaviors. Use the allowedCapabilities, defaultAddCapabilities, and requiredDropCapabilities parameters to control such requests from the pods. With these parameters you can specify which capabilities can be requested, which ones must be added to each container, and which ones must be forbidden, or dropped, from each container.
|
|
You can drop all capabilites from containers by setting the |
Security context constraints strategies
-
MustRunAs- Requires arunAsUserto be configured. Uses the configuredrunAsUseras the default. Validates against the configuredrunAsUser.ExampleMustRunAssnippet... runAsUser: type: MustRunAs uid: <id> ... -
MustRunAsRange- Requires minimum and maximum values to be defined if not using pre-allocated values. Uses the minimum as the default. Validates against the entire allowable range.ExampleMustRunAsRangesnippet... runAsUser: type: MustRunAsRange uidRangeMax: <maxvalue> uidRangeMin: <minvalue> ... -
MustRunAsNonRoot- Requires that the pod be submitted with a non-zerorunAsUseror have theUSERdirective defined in the image. No default provided.ExampleMustRunAsNonRootsnippet... runAsUser: type: MustRunAsNonRoot ... -
RunAsAny- No default provided. Allows anyrunAsUserto be specified.ExampleRunAsAnysnippet... runAsUser: type: RunAsAny ...
-
MustRunAs- RequiresseLinuxOptionsto be configured if not using pre-allocated values. UsesseLinuxOptionsas the default. Validates againstseLinuxOptions. -
RunAsAny- No default provided. Allows anyseLinuxOptionsto be specified.
-
MustRunAs- Requires at least one range to be specified if not using pre-allocated values. Uses the minimum value of the first range as the default. Validates against all ranges. -
RunAsAny- No default provided. Allows anysupplementalGroupsto be specified.
-
MustRunAs- Requires at least one range to be specified if not using pre-allocated values. Uses the minimum value of the first range as the default. Validates against the first ID in the first range. -
RunAsAny- No default provided. Allows anyfsGroupID to be specified.
Controlling volumes
The usage of specific volume types
can be controlled by setting the volumes
field of the SCC.
The allowable values of this field correspond to the volume sources that are defined when creating a volume:
-
photonPersistentDisk -
* (A special value to allow the use of all volume types.)
-
none(A special value to disallow the use of all volumes types. Exists only for backwards compatibility.)
The recommended minimum set of allowed volumes for new SCCs are configMap,
downwardAPI, emptyDir, persistentVolumeClaim, secret, and projected.
|
|
This list of allowable volume types is not exhaustive because new types are added with each release of Red Hat OpenShift Container Platform. |
|
|
For backwards compatibility, the usage of |
Admission control
Admission control with SCCs allows for control over the creation of resources based on the capabilities granted to a user.
In terms of the SCCs, this means that an admission controller can inspect the user information made available in the context to retrieve an appropriate set of SCCs. Doing so ensures the pod is authorized to make requests about its operating environment or to generate a set of constraints to apply to the pod.
The set of SCCs that admission uses to authorize a pod are determined by the user identity and groups that the user belongs to. Additionally, if the pod specifies a service account, the set of allowable SCCs includes any constraints accessible to the service account.
|
|
When you create a workload resource, such as a deployment, only the service account is used to find the SCCs and is used to admit the pods when they are created. |
|
|
When creating pods directly, SCCs admission considers SCC permissions of both the caller and the Service Account that runs the pod. When a pod is created by a pod controller such as a deployment or a job, only Service Account SCC permissions are considered. |
Admission uses the following approach to create the final security context for the pod:
-
Retrieve all SCCs available for use.
-
Generate field values for security context settings that were not specified on the request.
-
Validate the final settings against the available constraints.
If a matching set of constraints is found, then the pod is accepted. If the request cannot be matched to an SCC, the pod is rejected.
A pod must validate every field against the SCC. The following are examples for just two of the fields that must be validated:
|
|
These examples are in the context of a strategy using the pre-allocated values. |
An FSGroup SCC strategy of MustRunAs
If the pod defines a fsGroup ID, then that ID must equal the default
fsGroup ID. Otherwise, the pod is not validated by that SCC and the next SCC
is evaluated.
If the SecurityContextConstraints.fsGroup field has value RunAsAny
and the pod specification omits the Pod.spec.securityContext.fsGroup,
then this field is considered valid. Note that it is possible that during
validation, other SCC settings will reject other pod fields and thus cause the
pod to fail.
A SupplementalGroups SCC strategy of MustRunAs
If the pod specification defines one or more supplementalGroups IDs, then
the pod’s IDs must equal one of the IDs in the namespace’s
openshift.io/sa.scc.supplemental-groups annotation. Otherwise, the pod is not
validated by that SCC and the next SCC is evaluated.
If the SecurityContextConstraints.supplementalGroups field has value RunAsAny
and the pod specification omits the Pod.spec.securityContext.supplementalGroups,
then this field is considered valid. Note that it is possible that during
validation, other SCC settings will reject other pod fields and thus cause the
pod to fail.
Security context constraints prioritization
Security context constraints (SCCs) have a priority field that affects the ordering when attempting to validate a request by the admission controller.
|
|
Setting an SCC priority greater than 0 for the default Red Hat OpenShift Container Platform SCCs can cause critical cluster instability. |
A priority value of 0 is the lowest possible priority. A nil priority is considered a 0, or lowest, priority. Higher priority SCCs are moved to the front of the set when sorting.
When the complete set of available SCCs is determined, the SCCs are ordered in the following manner:
-
The highest priority SCCs are ordered first.
-
If the priorities are equal, the SCCs are sorted from most restrictive to least restrictive.
-
If both the priorities and restrictions are equal, the SCCs are sorted by name.
By default, the anyuid SCC granted to cluster administrators is given priority
in their SCC set. This allows cluster administrators to run pods as any
user by specifying RunAsUser in the pod’s SecurityContext.