Skip to content

Commit

Permalink
Allow vcluster containers to run with arbitrary non-root UIDs on Open…
Browse files Browse the repository at this point in the history
…Shift
  • Loading branch information
simu committed Nov 21, 2023
1 parent b17d6cf commit 5b286a7
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
38 changes: 38 additions & 0 deletions component/cluster.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,42 @@ local cluster = function(name, options)
roleRef_: clusterRole,
};

local sccRole = if isOpenshift then
kube.Role('use-nonroot-v2') {
rules: [
{
apiGroups: [
'security.openshift.io',
],
resourceNames: [
'nonroot-v2',
],
resources: [
'securitycontextconstraints',
],
verbs: [
'use',
],
},
],
};
local sccRoleBinding = if isOpenshift then
kube.RoleBinding('default-use-nonroot-v2') {
metadata+: {
annotations+: {
'vcluster.syn.tools/description': 'Allow vcluster to sync pods with arbitrary nonroot users by allowing the default ServiceAccount to use the nonroot-v2 scc',
},
},
roleRef_: sccRole,
subjects: [
{
kind: 'ServiceAccount',
name: 'default',
namespace: options.namespace,
},
],
};

local service = kube.Service(name) {
metadata+: {
namespace: options.namespace,
Expand Down Expand Up @@ -413,6 +449,8 @@ local cluster = function(name, options)
roleBinding,
clusterRole,
clusterRoleBinding,
sccRole,
sccRoleBinding,
service,
headlessService,
statefulSet,
Expand Down
35 changes: 35 additions & 0 deletions tests/golden/openshift/openshift/openshift/10_cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,41 @@ subjects:
name: vc-openshift
namespace: syn-openshift
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
annotations: {}
labels:
name: use-nonroot-v2
name: use-nonroot-v2
rules:
- apiGroups:
- security.openshift.io
resourceNames:
- nonroot-v2
resources:
- securitycontextconstraints
verbs:
- use
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
annotations:
vcluster.syn.tools/description: Allow vcluster to sync pods with arbitrary nonroot
users by allowing the default ServiceAccount to use the nonroot-v2 scc
labels:
name: default-use-nonroot-v2
name: default-use-nonroot-v2
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: use-nonroot-v2
subjects:
- kind: ServiceAccount
name: default
namespace: syn-openshift
---
apiVersion: v1
kind: Service
metadata:
Expand Down

0 comments on commit 5b286a7

Please sign in to comment.