Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

What are Security Context Constraints (SCC) in OpenShift?

🔐 What are Security Context Constraints (SCC) in OpenShift?

Security Context Constraints (SCC) are OpenShift’s mechanism for controlling security-sensitive aspects of how containers run in the cluster. SCCs define a set of rules that govern what actions a pod or container can perform and what privileges it can have.

They are a powerful RBAC + security enforcement layer, unique to OpenShift, built to enforce strong multi-tenancy and non-root container execution — making it more secure than vanilla Kubernetes by default.


🚧 Why SCCs Matter

By default, OpenShift enforces non-root, least privilege principles through SCCs. This prevents containers from:

  • Running as the root user
  • Mounting host paths
  • Running privileged containers
  • Escaping the container isolation

This protects the cluster from poorly configured or potentially malicious workloads.


🧱 Key Features of SCC

SCC AttributeWhat It Does
runAsUserControls if the pod can run as root or must use a specific UID
seLinuxContextDefines SELinux labels that must be applied to containers
allowPrivilegedContainerDetermines whether a pod can request privileged mode
volumesLimits which volume types (e.g., hostPath, PVC) a pod can mount
allowHostNetworkDetermines if a pod can use the host’s network namespace
allowHostPID/IPCControls access to the host’s PID or IPC namespaces
readOnlyRootFilesystemForces the container to use a read-only root filesystem

🧩 Default SCCs in OpenShift

SCC NameUse CaseAllows Running as Root?Privileged?
restrictedDefault for most users❌ No❌ No
anyuidFor workloads that require root✅ Yes❌ No
privilegedFor system-level workloads✅ Yes✅ Yes
hostaccessAllows host network and volumes✅ Yes❌ No
nonrootMust run as non-root explicitly❌ No❌ No
baseline (v4.x+)Common for unprivileged workloads❌ No❌ No

You can view all SCCs in your cluster with:

oc get scc

And inspect details with:

oc describe scc restricted

🔑 Binding SCCs to Users/Service Accounts

OpenShift assigns SCCs using RBAC bindings to users, groups, or service accounts. Example:

oc adm policy add-scc-to-user anyuid -z myserviceaccount -n mynamespace

This allows your pod to run under the anyuid SCC — enabling it to run as root, if required.


⚠️ Common SCC-Related Errors

  • “permission denied” when trying to bind to port < 1024 → likely due to restricted SCC not allowing root.
  • “hostPath volume mounts are not allowed” → SCC does not permit hostPath volume type.
  • Container fails to start due to UID mismatch → Pod expected to run with a specific UID or non-root.

✅ Best Practices

  • Stick with the restricted SCC whenever possible.
  • Avoid using anyuid or privileged unless absolutely necessary.
  • Use custom SCCs for edge cases (e.g., to allow hostPath volumes or specific capabilities).
  • Always audit SCC use for security compliance.

Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.

0
Would love your thoughts, please comment.x
()
x