Skip to content

Commit 9d1d680

Browse files
committed
test(seaweedfs,api): bound both Roles against a respelled rule
Each suite forbade a rule by naming it in full, and helm-unittest compares every field it is handed by value equality, so one respelling walks past. For seaweedfs that is not theoretical. Ungating the cnpg block and adding a verb to the rule (get,list,delete rather than get,delete) is the same grant and more, and the guard stayed green while a Client instance held delete on another app's Postgres cluster. Bound the Role by shape: a Client renders exactly two rules, both in the core group, and the cnpg grant is gated between them, so ungating it adds a third whatever its spelling. The rules themselves stay unpinned because the secret list is long and changes on its own schedule. For cozystack-api, add a count bound beside the existing spelling assert rather than in place of it. The two catch different things and neither covers the other: templates/rbac.yaml carries no template directives, so the list is pinned at exactly sixteen rules, while a grant swapped in for an existing one leaves the count where it was and only the named-rule assert sees it. The count is pinned from both sides — a dropped grant is the failure this suite is about, since the apiserver then returns forbidden and List silently drops the dropdown. Measured on all three: append, delete, and swap. Assisted-By: Claude <[email protected]> Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent a3c1408 commit 9d1d680

2 files changed

Lines changed: 41 additions & 15 deletions

File tree

‎packages/extra/seaweedfs/tests/cleanup_client_test.yaml‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,20 @@ tests:
3434
path: kind
3535
value: Role
3636
asserts:
37-
- notContains:
38-
path: rules
39-
content:
40-
apiGroups: ["postgresql.cnpg.io"]
41-
resources: ["clusters"]
42-
verbs: ["get", "delete"]
43-
resourceNames:
44-
- seaweedfs-db
37+
# Bound the Role by shape instead of naming one spelling of the forbidden
38+
# rule. A Client renders exactly two rules, both in the core group. The
39+
# cnpg grant is gated between them in the template, so ungating it adds a
40+
# third rule whatever its spelling — other verbs, a wildcard resource, a
41+
# different resourceNames list — and rules[2] exists. The rules themselves
42+
# are left unpinned because the secret list is long and churns on its own.
43+
- equal:
44+
path: rules[0].apiGroups
45+
value: [""]
46+
- equal:
47+
path: rules[1].apiGroups
48+
value: [""]
49+
- notExists:
50+
path: rules[2]
4551

4652
- it: does not delete any database in a Client instance's cleanup command
4753
set: *client

‎packages/system/cozystack-api/tests/rbac_test.yaml‎

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ release:
1313
# forbidden and List silently drops those dropdowns (Get returns 500). The
1414
# bare cozystack.io grant does NOT cover backups.cozystack.io — RBAC matches
1515
# the API group string exactly.
16+
#
17+
# The last two tests bound the role from two directions, and neither covers the
18+
# other. The count bound pins the list at exactly sixteen: templates/rbac.yaml
19+
# carries no template directives, so anything appended makes rules[16] exist and
20+
# anything dropped takes rules[15] away, whatever the rule is called. It says
21+
# nothing about a grant swapped in for an existing one, because the count does
22+
# not move under a swap. The spelling assert catches that case for the one rule
23+
# it names, and misses every other wording of it, because helm-unittest compares
24+
# each field it is handed by value equality and `any: true` only selects which
25+
# fields are compared. Changing the rule count on purpose means moving both
26+
# indices below, which is the review this role should get.
1627

1728
tests:
1829
- it: grants read on backups.cozystack.io plans and backups for the plan/backup providers
@@ -24,6 +35,15 @@ tests:
2435
resources: ["backupclasses", "plans", "backups"]
2536
verbs: ["get", "watch", "list"]
2637

38+
- it: grants full access on cilium.io ciliumnetworkpolicies for SecurityGroup storage
39+
asserts:
40+
- contains:
41+
path: rules
42+
content:
43+
apiGroups: ["cilium.io"]
44+
resources: ["ciliumnetworkpolicies"]
45+
verbs: ["get", "watch", "list", "create", "update", "patch", "delete"]
46+
2747
- it: does not grant objectstorage.k8s.io bucketclasses (no provider reads it)
2848
asserts:
2949
- notContains:
@@ -33,11 +53,11 @@ tests:
3353
resources: ["bucketclasses"]
3454
verbs: ["get", "watch", "list"]
3555

36-
- it: grants full access on cilium.io ciliumnetworkpolicies for SecurityGroup storage
56+
- it: ships exactly the sixteen rules this role is pinned to
3757
asserts:
38-
- contains:
39-
path: rules
40-
content:
41-
apiGroups: ["cilium.io"]
42-
resources: ["ciliumnetworkpolicies"]
43-
verbs: ["get", "watch", "list", "create", "update", "patch", "delete"]
58+
# Both directions. A dropped grant is the failure this suite is about:
59+
# the apiserver returns forbidden and List silently drops the dropdown.
60+
- exists:
61+
path: rules[15]
62+
- notExists:
63+
path: rules[16]

0 commit comments

Comments
 (0)