New “Security Context Constraints” Policies Introduced with Red Hat OpenShift 4.11

New “Security Context Constraints” Policies Introduced with Red Hat OpenShift 4.11

04 Jan 2023

Prepared by: Melek Sima Turunç – Sekom – AppDev & DevOps Specialist

Security Context Constraint (SCC) is a Role-based Access Control (RBAC) technology specific to Red Hat OpenShift’s pods. SCC is a component of Red Hat OpenShift that limits an existing pod to a set of resources. Its primary goal is to restrict a pod’s access to the host environment. Admins use SCCs to control pod permissions and define the conditions that must be met for a pod to be accepted into the system. These permissions include actions a pod can perform, which authorized containers the pod can run, the pod’s SELinux context, and which resources the pod can access.

Sekom | New

Since Kubernetes 1.21, the optional PodSecurityPolicy was used, but with the release of Kubernetes 1.25, it has been completely deprecated and replaced by the Pod Security Admission control component, which is applied at the namespace level. To remain compatible with the changes made in Kubernetes, Red Hat OpenShift has updated its APIs accordingly.

Sekom | New

For more information on which APIs have been deprecated and which versions will no longer be supported, you can refer to the Deprecated API Migration Guide on the Kubernetes website. Additionally, for information on how to update your Red Hat OpenShift operators to accommodate API changes, you can consult the Updating your operators for OpenShift when Kubernetes changes APIs document.

With the introduction of Pod Security Admission Control, namespaces and pods can now be defined with three different pod security standards: Privileged, Baseline, and Restricted. Therefore, as part of the new SCC policies (restricted-v2, nonroot-v2, and hostnetwork-v2) introduced with Red Hat OpenShift 4.11, pods that are not configured with security standards at the namespace level will not be accepted or will fail to run.

Sekom | New

Default Security Context Constraints

Security context constraint(SCC) Description
anyuid Provides all features of the restricted SCC, but allows users to run with any UID and any GID. 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.
hostaccess This SCC allows host access to namespaces, file systems, and PIDs. It should only be used by trusted pods. Grant with caution.
hostmount-anyuid Provides all the features of the restricted SCC, but allows host mounts and running as any UID and any GID on the system. This SCC allows host file system access as any UID, including UID 0. Grant with caution.
hostnetwork Allows using host networking and host ports but still requires pods to be run with a UID and SELinux context that is allocated to the namespace. If additional workloads are run on control plane hosts, use caution when providing access to hostnetwork. A workload that runs hostnetwork on a control plane host is effectively rooted in the cluster and must be trusted accordingly.
hostnetwork-v2 Like the hostnetwork SCC, but with the following differences :

  • ALL capabilities are dropped from containers
  • The NET_BIND_SERVICE capability can be added explicitly.
  • seccompProfile is set to runtime/default by default
  • allowPrivilegeEscalation must be unset or set to false in security contexts. Used for the Prometheus node exporter.
node-exporter Used for the Prometheus node exporter. This SCC allows host file system access as any UID, including UID 0. Grant with caution.
nonroot Provides all features of the restricted SCC, but allows users to run with any non-root UID. The user must specify the UID or it must be specified in the manifest of the container runtime. Like the nonroot SCC, but with the following differences: ALL capabilities are dropped from containers.
nonroot-v2 The NET_BIND_SERVICE capability can be added explicitly.

seccompProfile is set to runtime/default by default.

allowPrivilegeEscalation must be unset or set to false in security contexts.

privileged 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. This is the most relaxed SCC and should be used only for cluster administration. Grant with caution.

The privileged SCC allows:

  • Users to run privileged pods
  • Pods to mount host directories as volumes
  • Pods to run as any user
  • Pods to run with any MCS label
  • Pods to use the host’s IPC namespace
  • Pods to use the host’s PID namespace
  • Pods to use any FSGroup
  • Pods to use any supplemental group
  • Pods to use any seccomp profiles
  • Pods to request any capabilities

Setting privileged: true in the pod specification does not necessarily select the privileged SCC. The SCC that has allowPrivilegedContainer: true and has the highest prioritization will be chosen if the user has permission to use it.

restricted 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 restricted SCC:

  • Ensures that pods cannot run as privileged
  • Ensures that pods cannot mount host directory volumes
  • Requires that a pod is run as a user in a pre-allocated range of UIDs
  • Requires that a pod is run with a pre-allocated MCS label
  • Allows pods to use any FSGroup
  • Allows pods to use any supplemental group

In clusters that were upgraded from OpenShift Container Platform 4.10 or earlier, this SCC is available for use by any authenticated user. The restricted SCC is no longer available to users of new OpenShift Container Platform 4.11 installations unless the access is explicitly granted.

restricted-v2 Like the restricted SCC, but with the following differences:

  • ALL capabilities are dropped from containers.
  • The NET_BIND_SERVICE capability can be added explicitly.
  • seccompProfile is set to runtime/default by default.
  • allowPrivilegeEscalation must be unset or set to false in security contexts

This is the most restrictive SCC provided by a new installation and will be used by default for authenticated users.
The restricted-v2 SCC is the most restrictive of the SCCs that is included by default with the system. However, you can create a custom SCC that is even more restrictive. For example, you can create an SCC that restricts readOnlyRootFilesystem to true.

 

Security Context Constraints Strategies

RunAsUser

  • MustRunAs – Requires a runAsUser to be configured. Uses the configured runAsUser as the default. Validates against the configured runAsUser.
  • 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.
  • MustRunAsNonRoot – Requires that the pod be submitted with a non-zero runAsUser or have the USER directive defined in the image. No default was provided.
  • RunAsAny – No default provided. Allows any runAsUser to be specified.

SELinuxContext

  • MustRunAs – Requires seLinuxOptions to be configured if not using pre-allocated values. Uses seLinuxOptions as the default. Validates against seLinuxOptions
  • RunAsAny – No default provided. Allows any seLinuxOptions to be specified.

SupplementalGroups

  • 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 any SupplementalGroups to be specified.

FSGroup

  • 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 any fsGroup ID to be specified.

Kaynak: Table 1

Errors Caused by SCC and Examples from Knowledgebase:

ISSUE : Red Hat OpenShift 4.11 Workloads Failing with “Operation not permitted” Code

Solution 1 : After upgrading to Red Hat OpenShift Container Platform 4.11, issues arise in specific workloads due to SCC not functioning properly following the migration from the restricted Security Context Constraint to the restricted-v2 Security Context Constraint.

Solution 2 : In Red Hat OpenShift 4.11, processes fail when creating new pods due to the setting “allowPrivilegeEscalation: true”.

Solution 3: Source

Sekom | New

You can stay updated on Red Hat-related news through our blog posts. Click to read our latest post on Red Hat Enterprise Linux 9.1 and 8.7 Released!



Other Posts

Turning Customer Data into Strategic Advantage with Splunk MLTK


A New Era in Security Operations with Splunk Mission Control


The Power Behind Real-Time Web Applications


See all posts

Other Posts

Sekom | New
Turning Customer Data into Strategic Advantage with Splunk MLTK

Turn customer data into strategic advantage with Splunk MLTK. Machine learning anomaly detection, security, and Splunk Enterprise Security.

Read More
Sekom | New
A New Era in Security Operations with Splunk Mission Control

Unify alerts, automate response, and gain full visibility with Splunk Mission Control. Accelerate SOC efficiency—take control today!

Read More
Sekom | New
Understanding Modern Systems: End-to-End Visibility with Splunk Observability

Discover how Splunk Observability provides visibility and faster root cause analysis across systems. Start your observability journey today.

Read More
Sekom | New
Smart Log Analysis with Splunk Machine Learning Toolkit (MLTK)

Unlock insights with Splunk’s Machine Learning Toolkit (MLTK). Detect anomalies, predict trends, optimize operations using machine data.

Read More
Sekom | New
Export Jira Worklog Data with Python and Send It to Your Team via Email

Transfer Jira worklogs to Excel using Python and Jira API. Send via email. Save time with this detailed guide and troubleshooting tips!

Read More
Sekom | New
Jira Time Tracking Automation with Python: Daily API and Cron-Based Solution

Automate daily time tracking using Python, Jira REST API, and cron. A quick guide to holiday-aware reporting and Teams alerts!

Read More

“Building Digital Future”

We are a well-established, reliable, and expert digital transformation integrator, committed to the satisfaction of both our customers and our employees.

Explore