Skip to content

Commit 711fcc1

Browse files
committed
fix(apps): let the cleanup hooks watch the objects they delete
kubectl delete waits for the object to disappear unless told otherwise, and that wait is a watch. The post-delete hook Roles of harbor, clickhouse, mariadb and qdrant granted get, list and delete only, so every uninstall logged a forbidden watch, the wait was skipped and the hook reported success before the PVCs were actually gone. The rules now carry watch for every resource the hooks delete, including the named Secrets the mariadb hook removes. Signed-off-by: Yan Bondarenko <[email protected]>
1 parent cd675e1 commit 711fcc1

8 files changed

Lines changed: 21 additions & 20 deletions

File tree

‎packages/apps/clickhouse/templates/hooks/cleanup-pvc.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ metadata:
8787
rules:
8888
- apiGroups: [""]
8989
resources: ["persistentvolumeclaims"]
90-
verbs: ["get", "list", "delete"]
90+
verbs: ["get", "list", "watch", "delete"]
9191
---
9292
apiVersion: rbac.authorization.k8s.io/v1
9393
kind: RoleBinding

‎packages/apps/clickhouse/tests/cleanup_pvc_test.yaml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ tests:
4545
path: spec.template.spec.containers[0].command[2]
4646
pattern: 'exit 1'
4747

48-
- it: "grants only get/list/delete on persistentvolumeclaims"
48+
- it: "grants get/list/watch/delete on persistentvolumeclaims"
4949
documentSelector:
5050
path: kind
5151
value: Role
@@ -66,6 +66,7 @@ tests:
6666
value:
6767
- get
6868
- list
69+
- watch
6970
- delete
7071

7172
- it: "binds the cleanup ServiceAccount to the cleanup Role"

‎packages/apps/harbor/templates/hooks/cleanup.yaml‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,21 +201,21 @@ metadata:
201201
rules:
202202
- apiGroups: [""]
203203
resources: ["persistentvolumeclaims"]
204-
verbs: ["get", "list", "delete"]
204+
verbs: ["get", "list", "watch", "delete"]
205205
- apiGroups: ["cert-manager.io"]
206206
resources: ["certificates"]
207-
verbs: ["get", "list", "delete"]
207+
verbs: ["get", "list", "watch", "delete"]
208208
# Only Challenges are touched directly (the host-scoped sweep lists and
209209
# deletes them); Orders are cascade-deleted by cert-manager itself when the
210210
# Certificate is removed, so the hook needs no RBAC for them.
211211
- apiGroups: ["acme.cert-manager.io"]
212212
resources: ["challenges"]
213-
verbs: ["get", "list", "delete"]
213+
verbs: ["get", "list", "watch", "delete"]
214214
# We list ACME http01 solver Ingresses (filtered by this release's host)
215215
# and delete the orphaned ones by name.
216216
- apiGroups: ["networking.k8s.io"]
217217
resources: ["ingresses"]
218-
verbs: ["get", "list", "delete"]
218+
verbs: ["get", "list", "watch", "delete"]
219219
---
220220
apiVersion: rbac.authorization.k8s.io/v1
221221
kind: RoleBinding

‎packages/apps/harbor/tests/cleanup_hook_test.yaml‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,13 @@ tests:
211211
content:
212212
apiGroups: [""]
213213
resources: ["persistentvolumeclaims"]
214-
verbs: ["get", "list", "delete"]
214+
verbs: ["get", "list", "watch", "delete"]
215215
- contains:
216216
path: rules
217217
content:
218218
apiGroups: ["cert-manager.io"]
219219
resources: ["certificates"]
220-
verbs: ["get", "list", "delete"]
220+
verbs: ["get", "list", "watch", "delete"]
221221
# Only "challenges" are granted: the host-scoped sweep lists/deletes
222222
# them, while Orders are cascade-deleted by cert-manager itself when the
223223
# Certificate is removed, so the hook needs no RBAC for orders.
@@ -226,35 +226,35 @@ tests:
226226
content:
227227
apiGroups: ["acme.cert-manager.io"]
228228
resources: ["challenges"]
229-
verbs: ["get", "list", "delete"]
229+
verbs: ["get", "list", "watch", "delete"]
230230
- notContains:
231231
path: rules
232232
content:
233233
apiGroups: ["acme.cert-manager.io"]
234234
resources: ["orders", "challenges"]
235-
verbs: ["get", "list", "delete"]
235+
verbs: ["get", "list", "watch", "delete"]
236236
# We list+delete orphaned http01 solver Ingresses by name, so we need
237237
# get/list/delete on networking.k8s.io ingresses.
238238
- contains:
239239
path: rules
240240
content:
241241
apiGroups: ["networking.k8s.io"]
242242
resources: ["ingresses"]
243-
verbs: ["get", "list", "delete"]
243+
verbs: ["get", "list", "watch", "delete"]
244244
# The hook must not grant services/pods: solver Pods/Services cascade
245245
# from the Challenge/Certificate and are never deleted directly.
246246
- notContains:
247247
path: rules
248248
content:
249249
apiGroups: [""]
250250
resources: ["services"]
251-
verbs: ["get", "list", "delete"]
251+
verbs: ["get", "list", "watch", "delete"]
252252
- notContains:
253253
path: rules
254254
content:
255255
apiGroups: [""]
256256
resources: ["pods"]
257-
verbs: ["get", "list", "delete"]
257+
verbs: ["get", "list", "watch", "delete"]
258258

259259
- it: binds the Role to the cleanup ServiceAccount
260260
documentSelector:

‎packages/apps/mariadb/templates/hooks/cleanup-pvc.yaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ rules:
113113
# PVCs are deleted by label selector, which requires list.
114114
- apiGroups: [""]
115115
resources: ["persistentvolumeclaims"]
116-
verbs: ["get", "list", "delete"]
116+
verbs: ["get", "list", "watch", "delete"]
117117
# The Secrets left behind are deleted by name — the first two generated by the
118118
# operator, the last two by cert-manager — so the rule is scoped to those four
119119
# rather than to namespace-wide secret access.
@@ -132,7 +132,7 @@ rules:
132132
- {{ .Release.Name }}-repl-password
133133
- {{ .Release.Name }}.ca-tls
134134
- {{ .Release.Name }}.tls
135-
verbs: ["get", "delete"]
135+
verbs: ["get", "watch", "delete"]
136136
---
137137
apiVersion: rbac.authorization.k8s.io/v1
138138
kind: RoleBinding

‎packages/apps/mariadb/tests/cleanup_hook_test.yaml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ tests:
5959
path: spec.template.spec.containers[0].command[2]
6060
pattern: 'exit "\$\{cleanup_failed\}"'
6161

62-
- it: "cleanup Role grants get/list/delete on persistentvolumeclaims"
62+
- it: "cleanup Role grants get/list/watch/delete on persistentvolumeclaims"
6363
documentSelector:
6464
path: kind
6565
value: Role
@@ -69,7 +69,7 @@ tests:
6969
content:
7070
apiGroups: [""]
7171
resources: ["persistentvolumeclaims"]
72-
verbs: ["get", "list", "delete"]
72+
verbs: ["get", "list", "watch", "delete"]
7373

7474
- it: "cleanup Role scopes secret access to the named secrets only (least privilege)"
7575
documentSelector:
@@ -86,7 +86,7 @@ tests:
8686
- mariadb-test-repl-password
8787
- mariadb-test.ca-tls
8888
- mariadb-test.tls
89-
verbs: ["get", "delete"]
89+
verbs: ["get", "watch", "delete"]
9090
# Lock the exact rule set (PVC rule + the single scoped secrets rule).
9191
# Without this, a broader unscoped `secrets` rule could be added and the
9292
# `contains` checks above would still pass.

‎packages/apps/qdrant/templates/hooks/cleanup-pvc.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ metadata:
147147
rules:
148148
- apiGroups: [""]
149149
resources: ["persistentvolumeclaims"]
150-
verbs: ["get", "list", "delete"]
150+
verbs: ["get", "list", "watch", "delete"]
151151
---
152152
apiVersion: rbac.authorization.k8s.io/v1
153153
kind: RoleBinding

‎packages/apps/qdrant/tests/cleanup_pvc_test.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,4 @@ tests:
8080
content:
8181
apiGroups: [""]
8282
resources: ["persistentvolumeclaims"]
83-
verbs: ["get", "list", "delete"]
83+
verbs: ["get", "list", "watch", "delete"]

0 commit comments

Comments
 (0)