Skip to content

Commit de4a726

Browse files
authored
Merge pull request #71 from projectsyn/ocp4/allow-scc-nonroot-v2
Allow vcluster containers to run with arbitrary non-root UIDs on OpenShift
2 parents b17d6cf + 12504d6 commit de4a726

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

component/cluster.libsonnet

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,46 @@ local cluster = function(name, options)
136136
roleRef_: clusterRole,
137137
};
138138

139+
local sccRole = if isOpenshift then
140+
kube.Role('use-nonroot-v2') {
141+
metadata+: {
142+
namespace: options.namespace,
143+
},
144+
rules: [
145+
{
146+
apiGroups: [
147+
'security.openshift.io',
148+
],
149+
resourceNames: [
150+
'nonroot-v2',
151+
],
152+
resources: [
153+
'securitycontextconstraints',
154+
],
155+
verbs: [
156+
'use',
157+
],
158+
},
159+
],
160+
};
161+
local sccRoleBinding = if isOpenshift then
162+
kube.RoleBinding('default-use-nonroot-v2') {
163+
metadata+: {
164+
annotations+: {
165+
'vcluster.syn.tools/description': 'Allow vcluster to sync pods with arbitrary nonroot users by allowing the default ServiceAccount to use the nonroot-v2 scc',
166+
},
167+
namespace: options.namespace,
168+
},
169+
roleRef_: sccRole,
170+
subjects: [
171+
{
172+
kind: 'ServiceAccount',
173+
name: 'default',
174+
namespace: options.namespace,
175+
},
176+
],
177+
};
178+
139179
local service = kube.Service(name) {
140180
metadata+: {
141181
namespace: options.namespace,
@@ -413,6 +453,8 @@ local cluster = function(name, options)
413453
roleBinding,
414454
clusterRole,
415455
clusterRoleBinding,
456+
sccRole,
457+
sccRoleBinding,
416458
service,
417459
headlessService,
418460
statefulSet,

tests/golden/openshift/openshift/openshift/10_cluster.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,43 @@ subjects:
124124
name: vc-openshift
125125
namespace: syn-openshift
126126
---
127+
apiVersion: rbac.authorization.k8s.io/v1
128+
kind: Role
129+
metadata:
130+
annotations: {}
131+
labels:
132+
name: use-nonroot-v2
133+
name: use-nonroot-v2
134+
namespace: syn-openshift
135+
rules:
136+
- apiGroups:
137+
- security.openshift.io
138+
resourceNames:
139+
- nonroot-v2
140+
resources:
141+
- securitycontextconstraints
142+
verbs:
143+
- use
144+
---
145+
apiVersion: rbac.authorization.k8s.io/v1
146+
kind: RoleBinding
147+
metadata:
148+
annotations:
149+
vcluster.syn.tools/description: Allow vcluster to sync pods with arbitrary nonroot
150+
users by allowing the default ServiceAccount to use the nonroot-v2 scc
151+
labels:
152+
name: default-use-nonroot-v2
153+
name: default-use-nonroot-v2
154+
namespace: syn-openshift
155+
roleRef:
156+
apiGroup: rbac.authorization.k8s.io
157+
kind: Role
158+
name: use-nonroot-v2
159+
subjects:
160+
- kind: ServiceAccount
161+
name: default
162+
namespace: syn-openshift
163+
---
127164
apiVersion: v1
128165
kind: Service
129166
metadata:

0 commit comments

Comments
 (0)