Skip to content

Commit add2cd7

Browse files
committed
refactor(helm): scope service ingress RBAC to the release namespace
Every object the service ingress reconciler manages is created in the gateway's own namespace, so the route/httproute/ingress permissions move from the ClusterRole to a namespaced Role and RoleBinding owned by the chart. Service ingress no longer requires any cluster-scoped permissions and works in namespace-admin installs with rbac.clusterScoped.create disabled; the ClusterRole keeps its genuinely cluster-scoped rules. Signed-off-by: Jesse Jaggars <jjaggars@redhat.com>
1 parent 0f36bc4 commit add2cd7

6 files changed

Lines changed: 225 additions & 73 deletions

File tree

‎deploy/helm/openshell/templates/clusterrole.yaml‎

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@
1111
{{- if hasKey $managedSshIngress "enabled" -}}
1212
{{- $managedSshIngressEnabled = get $managedSshIngress "enabled" -}}
1313
{{- end -}}
14-
{{- $serviceIngressTOML := get $gatewayConfig "openshell.drivers.kubernetes.service_ingress" | default dict -}}
15-
{{- $serviceIngressEnabled := false -}}
16-
{{- if hasKey $serviceIngressTOML "enabled" -}}
17-
{{- $serviceIngressEnabled = get $serviceIngressTOML "enabled" -}}
18-
{{- else if hasKey .Values "serviceIngress" -}}
19-
{{- $serviceIngressEnabled = .Values.serviceIngress.enabled -}}
20-
{{- end -}}
2114
apiVersion: rbac.authorization.k8s.io/v1
2215
kind: ClusterRole
2316
metadata:
@@ -140,46 +133,4 @@ rules:
140133
- update
141134
{{- end }}
142135
{{- end }}
143-
{{- if $serviceIngressEnabled }}
144-
# Reconcile ingress objects for exposed sandbox services in the gateway's
145-
# namespace. The reconciled kind is selected by configuration; the rules
146-
# cover every supported kind.
147-
- apiGroups:
148-
- route.openshift.io
149-
resources:
150-
- routes
151-
verbs:
152-
- get
153-
- list
154-
- create
155-
- delete
156-
# Setting a custom spec.host on an OpenShift Route requires the
157-
# custom-host subresource in addition to routes themselves.
158-
- apiGroups:
159-
- route.openshift.io
160-
resources:
161-
- routes/custom-host
162-
verbs:
163-
- create
164-
- patch
165-
- update
166-
- apiGroups:
167-
- gateway.networking.k8s.io
168-
resources:
169-
- httproutes
170-
verbs:
171-
- get
172-
- list
173-
- create
174-
- delete
175-
- apiGroups:
176-
- networking.k8s.io
177-
resources:
178-
- ingresses
179-
verbs:
180-
- get
181-
- list
182-
- create
183-
- delete
184-
{{- end }}
185136
{{- end }}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{{- if include "openshell.rbacCreate" . }}
2+
{{- /* RBAC for service ingress reconciliation.
3+
All reconciled objects (OpenShift Routes, Gateway API HTTPRoutes, and
4+
networking.k8s.io Ingresses) are created in the gateway's own
5+
namespace, so a namespaced Role is sufficient — no cluster-scoped
6+
permissions are required for this feature. The rules cover every
7+
supported kind because the reconciled kind is selected by
8+
configuration. */ -}}
9+
{{- $gatewayConfig := .Values.gatewayConfig | default dict -}}
10+
{{- $serviceIngressTOML := get $gatewayConfig "openshell.drivers.kubernetes.service_ingress" | default dict -}}
11+
{{- $serviceIngressEnabled := false -}}
12+
{{- if hasKey $serviceIngressTOML "enabled" -}}
13+
{{- $serviceIngressEnabled = get $serviceIngressTOML "enabled" -}}
14+
{{- else if hasKey .Values "serviceIngress" -}}
15+
{{- $serviceIngressEnabled = .Values.serviceIngress.enabled -}}
16+
{{- end -}}
17+
{{- if $serviceIngressEnabled }}
18+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
19+
# SPDX-License-Identifier: Apache-2.0
20+
21+
apiVersion: rbac.authorization.k8s.io/v1
22+
kind: Role
23+
metadata:
24+
name: {{ include "openshell.fullname" . }}-service-ingress
25+
namespace: {{ .Release.Namespace }}
26+
labels:
27+
{{- include "openshell.labels" . | nindent 4 }}
28+
rules:
29+
- apiGroups:
30+
- route.openshift.io
31+
resources:
32+
- routes
33+
verbs:
34+
- get
35+
- list
36+
- create
37+
- delete
38+
# Setting a custom spec.host on an OpenShift Route requires the
39+
# custom-host subresource in addition to routes themselves.
40+
- apiGroups:
41+
- route.openshift.io
42+
resources:
43+
- routes/custom-host
44+
verbs:
45+
- create
46+
- patch
47+
- update
48+
- apiGroups:
49+
- gateway.networking.k8s.io
50+
resources:
51+
- httproutes
52+
verbs:
53+
- get
54+
- list
55+
- create
56+
- delete
57+
- apiGroups:
58+
- networking.k8s.io
59+
resources:
60+
- ingresses
61+
verbs:
62+
- get
63+
- list
64+
- create
65+
- delete
66+
---
67+
apiVersion: rbac.authorization.k8s.io/v1
68+
kind: RoleBinding
69+
metadata:
70+
name: {{ include "openshell.fullname" . }}-service-ingress
71+
namespace: {{ .Release.Namespace }}
72+
labels:
73+
{{- include "openshell.labels" . | nindent 4 }}
74+
roleRef:
75+
apiGroup: rbac.authorization.k8s.io
76+
kind: Role
77+
name: {{ include "openshell.fullname" . }}-service-ingress
78+
subjects:
79+
- kind: ServiceAccount
80+
name: {{ include "openshell.serviceAccountName" . }}
81+
namespace: {{ .Release.Namespace }}
82+
{{- end }}
83+
{{- end }}

‎deploy/helm/openshell/tests/clusterrole_test.yaml‎

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -222,26 +222,11 @@ tests:
222222
path: metadata.name
223223
value: openshell-node-reader-my-namespace
224224

225-
- it: omits service ingress rules unless reconciliation is enabled
226-
asserts:
227-
- notContains:
228-
path: rules
229-
content:
230-
apiGroups:
231-
- route.openshift.io
232-
resources:
233-
- routes
234-
verbs:
235-
- get
236-
- list
237-
- create
238-
- delete
239-
240-
- it: grants service ingress object access when reconciliation is enabled
225+
- it: never grants service ingress rules regardless of reconciliation
241226
set:
242227
serviceIngress.enabled: true
243228
asserts:
244-
- contains:
229+
- notContains:
245230
path: rules
246231
content:
247232
apiGroups:
@@ -253,7 +238,7 @@ tests:
253238
- list
254239
- create
255240
- delete
256-
- contains:
241+
- notContains:
257242
path: rules
258243
content:
259244
apiGroups:
@@ -265,7 +250,7 @@ tests:
265250
- list
266251
- create
267252
- delete
268-
- contains:
253+
- notContains:
269254
path: rules
270255
content:
271256
apiGroups:
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
suite: Service ingress RBAC
5+
templates:
6+
- templates/service-ingress-rbac.yaml
7+
release:
8+
name: openshell
9+
namespace: my-namespace
10+
11+
tests:
12+
- it: renders no documents unless reconciliation is enabled
13+
asserts:
14+
- hasDocuments:
15+
count: 0
16+
17+
- it: grants service ingress object access when reconciliation is enabled
18+
set:
19+
serviceIngress.enabled: true
20+
asserts:
21+
- hasDocuments:
22+
count: 2
23+
- equal:
24+
path: metadata.name
25+
value: openshell-service-ingress
26+
documentIndex: 0
27+
- equal:
28+
path: metadata.namespace
29+
value: my-namespace
30+
documentIndex: 0
31+
- contains:
32+
path: rules
33+
content:
34+
apiGroups:
35+
- route.openshift.io
36+
resources:
37+
- routes
38+
verbs:
39+
- get
40+
- list
41+
- create
42+
- delete
43+
documentIndex: 0
44+
- contains:
45+
path: rules
46+
content:
47+
apiGroups:
48+
- route.openshift.io
49+
resources:
50+
- routes/custom-host
51+
verbs:
52+
- create
53+
- patch
54+
- update
55+
documentIndex: 0
56+
- contains:
57+
path: rules
58+
content:
59+
apiGroups:
60+
- gateway.networking.k8s.io
61+
resources:
62+
- httproutes
63+
verbs:
64+
- get
65+
- list
66+
- create
67+
- delete
68+
documentIndex: 0
69+
- contains:
70+
path: rules
71+
content:
72+
apiGroups:
73+
- networking.k8s.io
74+
resources:
75+
- ingresses
76+
verbs:
77+
- get
78+
- list
79+
- create
80+
- delete
81+
documentIndex: 0
82+
83+
- it: binds the role to the gateway service account in the release namespace
84+
set:
85+
serviceIngress.enabled: true
86+
asserts:
87+
- equal:
88+
path: kind
89+
value: RoleBinding
90+
documentIndex: 1
91+
- equal:
92+
path: metadata.namespace
93+
value: my-namespace
94+
documentIndex: 1
95+
- equal:
96+
path: roleRef.kind
97+
value: Role
98+
documentIndex: 1
99+
- equal:
100+
path: roleRef.name
101+
value: openshell-service-ingress
102+
documentIndex: 1
103+
- equal:
104+
path: subjects[0].kind
105+
value: ServiceAccount
106+
documentIndex: 1
107+
- equal:
108+
path: subjects[0].namespace
109+
value: my-namespace
110+
documentIndex: 1
111+
112+
- it: honors raw TOML gateway config enablement
113+
set:
114+
gatewayConfig:
115+
openshell.drivers.kubernetes.service_ingress:
116+
enabled: true
117+
asserts:
118+
- hasDocuments:
119+
count: 2
120+
121+
- it: renders no documents when chart RBAC ownership is disabled
122+
set:
123+
serviceIngress.enabled: true
124+
rbac:
125+
create: false
126+
asserts:
127+
- hasDocuments:
128+
count: 0

‎docs/how-it-works/gateways/configuration.mdx‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,9 @@ The Kubernetes compute driver can reconcile the exact-host ingress objects
393393
that hashed hostnames need. Enable
394394
`[openshell.drivers.kubernetes.service_ingress]` with `enabled = true` and
395395
choose the object `kind` — `route` (an `OpenShift` Route with TLS
396-
passthrough), `httproute` (a Gateway API HTTPRoute attached to a parent
397-
Gateway), or `ingress` (a `networking.k8s.io` Ingress; the gateway terminates
396+
passthrough), `http_route` (a Gateway API HTTPRoute attached to a parent
397+
Gateway; the Helm chart's `httproute` spelling is accepted as an alias), or
398+
`ingress` (a `networking.k8s.io` Ingress; the gateway terminates
398399
service TLS itself, so the controller must support SSL passthrough — the
399400
nginx passthrough annotation is set automatically).
400401

@@ -405,8 +406,10 @@ gateway Service named by `target_service_name` in
405406
`target_service_namespace` on `target_service_port`. Objects carry the
406407
`openshell.ai/managed-by: openshell` and `openshell.ai/service-ingress: true`
407408
labels plus the `openshell.ai/service-hostname` annotation; objects whose
408-
hostname is no longer exposed are deleted. The gateway ServiceAccount needs
409-
create, get, list, and delete permission on the reconciled kind.
409+
hostname is no longer exposed are deleted, and so are objects of other kinds
410+
left behind by a previous `kind` configuration. The gateway ServiceAccount
411+
needs create, get, list, and delete permission on every supported kind in
412+
the gateway's namespace.
410413

411414
The Helm chart exposes this as `serviceIngress.enabled`, wiring the release's
412415
own Service, namespace, and port automatically. Because every replica of a

‎docs/kubernetes/ingress.mdx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,9 @@ The reconciler polls the gateway's exposed services and ensures one ingress
320320
object per hostname, targeting the gateway's own Service. `serviceIngress.kind`
321321
selects the object kind — `route` (`OpenShift` Route with TLS passthrough),
322322
`httproute` (Gateway API HTTPRoute), or `ingress` (requires an SSL-passthrough
323-
capable controller). The chart grants the matching RBAC automatically.
323+
capable controller). The chart grants the matching RBAC automatically through
324+
a Role in the release namespace; no cluster-scoped permissions are required.
325+
Changing `kind` cleans up objects left by the previous kind.
324326

325327
Alternatively, run your own automation that reads `openshell service list` or
326328
the gateway API and reconciles exact-host routes per gateway. Without either,

0 commit comments

Comments
 (0)