Skip to content

design-proposals: Keycloak SSO for tenant Grafana#15

Open
IvanHunters wants to merge 1 commit into
cozystack:mainfrom
IvanHunters:design/grafana-keycloak-tenants
Open

design-proposals: Keycloak SSO for tenant Grafana#15
IvanHunters wants to merge 1 commit into
cozystack:mainfrom
IvanHunters:design/grafana-keycloak-tenants

Conversation

@IvanHunters

Copy link
Copy Markdown

Summary

Adds a draft design proposal for making Keycloak SSO automatic on every tenant Grafana, not just the root tenant's. Today the monitoring chart hardcodes the OAuth wiring against _cluster.\"root-host\", so child tenants ship without auth.generic_oauth configured at all — operators end up with only the local admin/password login.

The proposal mirrors how cozy-dashboard already wires per-tenant KeycloakClient + Secret + dashboard config. Per non-root tenant the monitoring chart renders:

  • a KeycloakClient grafana-<tenant>-client in cozy-keycloak scoped to that tenant's host;
  • the corresponding Secret (mirrored to the tenant ns via ESO / Reflector — picked one of two options in the body, open question for reviewers);
  • the auth.generic_oauth block + GF_OAUTH_CLIENT_SECRET env on the Grafana CR.

Default role mapping mirrors today's root behaviour (cozystack-cluster-admin → Admin), but is overridable per tenant for tenant-scoped groups.

Why now

The TTK platform operations team is running a manual workaround in production: patch the shared grafana-client KeycloakClient to add child redirect URIs, mirror the Secret by hand, suspend: true the tenant's monitoring HelmRelease, and kubectl patch grafana ... to add the OAuth block. This freezes all monitoring chart updates for the affected tenant and is brittle (collisions with Grafana operator reconciles caused multi-RS rollout loops in our deployment). The fix belongs in-chart.

Open questions for reviewers

In the body — copied here so they don't get lost:

  • Default allowedGroups value for non-root tenants: cozystack-cluster-admin (today's root behaviour, convenient) or empty (safer, but worse first-day UX)?
  • Auto-render default per-tenant KeycloakRealmGroups (grafana-tenant-X-admin/viewer) or leave it to the operator?
  • Secret mirror mechanism: ESO ExternalSecret, Reflector annotation, or chart-managed dual-write?
  • Should we generalise the pattern (an IdentityProvider abstraction reusable for Argo CD / JupyterHub / etc.) now, or wait until a second use-case forces the abstraction?

Proposes that the monitoring chart auto-renders a per-tenant
KeycloakClient + secret + Grafana auth.generic_oauth block for every
non-root tenant, mirroring how cozy-dashboard already gets per-tenant
SSO wiring. Default behaviour for tenant-root stays identical.

Replaces the production workaround currently in use on the TTK platform
(manual KeycloakClient patches + monitoring-system HelmRelease suspend
+ kubectl patch grafana), which is brittle and freezes all chart
updates for the affected tenant.

Signed-off-by: IvanHunters <xorokhotnikov@gmail.com>
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@IvanHunters, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 55 minutes and 44 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 61757034-8e4a-4534-b0a4-b27173fecf67

📥 Commits

Reviewing files that changed from the base of the PR and between abb40d0 and 40bfffa.

📒 Files selected for processing (1)
  • design-proposals/grafana-keycloak-sso-for-tenants/README.md
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a design proposal for implementing automatic Keycloak SSO for tenant Grafana instances in Cozystack. The proposal details the resource architecture, secret mirroring, and role mapping configurations. Feedback on the proposal highlights two key points: first, Grafana's native syntax for environment variable interpolation should be corrected to $__env{GF_OAUTH_CLIENT_SECRET}; second, using ExternalSecret (ESO) is recommended over Reflector for secret mirroring, as Reflector requires annotations on the operator-managed source secret which may not be supported.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

enabled: "true"
name: Keycloak
client_id: grafana-{{ .Release.Namespace }}
client_secret: ${GF_OAUTH_CLIENT_SECRET}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Grafana's native syntax for environment variable interpolation in configuration files is $__env{VAR_NAME} rather than ${VAR_NAME}. Using $__env{GF_OAUTH_CLIENT_SECRET} is recommended to ensure the configuration is parsed correctly by Grafana.

Suggested change
client_secret: ${GF_OAUTH_CLIENT_SECRET}
client_secret: $__env{GF_OAUTH_CLIENT_SECRET}


Two ways to wire this:

- **Option A (proposed): operator-managed in `cozy-keycloak`, projected via existing `External Secrets / Reflector`.** Cozystack already runs `external-secrets-operator` for similar cross-namespace secret plumbing. The chart renders an `ExternalSecret` (or equivalent `Reflector`-annotated mirror) so the tenant ns gets a copy automatically. No human action.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

When using Reflector for secret mirroring, the source secret in cozy-keycloak must be annotated with reflector.v1.k8s.io/reflection-allowed: "true". Since this secret is managed and generated by the Keycloak operator, adding these annotations might not be supported directly. Using ExternalSecret (ESO) is a more robust approach as it does not require modifying the source secret.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant