mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-22 12:43:32 +09:00
The assertions withholding the key-bearing TLS Secrets from the tenant Role addressed it as document 0 and, in two cases, asserted only with notContains. Neither survives a rearrangement. notContains passes when its path does not resolve, so a test built from it alone goes green against the wrong document. Reversing the order of the two documents in the template moved the RoleBinding into position 0, and "does not grant the key-bearing TLS secrets when external is enabled" and "does not grant the tenant-ca projection by name" both stayed green while the Role granted <release>-ca-cert by name — the Secret holding the CA private key. Select the Role by kind, and pair every notContains with a positive assertion on the same path so a rule reordering that moves rules[1] reddens too. Indexing survives neither rearrangement; selecting survives the first; the positive anchor catches the second. Signed-off-by: Aleksei Sviridkin <f@lex.la>
239 lines
7.0 KiB
YAML
239 lines
7.0 KiB
YAML
suite: dashboard resourcemap tests
|
|
|
|
templates:
|
|
- templates/dashboard-resourcemap.yaml
|
|
|
|
tests:
|
|
# Always renders Role and RoleBinding
|
|
- it: renders Role and RoleBinding
|
|
release:
|
|
name: test-mongodb
|
|
namespace: tenant-test
|
|
asserts:
|
|
- hasDocuments:
|
|
count: 2
|
|
- isKind:
|
|
of: Role
|
|
documentIndex: 0
|
|
- isKind:
|
|
of: RoleBinding
|
|
documentIndex: 1
|
|
|
|
# Role naming
|
|
- it: uses correct Role name
|
|
release:
|
|
name: mydb
|
|
namespace: tenant-test
|
|
asserts:
|
|
- equal:
|
|
path: metadata.name
|
|
value: mydb-dashboard-resources
|
|
documentIndex: 0
|
|
|
|
# RoleBinding naming
|
|
- it: uses correct RoleBinding name
|
|
release:
|
|
name: mydb
|
|
namespace: tenant-test
|
|
asserts:
|
|
- equal:
|
|
path: metadata.name
|
|
value: mydb-dashboard-resources
|
|
documentIndex: 1
|
|
|
|
# Role grants access to services
|
|
- it: grants access to MongoDB services
|
|
release:
|
|
name: test-mongodb
|
|
namespace: tenant-test
|
|
asserts:
|
|
- contains:
|
|
path: rules[0].resourceNames
|
|
content: test-mongodb-rs0
|
|
documentIndex: 0
|
|
- contains:
|
|
path: rules[0].resourceNames
|
|
content: test-mongodb-mongos
|
|
documentIndex: 0
|
|
- contains:
|
|
path: rules[0].resourceNames
|
|
content: test-mongodb-external
|
|
documentIndex: 0
|
|
|
|
# Role grants access to credentials secret
|
|
- it: grants access to credentials secret
|
|
release:
|
|
name: test-mongodb
|
|
namespace: tenant-test
|
|
asserts:
|
|
- contains:
|
|
path: rules[1].resourceNames
|
|
content: test-mongodb-credentials
|
|
documentIndex: 0
|
|
|
|
# Role grants access to workloadmonitor
|
|
- it: grants access to WorkloadMonitor
|
|
release:
|
|
name: test-mongodb
|
|
namespace: tenant-test
|
|
asserts:
|
|
- contains:
|
|
path: rules[2].resourceNames
|
|
content: test-mongodb
|
|
documentIndex: 0
|
|
- equal:
|
|
path: rules[2].apiGroups[0]
|
|
value: cozystack.io
|
|
documentIndex: 0
|
|
|
|
# RoleBinding references correct Role
|
|
- it: RoleBinding references correct Role
|
|
release:
|
|
name: test-mongodb
|
|
namespace: tenant-test
|
|
asserts:
|
|
- equal:
|
|
path: roleRef.kind
|
|
value: Role
|
|
documentIndex: 1
|
|
- equal:
|
|
path: roleRef.name
|
|
value: test-mongodb-dashboard-resources
|
|
documentIndex: 1
|
|
- equal:
|
|
path: roleRef.apiGroup
|
|
value: rbac.authorization.k8s.io
|
|
documentIndex: 1
|
|
|
|
# The operator's TLS Secrets both carry private key material: <release>-ca-cert
|
|
# holds the CA private key, <release>-ssl holds the server private key. Neither
|
|
# may ever be granted to a tenant. The trust anchor is delivered instead as the
|
|
# key-free <release>.tenant-ca projection, via core.cozystack.io/tenantsecrets
|
|
# — a label-gated path, so it needs no grant in this Role either.
|
|
#
|
|
# The four tests below pick the Role with documentSelector rather than
|
|
# documentIndex, and each pairs its notContains with a positive assertion on
|
|
# the same path. Both halves are load-bearing and neither substitutes for the
|
|
# other: notContains passes when the path does not resolve, so on its own it
|
|
# goes green against the WRONG document (reorder the template) and green when
|
|
# the path moves (reorder the rules). Indexing survives neither; selecting
|
|
# survives the first; the positive anchor catches the second.
|
|
|
|
- it: Role does not grant the key-bearing TLS secrets
|
|
release:
|
|
name: test-mongodb
|
|
namespace: tenant-test
|
|
documentSelector:
|
|
path: kind
|
|
value: Role
|
|
asserts:
|
|
- notContains:
|
|
path: rules[1].resourceNames
|
|
content: test-mongodb-ca-cert
|
|
- notContains:
|
|
path: rules[1].resourceNames
|
|
content: test-mongodb-ssl
|
|
- equal:
|
|
path: rules[1].resourceNames
|
|
value:
|
|
- test-mongodb-credentials
|
|
|
|
- it: Role does not grant the key-bearing TLS secrets when external is enabled
|
|
release:
|
|
name: test-mongodb
|
|
namespace: tenant-test
|
|
documentSelector:
|
|
path: kind
|
|
value: Role
|
|
set:
|
|
external: true
|
|
asserts:
|
|
- notContains:
|
|
path: rules[1].resourceNames
|
|
content: test-mongodb-ca-cert
|
|
- notContains:
|
|
path: rules[1].resourceNames
|
|
content: test-mongodb-ssl
|
|
- equal:
|
|
path: rules[1].resourceNames
|
|
value:
|
|
- test-mongodb-credentials
|
|
|
|
- it: Role does not grant the tenant-ca projection by name
|
|
release:
|
|
name: test-mongodb
|
|
namespace: tenant-test
|
|
documentSelector:
|
|
path: kind
|
|
value: Role
|
|
asserts:
|
|
- notContains:
|
|
path: rules[1].resourceNames
|
|
content: test-mongodb.tenant-ca
|
|
- equal:
|
|
path: rules[1].resourceNames
|
|
value:
|
|
- test-mongodb-credentials
|
|
|
|
- it: Role has exactly three rules
|
|
release:
|
|
name: test-mongodb
|
|
namespace: tenant-test
|
|
documentSelector:
|
|
path: kind
|
|
value: Role
|
|
asserts:
|
|
# The secret assertions above are all anchored to rules[1]. Without this,
|
|
# a fourth rule granting secrets by name would satisfy every one of them
|
|
# while reopening the leak.
|
|
- lengthEqual:
|
|
path: rules
|
|
count: 3
|
|
|
|
- it: the secrets rule grants secrets and nothing wider
|
|
release:
|
|
name: test-mongodb
|
|
namespace: tenant-test
|
|
documentSelector:
|
|
path: kind
|
|
value: Role
|
|
asserts:
|
|
# Every other assertion here constrains resourceNames. None constrained
|
|
# `resources`, so mutating this rule to ["*"] would grant every resource
|
|
# kind in the namespace — Secrets included, whatever their names — while
|
|
# leaving the whole suite green.
|
|
- equal:
|
|
path: rules[1].resources
|
|
value:
|
|
- secrets
|
|
- equal:
|
|
path: rules[1].apiGroups
|
|
value:
|
|
- ""
|
|
# The other two rules are pinned for the same reason. Neither names a
|
|
# key-bearing Secret today, so widening one leaks nothing immediately —
|
|
# but a rule mutated to ["*"] would grant every resource kind for the
|
|
# names it lists, and closing the class costs no more than closing the
|
|
# one instance.
|
|
- equal:
|
|
path: rules[0].resources
|
|
value:
|
|
- services
|
|
- equal:
|
|
path: rules[2].resources
|
|
value:
|
|
- workloadmonitors
|
|
# verbs is the fourth axis of an RBAC rule and the last one left open.
|
|
# Widening it does not leak a key while resourceNames stays narrow, but
|
|
# it is the same widening class the assertions above close, and the Role
|
|
# is read-only by intent.
|
|
- equal:
|
|
path: rules[0].verbs
|
|
value: ["get", "list", "watch"]
|
|
- equal:
|
|
path: rules[1].verbs
|
|
value: ["get", "list", "watch"]
|
|
- equal:
|
|
path: rules[2].verbs
|
|
value: ["get", "list", "watch"]
|