From 2537b581563dc5fc9f02b0db2ccd25b7bf127cce Mon Sep 17 00:00:00 2001 From: Myasnikov Daniil Date: Tue, 29 Sep 2026 18:34:24 +0500 Subject: [PATCH 1/2] security(info): do not render the tenant ServiceAccount token under OIDC The Info application selects the ServiceAccount token Secret for the tenantsecrets API, and the use tier can read tenantsecrets, so the token and the rights bound to its ServiceAccount were readable by every use member of the tenant. With OIDC enabled the dashboard signs in with the user's own ID token and nothing consumes the token, so the Secret is no longer rendered. Removing it also invalidates tokens that were already read. Assisted-by: LLM Signed-off-by: Myasnikov Daniil Signed-off-by: Andrei Kvapil (cherry picked from commit 5674d01c95795a864b9dcee7eb5d8648f701f321) --- .../extra/info/templates/serviceaccount.yaml | 3 ++ .../extra/info/tests/serviceaccount_test.yaml | 40 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 packages/extra/info/tests/serviceaccount_test.yaml diff --git a/packages/extra/info/templates/serviceaccount.yaml b/packages/extra/info/templates/serviceaccount.yaml index 492f1b273..92a220cf3 100644 --- a/packages/extra/info/templates/serviceaccount.yaml +++ b/packages/extra/info/templates/serviceaccount.yaml @@ -1,3 +1,5 @@ +{{- $oidcEnabled := index .Values._cluster "oidc-enabled" }} +{{- if ne $oidcEnabled "true" }} --- apiVersion: v1 kind: Secret @@ -6,3 +8,4 @@ metadata: annotations: kubernetes.io/service-account.name: {{ .Release.Namespace }} type: kubernetes.io/service-account-token +{{- end }} diff --git a/packages/extra/info/tests/serviceaccount_test.yaml b/packages/extra/info/tests/serviceaccount_test.yaml new file mode 100644 index 000000000..2422eac89 --- /dev/null +++ b/packages/extra/info/tests/serviceaccount_test.yaml @@ -0,0 +1,40 @@ +suite: info tenant ServiceAccount token +templates: + - templates/serviceaccount.yaml + +release: + name: info + namespace: tenant-root + +# The Info application selects this Secret for the tenantsecrets API, and +# cozy:tenant:use can read tenantsecrets. Rendering a live ServiceAccount token +# under OIDC therefore hands the token, and the rights bound to that +# ServiceAccount, to every member of the use tier. Under OIDC the dashboard +# signs in with the user's own ID token, so nothing needs the token there. +# _cluster.oidc-enabled arrives as the string "true" or "false", never a bool. + +tests: + - it: renders no token Secret when OIDC is enabled + set: + _cluster: + oidc-enabled: "true" + asserts: + - hasDocuments: + count: 0 + + - it: renders the token Secret when OIDC is disabled + set: + _cluster: + oidc-enabled: "false" + asserts: + - hasDocuments: + count: 1 + - equal: + path: type + value: kubernetes.io/service-account-token + - equal: + path: metadata.name + value: tenant-root + - equal: + path: metadata.annotations["kubernetes.io/service-account.name"] + value: tenant-root From d845c7d6c831f30b3b285349e53588a93964fbd3 Mon Sep 17 00:00:00 2001 From: Myasnikov Daniil Date: Tue, 29 Sep 2026 18:34:45 +0500 Subject: [PATCH 2/2] security(info): bind the real tenant ServiceAccount without OIDC The RoleBinding subject was built as tenant- in namespace tenant-, but the release namespace already starts with tenant-, so the binding did not name the tenant's own ServiceAccount. The name it did form is one another tenant can claim: a child named root of a tenant named tenant owns the ServiceAccount tenant-tenant-root, which would then be granted the token Secret of tenant-root. Bind the tenant's own ServiceAccount instead. Assisted-by: LLM Signed-off-by: Myasnikov Daniil Signed-off-by: Andrei Kvapil --- .../info/templates/dashboard-resourcemap.yaml | 4 +- .../tests/dashboard_resourcemap_test.yaml | 44 +++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 packages/extra/info/tests/dashboard_resourcemap_test.yaml diff --git a/packages/extra/info/templates/dashboard-resourcemap.yaml b/packages/extra/info/templates/dashboard-resourcemap.yaml index aa8b7641b..61aa5cf20 100644 --- a/packages/extra/info/templates/dashboard-resourcemap.yaml +++ b/packages/extra/info/templates/dashboard-resourcemap.yaml @@ -25,8 +25,8 @@ subjects: {{ include "cozy-lib.rbac.subjectsForTenantAndAccessLevel" (list "view" .Release.Namespace) }} {{- else }} - kind: ServiceAccount - name: tenant-{{ .Release.Namespace }} - namespace: tenant-{{ .Release.Namespace }} + name: {{ .Release.Namespace }} + namespace: {{ .Release.Namespace }} {{- end }} roleRef: kind: Role diff --git a/packages/extra/info/tests/dashboard_resourcemap_test.yaml b/packages/extra/info/tests/dashboard_resourcemap_test.yaml new file mode 100644 index 000000000..db1e6d678 --- /dev/null +++ b/packages/extra/info/tests/dashboard_resourcemap_test.yaml @@ -0,0 +1,44 @@ +suite: info dashboard resource access +templates: + - templates/dashboard-resourcemap.yaml + +release: + name: info + namespace: tenant-root + +# The tenant ServiceAccount is named after the namespace, which already starts +# with "tenant-". Without OIDC the dashboard signs in with that ServiceAccount's +# token, so the RoleBinding has to name exactly that subject. + +tests: + - it: binds the tenant ServiceAccount by its real name without OIDC + set: + _cluster: + oidc-enabled: "false" + documentIndex: 1 + asserts: + - isKind: + of: RoleBinding + - contains: + path: subjects + content: + kind: ServiceAccount + name: tenant-root + namespace: tenant-root + - notContains: + path: subjects + content: + kind: ServiceAccount + name: tenant-tenant-root + namespace: tenant-tenant-root + + - it: grants the token Secret by name without OIDC + set: + _cluster: + oidc-enabled: "false" + documentIndex: 0 + asserts: + - equal: + path: rules[0].resourceNames + value: + - tenant-root