|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * authentication/managing-security-context-constraints.adoc |
| 4 | + |
| 5 | +:_content-type: PROCEDURE |
| 6 | +[id="security-context-constraints-requiring_{context}"] |
| 7 | += Configuring a workload to require a specific SCC |
| 8 | + |
| 9 | +You can configure a workload to require a certain security context constraint (SCC). This is useful in scenarios where you want to pin a specific SCC to the workload or if you want to prevent your required SCC from being preempted by another SCC in the cluster. |
| 10 | + |
| 11 | +To require a specific SCC, set the `openshift.io/required-scc` annotation on your workload. You can set this annotation on any resource that can set a pod manifest template, such as a deployment or daemon set. |
| 12 | + |
| 13 | +The SCC must exist in the cluster and must be applicable to the workload, otherwise pod admission fails. An SCC is considered applicable to the workload if the user creating the pod or the pod's service account has `use` permissions for the SCC in the pod's namespace. |
| 14 | + |
| 15 | +[WARNING] |
| 16 | +==== |
| 17 | +Do not change the `openshift.io/required-scc` annotation in the live pod's manifest, because doing so causes the pod admission to fail. To change the required SCC, update the annotation in the underlying pod template, which causes the pod to be deleted and re-created. |
| 18 | +==== |
| 19 | + |
| 20 | +.Prerequisites |
| 21 | + |
| 22 | +* The SCC must exist in the cluster. |
| 23 | +
|
| 24 | +.Procedure |
| 25 | + |
| 26 | +. Create a YAML file for the deployment and specify a required SCC by setting the `openshift.io/required-scc` annotation: |
| 27 | ++ |
| 28 | +.Example `deployment.yaml` |
| 29 | +[source,yaml] |
| 30 | +---- |
| 31 | +apiVersion: config.openshift.io/v1 |
| 32 | +kind: Deployment |
| 33 | +apiVersion: apps/v1 |
| 34 | +spec: |
| 35 | +# ... |
| 36 | + template: |
| 37 | + metadata: |
| 38 | + annotations: |
| 39 | + openshift.io/required-scc: "my-scc" <1> |
| 40 | +# ... |
| 41 | +---- |
| 42 | +<1> Specify the name of the SCC to require. |
| 43 | + |
| 44 | +. Create the resource by running the following command: |
| 45 | ++ |
| 46 | +[source,terminal] |
| 47 | +---- |
| 48 | +$ oc create -f deployment.yaml |
| 49 | +---- |
| 50 | + |
| 51 | +.Verification |
| 52 | + |
| 53 | +* Verify that the deployment used the specified SCC: |
| 54 | +
|
| 55 | +.. View the value of the pod's `openshift.io/scc` annotation by running the following command: |
| 56 | ++ |
| 57 | +[source,terminal] |
| 58 | +---- |
| 59 | +$ oc get pod <pod_name> -o jsonpath='{.metadata.annotations.openshift\.io\/scc}{"\n"}' <1> |
| 60 | +---- |
| 61 | +<1> Replace `<pod_name>` with the name of your deployment pod. |
| 62 | + |
| 63 | +.. Examine the output and confirm that the displayed SCC matches the SCC that you defined in the deployment: |
| 64 | ++ |
| 65 | +.Example output |
| 66 | +[source,terminal] |
| 67 | +---- |
| 68 | +my-scc |
| 69 | +---- |
0 commit comments