Skip to content

Commit 57378e9

Browse files
authored
Merge pull request #3011 from rahulait/fix-computedomain-openshift-permissions
fix computedomain daemon permissions in openshift
2 parents cc6fd60 + 842ec60 commit 57378e9

8 files changed

Lines changed: 104 additions & 0 deletions

File tree

‎bundle/manifests/gpu-operator-certified.clusterserviceversion.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,7 @@ spec:
894894
- create
895895
- update
896896
- patch
897+
- delete
897898
- apiGroups:
898899
- coordination.k8s.io
899900
resources:

‎config/rbac/role.yaml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,14 @@ rules:
233233
- patch
234234
- update
235235
- watch
236+
- apiGroups:
237+
- security.openshift.io
238+
resourceNames:
239+
- anyuid
240+
resources:
241+
- securitycontextconstraints
242+
verbs:
243+
- use
236244
- apiGroups:
237245
- security.openshift.io
238246
resourceNames:

‎controllers/gpucluster_controller.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ type GPUClusterReconciler struct {
7575
//+kubebuilder:rbac:groups="",resources=namespaces,verbs=get;update;patch
7676
//+kubebuilder:rbac:groups=events.k8s.io,resources=events,verbs=create;patch
7777
//+kubebuilder:rbac:groups=resource.k8s.io,resources=resourceclaimtemplates,verbs=get;list;watch;create;update;delete
78+
//+kubebuilder:rbac:groups=security.openshift.io,resources=securitycontextconstraints,verbs=use,resourceNames=anyuid
7879

7980
func (r *GPUClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
8081
logger := log.FromContext(ctx)

‎deployments/gpu-operator/templates/clusterrole.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ rules:
190190
- create
191191
- update
192192
- patch
193+
- delete
193194
- apiGroups:
194195
- coordination.k8s.io
195196
resources:

‎internal/state/dra_driver_test.go‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/stretchr/testify/require"
2626
appsv1 "k8s.io/api/apps/v1"
2727
corev1 "k8s.io/api/core/v1"
28+
rbacv1 "k8s.io/api/rbac/v1"
2829
"k8s.io/apimachinery/pkg/api/resource"
2930
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3031
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -474,6 +475,28 @@ func TestDRADriverComputeDomainsContainerAndController(t *testing.T) {
474475
assert.Equal(t, "test-operator", depEnv["LEADER_ELECTION_LEASE_LOCK_NAMESPACE"])
475476
}
476477

478+
func TestComputeDomainDaemonCliquePermissions(t *testing.T) {
479+
s := newTestDRAState(t)
480+
cr := sampleGPUCluster()
481+
cr.Spec.DRADriver.ComputeDomains.Enabled = new(true)
482+
objs, err := s.getManifestObjects(context.Background(), cr, draSupportedCatalog())
483+
require.NoError(t, err)
484+
for _, obj := range objs {
485+
if obj.GetKind() != "ClusterRole" || obj.GetName() != "compute-domain-daemon" {
486+
continue
487+
}
488+
role := &rbacv1.ClusterRole{}
489+
require.NoError(t, runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, role))
490+
require.Contains(t, role.Rules, rbacv1.PolicyRule{
491+
APIGroups: []string{"resource.nvidia.com"},
492+
Resources: []string{"computedomaincliques"},
493+
Verbs: []string{"get", "list", "watch", "create", "update", "patch", "delete"},
494+
}, "owner-reference admission requires delete permission on the dependent clique")
495+
return
496+
}
497+
t.Fatal("compute-domain-daemon ClusterRole not found")
498+
}
499+
477500
func TestDRADriverDaemonsetsLabels(t *testing.T) {
478501
s := newTestDRAState(t)
479502
cr := sampleGPUCluster()

‎internal/state/gpucluster_scc_test.go‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,59 @@ func TestDRADriverSCCAllowsMPSHostPID(t *testing.T) {
9191
require.True(t, allowHostPID, "MPS control daemon pods require hostPID")
9292
}
9393

94+
func TestComputeDomainDaemonAnyUIDBinding(t *testing.T) {
95+
for _, tc := range []struct {
96+
name string
97+
openshift bool
98+
computeDomains bool
99+
}{
100+
{name: "openshift-enabled", openshift: true, computeDomains: true},
101+
{name: "openshift-disabled", openshift: true},
102+
{name: "kubernetes-enabled", computeDomains: true},
103+
{name: "kubernetes-disabled"},
104+
} {
105+
t.Run(tc.name, func(t *testing.T) {
106+
s := newTestDRAState(t)
107+
cr := sampleGPUCluster()
108+
cr.Spec.DRADriver.ComputeDomains.Enabled = new(tc.computeDomains)
109+
catalog := draSupportedCatalog()
110+
if tc.openshift {
111+
catalog = draSupportedOpenshiftCatalog()
112+
}
113+
objs, err := s.getManifestObjects(context.Background(), cr, catalog)
114+
require.NoError(t, err)
115+
var binding *unstructured.Unstructured
116+
for _, obj := range objs {
117+
if obj.GetKind() == "ClusterRoleBinding" && obj.GetName() == "compute-domain-daemon-openshift-anyuid-role-binding" {
118+
binding = obj
119+
}
120+
}
121+
if tc.openshift && tc.computeDomains {
122+
require.NotNil(t, binding)
123+
require.Equal(t, map[string]any{
124+
"apiGroup": "rbac.authorization.k8s.io",
125+
"kind": "ClusterRole",
126+
"name": "system:openshift:scc:anyuid",
127+
}, binding.Object["roleRef"])
128+
require.Equal(t, []any{map[string]any{
129+
"kind": "ServiceAccount",
130+
"name": "compute-domain-daemon-service-account",
131+
"namespace": "test-operator",
132+
}}, binding.Object["subjects"])
133+
} else {
134+
require.Nil(t, binding)
135+
}
136+
if tc.openshift {
137+
scc := findSCC(t, objs, "nvidia-dra-driver")
138+
require.NotNil(t, scc)
139+
require.Contains(t, sccUsers(t, scc), "system:serviceaccount:test-operator:compute-domain-daemon-service-account")
140+
require.Contains(t, scc.Object, "priority")
141+
require.Nil(t, scc.Object["priority"])
142+
}
143+
})
144+
}
145+
}
146+
94147
func TestGPUClusterOperandSCCs(t *testing.T) {
95148
testCases := []struct {
96149
name string

‎internal/state/testdata/golden/gpucluster-dra-driver-full-spec.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ rules:
164164
- create
165165
- update
166166
- patch
167+
- delete
167168
- apiGroups:
168169
- ""
169170
resources:

‎manifests/state-dra-driver/0120_compute-domain-daemon-rbac.yaml‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ rules:
3535
- create
3636
- update
3737
- patch
38+
- delete
3839
- apiGroups:
3940
- ""
4041
resources:
@@ -57,4 +58,19 @@ roleRef:
5758
kind: ClusterRole
5859
name: compute-domain-daemon
5960
apiGroup: rbac.authorization.k8s.io
61+
{{- if .OpenshiftVersion }}
62+
---
63+
apiVersion: rbac.authorization.k8s.io/v1
64+
kind: ClusterRoleBinding
65+
metadata:
66+
name: compute-domain-daemon-openshift-anyuid-role-binding
67+
subjects:
68+
- kind: ServiceAccount
69+
name: compute-domain-daemon-service-account
70+
namespace: {{ .Namespace }}
71+
roleRef:
72+
kind: ClusterRole
73+
name: system:openshift:scc:anyuid
74+
apiGroup: rbac.authorization.k8s.io
75+
{{- end }}
6076
{{- end }}

0 commit comments

Comments
 (0)