diff --git a/packages/system/cozystack-basics/templates/clusterroles.yaml b/packages/system/cozystack-basics/templates/clusterroles.yaml index 1c7ecb688..49cc5b775 100644 --- a/packages/system/cozystack-basics/templates/clusterroles.yaml +++ b/packages/system/cozystack-basics/templates/clusterroles.yaml @@ -382,3 +382,27 @@ rules: - '*' verbs: - '*' +--- +# GPUClass is the hoster's catalog and is cluster-scoped, so tenant roles, +# bound per namespace, cannot grant its read. +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: cozy:gpuclasses:view +rules: +- apiGroups: ["cozystack.io"] + resources: ["gpuclasses"] + verbs: ["get", "list", "watch"] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: cozy:gpuclasses:view:authenticated +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: cozy:gpuclasses:view +subjects: +- apiGroup: rbac.authorization.k8s.io + kind: Group + name: system:authenticated diff --git a/packages/system/cozystack-basics/tests/clusterroles-gpuclass_test.yaml b/packages/system/cozystack-basics/tests/clusterroles-gpuclass_test.yaml new file mode 100644 index 000000000..ae3f072e1 --- /dev/null +++ b/packages/system/cozystack-basics/tests/clusterroles-gpuclass_test.yaml @@ -0,0 +1,47 @@ +suite: cozystack-basics GPUClass catalog read + +templates: + - templates/clusterroles.yaml + +release: + name: cozystack-basics + namespace: cozy-system + +# GPUClass is the hoster's catalog: every authenticated user reads it, from +# a portal or from kubectl, and nobody but the hoster writes it. It is +# cluster-scoped, so tenant roles, which are bound per namespace, could not +# grant it even if they named it. +tests: + - it: renders a read-only GPUClass role + documentSelector: + path: metadata.name + value: cozy:gpuclasses:view + asserts: + - isKind: + of: ClusterRole + - equal: + path: rules + value: + - apiGroups: ["cozystack.io"] + resources: ["gpuclasses"] + verbs: ["get", "list", "watch"] + + - it: binds the GPUClass role to every authenticated user + documentSelector: + path: metadata.name + value: cozy:gpuclasses:view:authenticated + asserts: + - isKind: + of: ClusterRoleBinding + - equal: + path: roleRef + value: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: cozy:gpuclasses:view + - equal: + path: subjects + value: + - apiGroup: rbac.authorization.k8s.io + kind: Group + name: system:authenticated