This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
Chapter 9. Managing Security Context Constraints
9.1. Overview Link kopierenLink in die Zwischenablage kopiert!
Security context constraints allow administrators to control permissions for pods. To learn more about this API type please refer to the security context constraints (SCCs) architecture documentation. You may manage SCCs in your instance as normal API objects using the CLI.
You must have cluster-admin privileges to manage SCCs.
9.2. Listing Security Context Constraints Link kopierenLink in die Zwischenablage kopiert!
To get a current list of SCCs:
oc get scc
$ oc get scc
NAME PRIV CAPS HOSTDIR SELINUX RUNASUSER
privileged true [] true RunAsAny RunAsAny
restricted false [] false MustRunAs MustRunAsRange
9.3. Examining a Security Context Constraints Object Link kopierenLink in die Zwischenablage kopiert!
To examine a particular SCC, use oc get
, oc describe
, oc export
, or oc edit
.
- 1
- The SCC name specified in the
oc edit
command.
9.4. Creating New Security Context Constraints Link kopierenLink in die Zwischenablage kopiert!
To create a new SCC, first define the SCC in a JSON or YAML file:
Example 9.1. Security Context Constraint Object Definition
Although this example definition was written by hand, another way is to modify the definition obtained from examining a particular SCC.
Then, run oc create
passing the file to create it:
9.5. Deleting Security Context Constraints Link kopierenLink in die Zwischenablage kopiert!
To delete an SCC:
oc delete scc <scc_name>
$ oc delete scc <scc_name>
If you delete the default SCCs, they will not be regenerated upon restart, unless you delete all SCCs. If any constraint already exists within the system, no regeneration will take place.
9.6. Updating Security Context Constraints Link kopierenLink in die Zwischenablage kopiert!
To update an existing SCC:
oc edit scc <scc_name>
$ oc edit scc <scc_name>
9.7. Updating the default Security Context Constraints Link kopierenLink in die Zwischenablage kopiert!
If you would like to reset your security context constraints to the default settings for any reason you may delete the existing security context constraints and restart your master. The default security context constraints will only be recreated if no security context constraints exist in the system.
9.8. How Do I? Link kopierenLink in die Zwischenablage kopiert!
The following describe common scenarios and procedures using SCCs.
9.8.1. Grant Access to the Privileged SCC Link kopierenLink in die Zwischenablage kopiert!
In some cases, an administrator might want to allow users or groups outside the administrator group access to create more privileged pods. To do so, you can:
- Determine the user or group you would like to have access to the SCC.
Run:
oc edit scc <name>
$ oc edit scc <name>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Add the user or group to the users or groups field of the SCC.
For example, to allow the e2e-user access to the privileged SCC, add their user:
- 1
- The e2e-user added to the users section.
9.8.2. Grant a Service Account Access to the Privileged SCC Link kopierenLink in die Zwischenablage kopiert!
First, create a service account. For example, to create service account My_SVCACCT
in project My_Project
:
Then, add the service account to the privileged
SCC.
oc edit scc privileged
$ oc edit scc privileged
Add the following under users
:
- system:serviceaccount:My_Project:My_SVCACCT
- system:serviceaccount:My_Project:My_SVCACCT
9.8.3. Enable Images to Run with USER in the Dockerfile Link kopierenLink in die Zwischenablage kopiert!
To relax the security in your cluster so that images are not forced to run as a pre-allocated UID, without granting everyone access to the privileged SCC:
Edit the restricted SCC:
oc edit scc restricted
$ oc edit scc restricted
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Change the
runAsUser.Type
strategy to RunAsAny.
This allows images to run as the root UID if no USER is specified in the Dockerfile.
9.8.4. Use --mount-host on the Registry Link kopierenLink in die Zwischenablage kopiert!
It is recommended that persistent storage using PersistentVolume
and PersistentVolumeClaim
objects be used for registry deployments. If you are testing and would like to instead use the oadm registry
command with the --mount-host
option, you must first create a new service account for the registry and add it to the privileged SCC. See the Administrator Guide for full instructions.
9.8.5. Provide Additional Capabilities Link kopierenLink in die Zwischenablage kopiert!
In some cases, an image may require capabilities that Docker does not provide out of the box. You can provide the ability to request additional capabilities in the pod specification which will be validated against an SCC.
This allows images to run with elevated capabilities and should be used only if necessary. You should not edit the default restricted SCC to enable additional capabilities.
When used in conjunction with a non-root user, you must also ensure that the file that requires the additional capability is granted the capabilities using the setcap
command. For example, in the Dockerfile of the image:
setcap cap_net_raw,cap_net_admin+p /usr/bin/ping
setcap cap_net_raw,cap_net_admin+p /usr/bin/ping
Further, if a capability is provided by default in Docker, you do not need to modify the pod specification to request it. For example, NET_RAW
is provided by default and capabilities should already be set on ping
, therefore no special steps should be required to run ping
.
To provide additional capabilities:
Create a new SCC or edit the privileged SCC:
oc edit scc <name>
$ oc edit scc <name>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Add the allowed capability using the
allowedCapabilities
field. -
When creating the pod, request the capability in the
securityContext.capabilities.add
field.
9.8.6. Modify Cluster Default Behavior Link kopierenLink in die Zwischenablage kopiert!
To modify your cluster so that it does not pre-allocate UIDs, allows containers to run as any user, and prevents privileged containers:
Edit the restricted SCC:
oc edit scc restricted
$ oc edit scc restricted
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Change
runAsUser.Type
to RunAsAny. -
Ensure
allowPrivilegedContainer
is set to false. - Save the changes.
To modify your cluster so that it does not pre-allocate UIDs and does not allow containers to run as root:
Edit the restricted SCC:
oc edit scc restricted
$ oc edit scc restricted
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Change
runAsUser.Type
to MustRunAsNonRoot. - Save the changes.
9.8.7. Use the hostPath Volume Plug-in Link kopierenLink in die Zwischenablage kopiert!
To relax the security in your cluster so that pods are allowed to use the hostPath
volume plug-in without granting everyone access to the privileged SCC:
Edit the restricted SCC:
oc edit scc restricted
$ oc edit scc restricted
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Add
allowHostDirVolumePlugin: true
. - Save the changes.