Skip to content

Commit 2874222

Browse files
authored
chore: Describe RBAC rules, remove unnecessary rules (#820)
* chore: Describe RBAC rules, remove unnecessary rules * chore: Add missing rule comments * chore: Update changelog * chore: Remove the get for customresourcedefinitions for the operator clusterrole Not needed for CRD maintenance nor startup condition * chore: Remove nodes list/watch Not needed for clusterDomain detection * chore: Remove the configmaps/secrets/serviceaccounts rule for the product clusterrole OPA doesn't interact with the Kubernetes API * fix: Always allow customresourcedefinitions list/watch Required for startup condition regardless of CRD maintenance * chore: Simplify the rule comments * chore: Remove the events.k8s.io rule from the product ClusterRole Neither OPA nor UIF interact with the Kubernetes API * chore: Keep the rbac.authorization.k8s.io rules within a ClusterRole close to each other * chore: Split the roles.yaml into separate files for clusterrole-operator.yaml and clusterrole-product.yaml Also rename the opa-builder clusterrole file to be consistent * chore: Update changelog * chore: Restore rules after discovering that the bundle-builder clusterrole is not used * chore: Preserve comment on part of rule * chore: Add description to operator clusterrole
1 parent 9e0a0f5 commit 2874222

5 files changed

Lines changed: 101 additions & 98 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ All notable changes to this project will be documented in this file.
88

99
- Set `maxSurge=1` and `maxUnavailable=0` on the OPA DaemonSet rolling update strategy to eliminate
1010
availability gaps during rolling updates ([#819]).
11+
- Document Helm deployed RBAC permissions and remove unnecessary permissions ([#820]).
1112

1213
[#819]: https://github.com/stackabletech/opa-operator/pull/819
14+
[#820]: https://github.com/stackabletech/opa-operator/pull/820
1315

1416
## [26.3.0] - 2026-03-16
1517

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
# This ClusterRole is for the OPA bundle builder sidecar, which reads
3+
# Rego rules from ConfigMaps and compiles them into bundles for OPA.
4+
#
5+
# NOTE: This ClusterRole is currently not bound to any ServiceAccount. The
6+
# bundle-builder sidecar relies on the product ClusterRole for ConfigMap access
7+
# instead. The operator should be updated to bind this ClusterRole to the
8+
# product ServiceAccount via a separate RoleBinding.
9+
apiVersion: rbac.authorization.k8s.io/v1
10+
kind: ClusterRole
11+
metadata:
12+
name: {{ .Release.Name }}-opa-bundle-builder-clusterrole
13+
rules:
14+
# Read and watch ConfigMaps containing Rego rules used to build bundles
15+
- apiGroups:
16+
- ""
17+
resources:
18+
- configmaps
19+
verbs:
20+
- get
21+
- watch
22+
- list
23+
{{ if .Capabilities.APIVersions.Has "security.openshift.io/v1" }}
24+
# Allow the bundle builder pods to use the opa-scc SCC on OpenShift
25+
- apiGroups:
26+
- security.openshift.io
27+
resources:
28+
- securitycontextconstraints
29+
resourceNames:
30+
- opa-scc
31+
verbs:
32+
- use
33+
{{ end }}
Lines changed: 34 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,155 +1,118 @@
11
---
2+
# Operator ClusterRole: bound (via ClusterRoleBinding) to the operator's own ServiceAccount.
3+
# Grants permissions needed by the controller to reconcile OpaCluster resources.
24
apiVersion: rbac.authorization.k8s.io/v1
35
kind: ClusterRole
46
metadata:
57
name: {{ include "operator.fullname" . }}-clusterrole
68
labels:
79
{{- include "operator.labels" . | nindent 4 }}
810
rules:
9-
- apiGroups:
10-
- ""
11-
resources:
12-
- nodes
13-
verbs:
14-
- list
15-
- watch
1611
# For automatic cluster domain detection
1712
- apiGroups:
1813
- ""
1914
resources:
2015
- nodes/proxy
2116
verbs:
2217
- get
18+
# Manage core workload resources created per OpaCluster.
19+
# All resources are applied via Server-Side Apply (create + patch) and tracked for
20+
# orphan cleanup (list + delete).
2321
- apiGroups:
2422
- ""
2523
resources:
26-
- pods
2724
- configmaps
28-
- secrets
2925
- services
30-
- endpoints
31-
- serviceaccounts
3226
verbs:
3327
- create
3428
- delete
3529
- get
3630
- list
3731
- patch
38-
- update
3932
- watch
33+
# ServiceAccount created per OpaCluster for workload pod identity.
34+
# Applied via SSA and tracked for orphan cleanup.
4035
- apiGroups:
41-
- rbac.authorization.k8s.io
36+
- ""
4237
resources:
43-
- rolebindings
38+
- serviceaccounts
4439
verbs:
4540
- create
4641
- delete
4742
- get
4843
- list
4944
- patch
50-
- update
51-
- watch
45+
# RoleBinding created per OpaCluster to bind the product ClusterRole to the workload
46+
# ServiceAccount. Applied via SSA and tracked for orphan cleanup.
5247
- apiGroups:
53-
- apps
48+
- rbac.authorization.k8s.io
5449
resources:
55-
- daemonsets
50+
- rolebindings
5651
verbs:
57-
- get
5852
- create
5953
- delete
54+
- get
6055
- list
6156
- patch
62-
- update
63-
- watch
57+
# Required to bind the product ClusterRole to the per-cluster ServiceAccount.
6458
- apiGroups:
65-
- batch
59+
- rbac.authorization.k8s.io
6660
resources:
67-
- jobs
61+
- clusterroles
62+
verbs:
63+
- bind
64+
resourceNames:
65+
- {{ include "operator.name" . }}-clusterrole
66+
# DaemonSet created per role group. Applied via SSA, tracked for orphan cleanup, and
67+
# owned by the controller.
68+
- apiGroups:
69+
- apps
70+
resources:
71+
- daemonsets
6872
verbs:
6973
- create
74+
- delete
7075
- get
7176
- list
7277
- patch
73-
- update
7478
- watch
79+
# Required for maintaining the CRDs within the operator (including the conversion webhook info).
80+
# Also for the startup condition check before the controller can run.
7581
- apiGroups:
7682
- apiextensions.k8s.io
7783
resources:
7884
- customresourcedefinitions
7985
verbs:
80-
- get
8186
# Required to maintain the CRD. The operator needs to do this, as it needs to enter e.g. it's
8287
# generated certificate in the conversion webhook.
8388
{{- if .Values.maintenance.customResourceDefinitions.maintain }}
8489
- create
8590
- patch
91+
{{- end }}
8692
# Required for startup condition
8793
- list
8894
- watch
89-
{{- end }}
95+
# Required to report reconciliation results and warnings back to the OpaCluster object.
9096
- apiGroups:
9197
- events.k8s.io
9298
resources:
9399
- events
94100
verbs:
95101
- create
96102
- patch
103+
# Primary CRD: watched by the controller and read during reconciliation.
97104
- apiGroups:
98105
- {{ include "operator.name" . }}.stackable.tech
99106
resources:
100107
- {{ include "operator.name" . }}clusters
101108
verbs:
102109
- get
103110
- list
104-
- patch
105111
- watch
112+
# Status subresource: updated at the end of every reconciliation.
106113
- apiGroups:
107114
- {{ include "operator.name" . }}.stackable.tech
108115
resources:
109116
- {{ include "operator.name" . }}clusters/status
110117
verbs:
111118
- patch
112-
- apiGroups:
113-
- rbac.authorization.k8s.io
114-
resources:
115-
- clusterroles
116-
verbs:
117-
- bind
118-
resourceNames:
119-
- {{ include "operator.name" . }}-clusterrole
120-
121-
---
122-
apiVersion: rbac.authorization.k8s.io/v1
123-
kind: ClusterRole
124-
metadata:
125-
name: {{ include "operator.name" . }}-clusterrole
126-
labels:
127-
{{- include "operator.labels" . | nindent 4 }}
128-
rules:
129-
- apiGroups:
130-
- ""
131-
resources:
132-
- configmaps
133-
- secrets
134-
- serviceaccounts
135-
verbs:
136-
- get
137-
- list
138-
- watch
139-
- apiGroups:
140-
- events.k8s.io
141-
resources:
142-
- events
143-
verbs:
144-
- create
145-
- patch
146-
{{ if .Capabilities.APIVersions.Has "security.openshift.io/v1" }}
147-
- apiGroups:
148-
- security.openshift.io
149-
resources:
150-
- securitycontextconstraints
151-
resourceNames:
152-
- nonroot-v2
153-
verbs:
154-
- use
155-
{{ end }}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
# Product ClusterRole: bound (via per OpaCluster RoleBinding) to the ServiceAccount that OPA
3+
# workload pods run as.
4+
apiVersion: rbac.authorization.k8s.io/v1
5+
kind: ClusterRole
6+
metadata:
7+
name: {{ include "operator.name" . }}-clusterrole
8+
labels:
9+
{{- include "operator.labels" . | nindent 4 }}
10+
rules:
11+
# The bundle-builder sidecar lists and watches ConfigMaps labeled opa.stackable.tech/bundle
12+
# to compile Rego rules into bundles. It shares this ServiceAccount because the bundle-builder
13+
# ClusterRole (clusterrole-opa-builder.yaml) is not yet bound to the product ServiceAccount.
14+
# TODO: Wire up the bundle-builder ClusterRole binding in the operator and remove this rule.
15+
- apiGroups:
16+
- ""
17+
resources:
18+
- configmaps
19+
verbs:
20+
- list
21+
- watch
22+
{{ if .Capabilities.APIVersions.Has "security.openshift.io/v1" }}
23+
# Required on OpenShift to allow the OPA pods to run as a non-root user.
24+
- apiGroups:
25+
- security.openshift.io
26+
resources:
27+
- securitycontextconstraints
28+
resourceNames:
29+
- nonroot-v2
30+
verbs:
31+
- use
32+
{{ end }}

deploy/helm/opa-operator/templates/roles-opa-builder.yaml

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)