Using SCC anyuid in OKD-OpenShift » Historie » Zyklus 3
Peter Pfläging, 22.07.2021 06:27
| 1 | 3 | Peter Pfläging | # Let root containers run in a specific namespace (OKD / OpenShift) |
|---|---|---|---|
| 2 | |||
| 3 | It's not advised, but there are cases where you have to run Pods as root. There's a SecurityContextConstraint (SCC) in OpenShift handling this: |
||
| 4 | |||
| 5 | `oc get scc anyuid -o yaml` |
||
| 6 | |||
| 7 | ```yaml |
||
| 8 | kind: SecurityContextConstraints |
||
| 9 | apiVersion: security.openshift.io/v1 |
||
| 10 | metadata: |
||
| 11 | annotations: |
||
| 12 | include.release.openshift.io/ibm-cloud-managed: "true" |
||
| 13 | include.release.openshift.io/self-managed-high-availability: "true" |
||
| 14 | include.release.openshift.io/single-node-developer: "true" |
||
| 15 | kubernetes.io/description: anyuid provides all features of the restricted SCC but allows users to run with any UID and any GID. |
||
| 16 | release.openshift.io/create-only: "true" |
||
| 17 | name: anyuid |
||
| 18 | allowHostDirVolumePlugin: false |
||
| 19 | allowHostIPC: false |
||
| 20 | allowHostNetwork: false |
||
| 21 | allowHostPID: false |
||
| 22 | allowHostPorts: false |
||
| 23 | allowPrivilegeEscalation: true |
||
| 24 | allowPrivilegedContainer: false |
||
| 25 | allowedCapabilities: null |
||
| 26 | defaultAddCapabilities: null |
||
| 27 | fsGroup: |
||
| 28 | type: RunAsAny |
||
| 29 | groups: |
||
| 30 | - system:cluster-admins |
||
| 31 | priority: 10 |
||
| 32 | readOnlyRootFilesystem: false |
||
| 33 | requiredDropCapabilities: |
||
| 34 | - MKNOD |
||
| 35 | runAsUser: |
||
| 36 | type: RunAsAny |
||
| 37 | seLinuxContext: |
||
| 38 | type: MustRunAs |
||
| 39 | supplementalGroups: |
||
| 40 | type: RunAsAny |
||
| 41 | users: [] |
||
| 42 | volumes: |
||
| 43 | - configMap |
||
| 44 | - downwardAPI |
||
| 45 | - emptyDir |
||
| 46 | - persistentVolumeClaim |
||
| 47 | - projected |
||
| 48 | ``` |
||
| 49 | |||
| 50 | Reference: <https://docs.okd.io/latest/authentication/managing-security-context-constraints.html> |
||
| 51 | |||
| 52 | The best and practicable way is to create a special namespace for this *evil* pods and restrict the access to this namespaces as wide as you can. |
||
| 53 | |||
| 54 | ## Set this with commandline tools |
||
| 55 | |||
| 56 | OK, we make a namespace `evilone-notsecure` |
||
| 57 | |||
| 58 | `oc new-project evilone-notsecure --description="Evil Project for root Containers (need anyuid)" --display-name="Evil One (anyuid!)"` |
||
| 59 | |||
| 60 | Then we set the SCC for the default Systemaccount in this project: |
||
| 61 | |||
| 62 | `oc adm oc policy add-scc-to-user -z default -n evilone-notsecure anyuid` |
||
| 63 | |||
| 64 | |||
| 65 | 1 | Peter Pfläging | |
| 66 | ```yaml |
||
| 67 | apiVersion: rbac.authorization.k8s.io/v1 |
||
| 68 | kind: RoleBinding |
||
| 69 | metadata: |
||
| 70 | name: system:openshift:scc:anyuid |
||
| 71 | namespace: mysupercoolnamespace |
||
| 72 | roleRef: |
||
| 73 | apiGroup: rbac.authorization.k8s.io |
||
| 74 | kind: ClusterRole |
||
| 75 | name: system:openshift:scc:anyuid |
||
| 76 | subjects: |
||
| 77 | - kind: ServiceAccount |
||
| 78 | name: default |
||
| 79 | namespace: mysupercoolnamespace |
||
| 80 | 2 | Peter Pfläging | ``` |
| 81 | |||
| 82 | ```yaml |
||
| 83 | 1 | Peter Pfläging | kind: SecurityContextConstraints |
| 84 | apiVersion: security.openshift.io/v1 |
||
| 85 | metadata: |
||
| 86 | annotations: |
||
| 87 | include.release.openshift.io/ibm-cloud-managed: "true" |
||
| 88 | include.release.openshift.io/self-managed-high-availability: "true" |
||
| 89 | include.release.openshift.io/single-node-developer: "true" |
||
| 90 | kubernetes.io/description: anyuid provides all features of the restricted SCC but allows users to run with any UID and any GID. |
||
| 91 | release.openshift.io/create-only: "true" |
||
| 92 | name: anyuid |
||
| 93 | allowHostDirVolumePlugin: false |
||
| 94 | allowHostIPC: false |
||
| 95 | allowHostNetwork: false |
||
| 96 | allowHostPID: false |
||
| 97 | allowHostPorts: false |
||
| 98 | allowPrivilegeEscalation: true |
||
| 99 | allowPrivilegedContainer: false |
||
| 100 | allowedCapabilities: null |
||
| 101 | defaultAddCapabilities: null |
||
| 102 | fsGroup: |
||
| 103 | type: RunAsAny |
||
| 104 | groups: |
||
| 105 | - system:cluster-admins |
||
| 106 | priority: 10 |
||
| 107 | readOnlyRootFilesystem: false |
||
| 108 | requiredDropCapabilities: |
||
| 109 | - MKNOD |
||
| 110 | runAsUser: |
||
| 111 | type: RunAsAny |
||
| 112 | seLinuxContext: |
||
| 113 | type: MustRunAs |
||
| 114 | supplementalGroups: |
||
| 115 | type: RunAsAny |
||
| 116 | users: [] |
||
| 117 | volumes: |
||
| 118 | - configMap |
||
| 119 | - downwardAPI |
||
| 120 | - emptyDir |
||
| 121 | - persistentVolumeClaim |
||
| 122 | - projected |
||
| 123 | ``` |