Files
cozystack/packages/system/cozystack-api/tests/rbac_test.yaml
T
IvanHunters aa20495df3 feat(marketplace): register a tapped repository's apps on connect
Connecting a marketplace repository materialized its PackageSource but created no Package, so its ApplicationDefinitions never rendered and its apps never appeared in the dashboard catalog until a manual `cozypkg add` the dashboard cannot drive (the package list is computed from the ApplicationDefinitions, which do not exist yet).

The tap materializer now creates a tap-managed registration Package for each materialized PackageSource, the way the platform ships a Package per built-in app, so the ApplicationDefinition registrations deploy on connect and the apps become browsable; the app components carry no install block and are still instantiated per user resource.

Privileged install components of an unconfirmed tap auto-registration (a Package that still carries the marketplace-tap label) are refused on several best-effort layers: the Package reconciler skips their HelmRelease and prunes a lingering one at the install site, and the PackageSource reconciler withholds their ExternalArtifact so the helm-controller has no privileged content to deploy, re-running on confirmation via a Package watch. `cozypkg add --allow-privileged` sheds the label as an explicit ownership handover, which is the confirmation; a platform Package never carries the label. A benign component flipped to privileged in a new revision can still be materialized by source-watcher before these layers observe the flip; closing that race fully requires decoupling the catalog registration from install and is tracked in issue #4359.

`cozypkg untap` and the dashboard disconnect remove the registration Package (de-registering the apps) under a UID + ResourceVersion precondition, so a concurrent `cozypkg add` handover is never clobbered; running instances are left but unmanaged. `cozypkg add` re-opens a tap auto-registration for variant selection and hands it over. The cozystack-api ClusterRole gains delete on packages for the disconnect path.

Assisted-by: LLM
Signed-off-by: IvanHunters <xorokhotnikov@gmail.com>
2026-09-21 21:57:04 +03:00

87 lines
3.5 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: templates/rbac.yaml
# carries no template directives, so anything appended makes rules[20] exist and
# anything dropped takes rules[19] 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: 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 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[19]
- notExists:
path: rules[20]