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"