Kahibaro
Discord Login Register

13.3 Security Context Constraints

Overview of Security Context Constraints

Security Context Constraints (SCCs) are an OpenShift-specific mechanism that control what a pod is allowed to do at the security context level. While Kubernetes uses Pod Security Admission (and historically PodSecurityPolicies), OpenShift has SCCs as a first-class, cluster-wide resource.

SCCs define security capabilities for pods and containers, such as:

OpenShift evaluates SCCs at pod admission time. A pod is only admitted if, given the user and service account that is creating it, at least one SCC can be applied that both:

  1. Matches the pod’s requested securityContext (or can default it), and
  2. Is allowed for the requesting user/service account.

Key Concepts and Terminology

SCC vs. Pod Security Context

The pod or container securityContext (in the pod spec) is what the workload asks for: user IDs, SELinux contexts, capabilities, etc.

An SCC:

OpenShift admission logic takes your pod spec and an SCC, and:

Built-In SCCs

Common built-in SCCs you will see on most clusters include:

Cluster administrators can create custom SCCs to fit organizational policies.

Main Fields and Controls in an SCC

Understanding the most important SCC fields helps you reason about how they impact workloads.

Privilege and Capabilities

These interact with pod securityContext.capabilities.add and .drop. The SCC enforces a ceiling: requested capabilities must be a subset of what the SCC allows (minus required drops).

User and Group Strategies

These strategies govern UIDs/GIDs:

Together, these enforce or default identities and SELinux labels, enabling multi-tenant isolation while still allowing shared clusters.

Volume and Host Resource Controls

These settings determine whether workloads can escape their container sandbox via the host filesystem or namespaces.

Other Controls

How SCCs Are Applied to Pods

User, Service Accounts, and SCCs

SCCs are granted to:

An SCC has these key association fields:

Service accounts belong to groups such as:

When a pod is created:

  1. The API server identifies the user (if created directly) and/or service account (from spec.serviceAccountName).
  2. It gathers all SCCs that the user or service account is authorized to use.
  3. It tries to apply each candidate SCC to the pod in priority order.

SCC Priority and Selection

SCCs have a priority field (integer). Higher values are evaluated first. The selection process is:

Important implications:

Managing SCCs in Practice

Inspecting SCCs

Common commands with oc:

  oc get scc
  oc describe scc restricted
  oc get pod <pod-name> -o yaml | grep scc

Look for annotations such as:

Granting an SCC to a Service Account

SCCs are cluster-scoped, but they are bound to users and groups via oc adm policy helpers or direct RBAC.

Example: allow a service account in a namespace to use the anyuid SCC:

# Create a service account
oc create sa myapp-sa -n myproject
# Add the SCC to the service account
oc adm policy add-scc-to-user anyuid -z myapp-sa -n myproject

Notes:

To revoke:

oc adm policy remove-scc-from-user anyuid -z myapp-sa -n myproject

Creating a Custom SCC (Conceptually)

A typical workflow to define a custom SCC:

  1. Start from a built-in SCC YAML (for example, restricted).
  2. Modify specific fields:
    • Allow certain capabilities.
    • Adjust runAsUser ranges.
    • Permit a limited set of hostPath mounts.
  3. Apply it to the cluster:
   oc apply -f my-custom-scc.yaml
  1. Bind it to the appropriate service accounts or groups.

When designing a custom SCC, focus on the minimal additional permissions needed for the workload to function.

Common Workload Scenarios and SCC Implications

Non-Root vs. AnyUID

Many container images are designed to run as root by default. With the default restricted SCC:

Options:

Privileged or Host-Accessing Workloads

Some workloads, such as:

may require:

Recommended pattern:

Persistent Storage and SCCs

SCCs can impact volume behavior:

Typical mitigations:

Troubleshooting SCC-Related Issues

Common symptoms of SCC misconfiguration:

Basic troubleshooting steps:

  1. Describe the pod:
   oc describe pod <pod-name>

Look for events related to SCC or securityContext.

  1. Check which SCC was used:
   oc get pod <pod-name> -o yaml | grep openshift.io/scc
  1. Compare the pod’s securityContext to the selected SCC’s restrictions:
   oc describe scc <scc-name>
  1. Adjust:
    • The pod spec (e.g., runAsUser, capabilities, volume types), or
    • The SCC grant (e.g., bind a different SCC to the service account), or
    • The SCC definition (in coordination with cluster admins).

Best Practices for Using SCCs

By carefully designing and applying Security Context Constraints, OpenShift clusters can support diverse workloads—from strict multi-tenant applications to specialized platform services—while maintaining a clear, enforceable security posture at the pod level.

Views: 111

Comments

Please login to add a comment.

Don't have an account? Register now!