Files
cozystack/packages/system/cozystack-api/tests/rbac_test.yaml
T
Aleksei Sviridkin b201a0f878 fix(api): leave failed golden images out of the image options
The image option source lists every vm-default-images-* PVC in
cozy-public. CDI creates that PVC as soon as an import starts, so a
golden whose DataVolume ended in phase Failed is still offered, and a
disk cloned from it never populates: the user picks an image the
platform just suggested and ends up with a disk that never becomes
usable.

Read the DataVolumes next to the PVCs and drop the names whose import
Failed. Filtering beats marking: the option can never be used, and
OptionItem has no disabled state to show it in. A golden still
importing stays, since CDI holds a clone until the source is
populated, and so does a PVC with no DataVolume. When the DataVolumes
cannot be read, without CDI or without the grant, the PVCs go out
unfiltered: the Option list drops a source whose provider errors, and
an empty picker would be a regression rather than a safeguard.

Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
2026-09-29 12:40:36 +03:00

96 lines
3.8 KiB
YAML

suite: cozystack-api ClusterRole grants Option provider sources
templates:
- templates/rbac.yaml
release:
name: cozystack-api
namespace: cozy-system
# The Option (dropdown) providers run with the cozystack-api ServiceAccount's
# privileged client, so every GVR a provider lists must be granted on this
# ClusterRole. The plan/backup providers list namespaced plans/backups in the
# backups.cozystack.io group; without read access there the apiserver returns
# forbidden and List silently drops those dropdowns (Get returns 500). The
# bare cozystack.io grant does NOT cover backups.cozystack.io — RBAC matches
# the API group string exactly.
#
# The last two tests bound the role from two directions, and neither covers the
# other. The count bound pins the list at exactly twenty-one: templates/rbac.yaml
# carries no template directives, so anything appended makes rules[21] exist and
# anything dropped takes rules[20] away, whatever the rule is called. It says
# nothing about a grant swapped in for an existing one, because the count does
# not move under a swap. The spelling assert catches that case for the one rule
# it names, and misses every other wording of it, because helm-unittest compares
# each field it is handed by value equality and `any: true` only selects which
# fields are compared. Changing the rule count on purpose means moving both
# indices below, which is the review this role should get.
tests:
- it: grants read on backups.cozystack.io plans and backups for the plan/backup providers
asserts:
- contains:
path: rules
content:
apiGroups: ["backups.cozystack.io"]
resources: ["backupclasses", "plans", "backups"]
verbs: ["get", "watch", "list"]
- it: grants full access on cilium.io ciliumnetworkpolicies for SecurityGroup storage
asserts:
- contains:
path: rules
content:
apiGroups: ["cilium.io"]
resources: ["ciliumnetworkpolicies"]
verbs: ["get", "watch", "list", "create", "update", "patch", "delete"]
# The marketplace tap flow: disconnecting a tap deletes its cluster-scoped
# PackageSource and the tap-managed registration Package that de-registers its
# apps, and the tap's Flux OCIRepository is read to report status. These grants
# live on this ClusterRole because the tap handler runs with the cozystack-api
# ServiceAccount's client.
- it: grants delete on cozystack.io packagesources and packages for tap disconnect
asserts:
- contains:
path: rules
content:
apiGroups: ["cozystack.io"]
resources: ["packagesources", "packages"]
verbs: ["delete"]
- it: grants read on source.toolkit.fluxcd.io ocirepositories for tap status
asserts:
- contains:
path: rules
content:
apiGroups: ["source.toolkit.fluxcd.io"]
resources: ["ocirepositories"]
verbs: ["get", "list", "watch"]
- it: grants read on cdi.kubevirt.io datavolumes for the image provider
asserts:
- contains:
path: rules
content:
apiGroups: ["cdi.kubevirt.io"]
resources: ["datavolumes"]
verbs: ["get", "watch", "list"]
- it: does not grant objectstorage.k8s.io bucketclasses (no provider reads it)
asserts:
- notContains:
path: rules
content:
apiGroups: ["objectstorage.k8s.io"]
resources: ["bucketclasses"]
verbs: ["get", "watch", "list"]
- it: ships exactly the twenty-one rules this role is pinned to
asserts:
# Both directions. A dropped grant is the failure this suite is about:
# the apiserver returns forbidden and List silently drops the dropdown.
- exists:
path: rules[20]
- notExists:
path: rules[21]