From 57bb0d703f5f25fb945a130bbafa36d09b7ea219 Mon Sep 17 00:00:00 2001 From: Timofei Larkin Date: Wed, 18 Nov 2026 10:51:09 +0100 Subject: [PATCH] feat(cozyplane): give tenants the cozyplane API through cozy:tenant The cozyplane chart's tenant roles aggregate into the built-in admin/edit/view ClusterRoles, which no Cozystack tenant is bound to, so VPC self-service was Forbidden for every tenant. The wrapper carries them across: one role aggregates the chart's edit role into cozy:tenant (the tenant ServiceAccount Flux applies tenant releases as) and the admin tier, another the view role into the view tier. Aggregating the chart's roles instead of copying their rules keeps the list of tenant kinds the chart's to maintain, the NAT gateways and route tables the last re-vendor added included. Assisted-by: LLM Signed-off-by: Timofei Larkin --- .../cozyplane/templates/tenant-rbac.yaml | 31 ++++++++++ .../cozyplane/tests/tenant_rbac_test.yaml | 61 +++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 packages/system/cozyplane/templates/tenant-rbac.yaml create mode 100644 packages/system/cozyplane/tests/tenant_rbac_test.yaml diff --git a/packages/system/cozyplane/templates/tenant-rbac.yaml b/packages/system/cozyplane/templates/tenant-rbac.yaml new file mode 100644 index 000000000..7d7399d46 --- /dev/null +++ b/packages/system/cozyplane/templates/tenant-rbac.yaml @@ -0,0 +1,31 @@ +{{- /* Cozystack tenants hold the cozy:tenant* roles, not the built-in + admin/edit/view the cozyplane chart's own tenant roles aggregate into. + These roles carry those rules across by aggregating the chart's roles, + so the list of tenant kinds stays the chart's to maintain. */}} +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: cozy:tenant:cozyplane-edit + labels: + rbac.cozystack.io/aggregate-to-tenant: "true" + rbac.cozystack.io/aggregate-to-tenant-admin: "true" +aggregationRule: + clusterRoleSelectors: + - matchLabels: + app.kubernetes.io/part-of: cozyplane + rbac.authorization.k8s.io/aggregate-to-edit: "true" +rules: [] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: cozy:tenant:cozyplane-view + labels: + rbac.cozystack.io/aggregate-to-tenant-view: "true" +aggregationRule: + clusterRoleSelectors: + - matchLabels: + app.kubernetes.io/part-of: cozyplane + rbac.authorization.k8s.io/aggregate-to-view: "true" +rules: [] diff --git a/packages/system/cozyplane/tests/tenant_rbac_test.yaml b/packages/system/cozyplane/tests/tenant_rbac_test.yaml new file mode 100644 index 000000000..ca4eaa0af --- /dev/null +++ b/packages/system/cozyplane/tests/tenant_rbac_test.yaml @@ -0,0 +1,61 @@ +suite: tenants get the cozyplane tenant API through the cozy:tenant tiers +# Cozystack tenants are bound only to cozy:tenant*, whose aggregation selects +# rbac.cozystack.io labels; the cozyplane chart's own tenant roles carry the +# built-in admin/edit/view labels, which no tenant holds. +templates: + - templates/tenant-rbac.yaml + - charts/cozyplane/templates/tenant-rbac.yaml +release: + name: cozyplane + namespace: cozy-cozyplane +tests: + # cozy:tenant is the tenant ServiceAccount's role (the identity Flux applies + # tenant releases as); admin is the human tier that manages VPCs. + - it: carries the chart's edit role into the tenant and admin tiers + template: templates/tenant-rbac.yaml + documentSelector: + path: metadata.name + value: cozy:tenant:cozyplane-edit + asserts: + - equal: + path: metadata.labels + value: + rbac.cozystack.io/aggregate-to-tenant: "true" + rbac.cozystack.io/aggregate-to-tenant-admin: "true" + - equal: + path: aggregationRule.clusterRoleSelectors + value: + - matchLabels: + app.kubernetes.io/part-of: cozyplane + rbac.authorization.k8s.io/aggregate-to-edit: "true" + + - it: carries the chart's view role into the view tier + template: templates/tenant-rbac.yaml + documentSelector: + path: metadata.name + value: cozy:tenant:cozyplane-view + asserts: + - equal: + path: metadata.labels + value: + rbac.cozystack.io/aggregate-to-tenant-view: "true" + - equal: + path: aggregationRule.clusterRoleSelectors + value: + - matchLabels: + app.kubernetes.io/part-of: cozyplane + rbac.authorization.k8s.io/aggregate-to-view: "true" + + # The selectors must match the chart's roles, or the aggregation is empty. + - it: matches the labels the chart's tenant roles actually carry + template: charts/cozyplane/templates/tenant-rbac.yaml + documentSelector: + path: metadata.name + value: cozyplane-tenant-edit + asserts: + - equal: + path: metadata.labels["app.kubernetes.io/part-of"] + value: cozyplane + - equal: + path: metadata.labels["rbac.authorization.k8s.io/aggregate-to-edit"] + value: "true"