@@ -13,12 +13,12 @@ live `linstor` exec on every Flux HelmRelease reconcile. Being a pre-upgrade
1313(not pre-install) hook, it also never runs on a fresh install, where there is
1414no prior state to protect and no LINSTOR to query.
1515
16- Unlike the migration hook this binds a ClusterRole limited to the verbs the
17- checks need ( read nodes/pods/deployments, create pods/exec) rather than
18- cluster-admin : a read-only health probe has no reason to hold write access to
19- the whole cluster. Note that pods/exec cannot be narrowed to a single pod in
20- RBAC ( pod names are generated), so the exec grant is necessarily cluster-wide;
21- it is used only to exec into the linstor-controller .
16+ Unlike the migration hook (cluster-admin) this splits its access by least
17+ privilege : a ClusterRole with only read verbs ( nodes/pods/deployments
18+ get+list), plus a namespaced Role in cozy-linstor for the single privileged
19+ verb pods/exec (running `linstor` in the controller). exec cannot be narrowed
20+ to one pod name, but scoping it to the one namespace the check targets keeps
21+ the blast radius contained; that Role renders only when cozy-linstor exists .
2222*/ -}}
2323{{- $pf := .Values.preflight | default dict }}
2424{{- if dig "enabled" true $pf }}
@@ -94,18 +94,18 @@ metadata:
9494 helm.sh/hook-weight : " 0"
9595 helm.sh/hook-delete-policy : hook-succeeded,before-hook-creation
9696rules :
97+ # Read-only, and deliberately cluster-wide. nodes are cluster-scoped anyway;
98+ # pods/deployments get+list stay here (not in the LINSTOR Role below) so the
99+ # LINSTOR check can always probe `get deploy -n cozy-linstor` and get a clean
100+ # NotFound -> N/A on a cluster that has no LINSTOR, without depending on the
101+ # cozy-linstor namespace existing. The only privileged verb (pods/exec) is
102+ # NOT here; it is scoped to the LINSTOR namespace below.
97103 - apiGroups : [""]
98104 resources : ["nodes"]
99105 verbs : ["get", "list"]
100106 - apiGroups : [""]
101107 resources : ["pods"]
102108 verbs : ["get", "list"]
103- # Needed to run `linstor` inside the live controller pod. RBAC cannot scope
104- # exec to a single pod (pod names are generated), so this is cluster-wide
105- # create on pods/exec; the checks only ever exec into linstor-controller.
106- - apiGroups : [""]
107- resources : ["pods/exec"]
108- verbs : ["create"]
109109 - apiGroups : ["apps"]
110110 resources : ["deployments"]
111111 verbs : ["get", "list"]
@@ -126,6 +126,47 @@ subjects:
126126 - kind : ServiceAccount
127127 name : cozystack-preflight-hook
128128 namespace : {{ .Release.Namespace | quote }}
129+ {{- if lookup "v1" "Namespace" "" "cozy-linstor" }}
130+ ---
131+ # pods/exec (running `linstor` inside the controller) is the one privileged
132+ # grant, so it is a namespaced Role in cozy-linstor rather than cluster-wide:
133+ # exec cannot be scoped to a single pod name, but limiting it to the one
134+ # namespace the check ever targets keeps the blast radius contained. Rendered
135+ # only when the cozy-linstor namespace exists, so a cluster without LINSTOR
136+ # neither gets this grant nor fails applying a Role into a missing namespace
137+ # (there the check N/A-skips after the NotFound probe above).
138+ apiVersion : rbac.authorization.k8s.io/v1
139+ kind : Role
140+ metadata :
141+ name : cozystack-preflight-hook
142+ namespace : cozy-linstor
143+ annotations :
144+ helm.sh/hook : pre-upgrade
145+ helm.sh/hook-weight : " 0"
146+ helm.sh/hook-delete-policy : hook-succeeded,before-hook-creation
147+ rules :
148+ - apiGroups : [""]
149+ resources : ["pods/exec"]
150+ verbs : ["create"]
151+ ---
152+ apiVersion : rbac.authorization.k8s.io/v1
153+ kind : RoleBinding
154+ metadata :
155+ name : cozystack-preflight-hook
156+ namespace : cozy-linstor
157+ annotations :
158+ helm.sh/hook : pre-upgrade
159+ helm.sh/hook-weight : " 0"
160+ helm.sh/hook-delete-policy : hook-succeeded,before-hook-creation
161+ roleRef :
162+ apiGroup : rbac.authorization.k8s.io
163+ kind : Role
164+ name : cozystack-preflight-hook
165+ subjects :
166+ - kind : ServiceAccount
167+ name : cozystack-preflight-hook
168+ namespace : {{ .Release.Namespace | quote }}
169+ {{- end }}
129170---
130171apiVersion : v1
131172kind : ServiceAccount
0 commit comments