Skip to content

feat(keycloak): expose organizationsEnabled realm toggle - #3031

Merged
Aleksei Sviridkin (lexfrei) merged 2 commits into
cozystack:mainfrom
mattia-eleuteri:feature/keycloak-configure-organizations-toggle
Sep 29, 2026
Merged

Aleksei Sviridkin (lexfrei) merged 2 commits into
cozystack:mainfrom
mattia-eleuteri:feature/keycloak-configure-organizations-toggle

Conversation

@mattia-eleuteri

@mattia-eleuteri mattia-eleuteri commented Jun 24, 2026 •

Copy link
Copy Markdown
Collaborator

What this PR does

  • Adds an organizationsEnabled value to the cozy-keycloak-configure chart (default false, no behaviour change).
  • Maps it to ClusterKeycloakRealm.spec.organizationsEnabled so the Keycloak Organizations feature can be turned on declaratively for the platform realm.

Why

The chart hardcoded the realm without exposing this field. Enabling Organizations through the Keycloak admin console is not durable: the EDP keycloak-operator reconciles ClusterKeycloakRealm by PUTting the chart-rendered spec back to the realm, so the console change is reverted on the next reconcile (operator restart, periodic resync, or any CR change). Verified on Keycloak 26.5.2.

Release note

feat(keycloak): add `organizationsEnabled` value to the keycloak-configure chart to enable the Keycloak Organizations feature on the platform realm (default: false)

Summary by CodeRabbit

  • New Features
    • Added a configuration option to enable or disable organizations in the platform-managed Keycloak realm.
    • Organizations remain disabled by default. Set the option to true to enable them.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new configuration toggle for the Keycloak realm managed by the cozy-keycloak-configure chart. By exposing the organizationsEnabled field, users can now declaratively enable the Keycloak Organizations feature, preventing manual configuration changes from being overwritten by the operator during reconciliation cycles.

Highlights

  • Configuration Update: Added the organizationsEnabled parameter to the cozy-keycloak-configure Helm chart to allow declarative management of the Keycloak Organizations feature.
  • Resource Mapping: Updated the ClusterKeycloakRealm template to map the new configuration value to spec.organizationsEnabled, ensuring persistence across operator reconciliations.
New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment Gemini (@gemini-code-assist) Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on Gemini (@gemini-code-assist) comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@github-actions github-actions Bot added area/uncategorized PR auto-labeler could not map title scope to a known area/*; please review kind/feature Categorizes issue or PR as related to a new feature size/XS This PR changes 0-9 lines, ignoring generated files labels Jun 24, 2026
@coderabbitai

coderabbitai Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: cozystack/cozystack/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 98669a51-5fb8-4984-805a-545a4e6e5a01

📥 Commits

Reviewing files that changed from the base of the PR and between 658c083 and 874590e.

📒 Files selected for processing (3)
  • packages/system/keycloak-configure/templates/configure-kk.yaml
  • packages/system/keycloak-configure/tests/organizations_enabled_test.yaml
  • packages/system/keycloak-configure/values.yaml

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The keycloak-configure Helm chart adds an organizationsEnabled value with a default of false. The chart passes this value to the ClusterKeycloakRealm spec. Tests cover the default and an explicit true value.

Changes

Keycloak Organizations Feature Flag

Layer / File(s) Summary
Default value and template wiring
packages/system/keycloak-configure/values.yaml, packages/system/keycloak-configure/templates/configure-kk.yaml, packages/system/keycloak-configure/tests/organizations_enabled_test.yaml
Adds organizationsEnabled: false, maps the value to the realm spec, and tests rendering with the default and with true.

Priority: ⬇️ Low

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Feature

Merge Risk: ⚪ Minimal · up to 87459

The setting remains false by default and allows explicit enablement; rendering tests cover both values. No material merge-blocking risk is evident.

Architecture Summary

Architecture risk: 🔵 Low · up to 87459

The change affects 1 system.

Changed systems: packages/system

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — packages/system (library) was modified; 3 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in packages/system/keycloak-configure/templates/configure-kk.yaml: The realm configuration adds organizationsEnabled, sourced from chart values and defaulting to false.
  • observed — Modified behavior in packages/system/keycloak-configure/tests/organizations_enabled_test.yaml: Adds a test asserting that, with the specified cluster settings and no organizationsEnabled override, the rendered realm spec has organizationsEnabled: false.
  • observed — Modified behavior in packages/system/keycloak-configure/tests/organizations_enabled_test.yaml: Adds a test asserting that setting organizationsEnabled: true renders spec.organizationsEnabled as true.
  • observed — Modified behavior in packages/system/keycloak-configure/values.yaml: Adds the organizationsEnabled chart value, defaulting to false; its comments identify it as the setting mapped to ClusterKeycloakRealm.spec.organizationsEnabled.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: exposing the Keycloak realm organizationsEnabled toggle.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

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.

@dosubot dosubot Bot added the area/platform Issues or PRs related to platform infrastructure (bundle, flux, talos, installer) label Jun 24, 2026

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

Copy link
Copy Markdown
Contributor

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 adds the organizationsEnabled parameter to the Keycloak configuration chart, allowing the Keycloak Organizations feature to be enabled for the cozy realm (defaulting to false). The review feedback recommends using an explicit boolean comparison instead of the default function in the Helm template, as default can behave unexpectedly with boolean false values.

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.

spec:
realmName: cozy
clusterKeycloakRef: keycloak-cozy
organizationsEnabled: {{ .Values.organizationsEnabled | default false }}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

low

In Helm/Go templates, using the default function with boolean values can be risky because a boolean false is treated as empty/falsy, which triggers the default value. While this works here because the default is also false, a more robust and idiomatic way to handle boolean values is to use an explicit eq comparison against true.

  organizationsEnabled: {{ eq .Values.organizationsEnabled true }}

@lexfrei Aleksei Sviridkin (lexfrei) added area/keycloak Issues or PRs related to Keycloak (SSO / identity) and removed area/uncategorized PR auto-labeler could not map title scope to a known area/*; please review labels Jul 1, 2026
@lexfrei

Copy link
Copy Markdown
Contributor

This conflicts with main and needs a rebase. The organizationsEnabled toggle isn't present under packages/system/keycloak-configure/ yet, so the change still applies cleanly once rebased.

@mattia-eleuteri
mattia-eleuteri force-pushed the feature/keycloak-configure-organizations-toggle branch from 658c083 to 4214cfd Compare July 9, 2026 07:23
@github-actions github-actions Bot added the area/uncategorized PR auto-labeler could not map title scope to a known area/*; please review label Jul 9, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

NOT LGTM — the change itself is correct, but this chart already ships a helm-unittest suite over the very template being changed, and the new value arrives untested.

Business context: ClusterKeycloakRealm is rendered from the chart, and the keycloak-operator reconciles it by PUTting that spec back, so enabling Organizations through the admin console is reverted on the next reconcile; the realm field has to be exposed as a chart value to make it durable.

Blockers

B1: new value and new rendered field ship without a unit test

File: packages/system/keycloak-configure/ (missing tests/ case)
Issue: packages/system/keycloak-configure/tests/login_theme_test.yaml already covers templates/configure-kk.yaml — the same template this PR edits — asserting a rendered ClusterKeycloakRealm field from a chart value, and Makefile has test: helm unittest ., so CI runs the suite. Adding organizationsEnabled to values.yaml and a new spec.organizationsEnabled line to the template without a corresponding test leaves the contract unpinned in a chart that has an established test convention.
Impact: nothing pins the default (false, i.e. no behaviour change — the PR's central claim) or the enabled path, so either can regress silently. A future edit to the {{ .Values.organizationsEnabled | default false }} expression would not be caught.
Fix: add a case to tests/ mirroring the existing suite's shape — template: templates/configure-kk.yaml with documentSelector on kind: ClusterKeycloakRealm — asserting that the chart default renders spec.organizationsEnabled: false, and that set: {organizationsEnabled: true} renders spec.organizationsEnabled: true.

Non-blocking follow-up

| default false is correct here — it covers the case where the key is absent entirely, which would otherwise render an empty value. Worth knowing that the guard does not generalise: sprig's default treats false as empty, so if the default is ever flipped to true, | default true would silently override a user's explicit organizationsEnabled: false. At that point the expression would need a hasKey-style guard instead.

What I verified: the vendored CRD at packages/system/keycloak-operator/charts/keycloak-operator/crds/v1.edp.epam.com_clusterkeycloakrealms.yaml does declare organizationsEnabled (with default: false), so the field is not silently pruned by the structural schema and the toggle genuinely reaches the realm. The rendered value is an unquoted YAML boolean, and the default preserves current behaviour.

@github-actions github-actions Bot added size/M This PR changes 30-99 lines, ignoring generated files and removed size/XS This PR changes 0-9 lines, ignoring generated files labels Jul 9, 2026
@mattia-eleuteri

Copy link
Copy Markdown
Collaborator Author

B1 addressed in test(keycloak): pin organizationsEnabled rendering in configure-kk: new tests/organizations_enabled_test.yaml mirrors the login-theme suite (documentSelector on ClusterKeycloakRealm) and pins both paths — chart default renders spec.organizationsEnabled: false, and organizationsEnabled: true renders through. helm unittest green locally (2 suites, 4 tests). Noted on the sprig default gotcha — agreed a flip of the default to true would need a hasKey guard; the default-path test now pins that behaviour so it can't change silently.

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

This PR has had no activity for 60 days and was marked lifecycle/stale.
It will be closed in 14 days unless commented or labelled lifecycle/frozen.

@github-actions github-actions Bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale label Sep 8, 2026
@github-actions github-actions Bot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale label Sep 22, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

mattia-eleuteri NOT LGTM. The code and the new test are fine now, but the first commit carries model attribution trailers that main's required pre-commit check rejects.

The test blocker from July is closed. tests/organizations_enabled_test.yaml pins both the default and the enabled path. On a trial merge with current main the chart suite passes, 6 suites and 13 tests. Both cases are real checks: with the template value hardcoded to false the enabled case fails, and with the line removed both fail. The change still lands in the right place. Main's operator build (edp-keycloak-operator facbc36) maps spec.organizationsEnabled into the realm representation in pkg/realmbuilder/settings_builder.go, and the vendored ClusterKeycloakRealm CRD still declares the field with default: false.

Blocker

B1: model attribution in the trailers of 4214cfd

File: commit 4214cfd71e3e5a30a466c4ad00bf798a51c9b300

The commit ends with these two lines:

Assisted-By: Claude <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

docs/agents/contributing.md ("AI Agent Attribution") allows one disclosure form only, Assisted-by: LLM, and no model or vendor name in any trailer. Since early September, main also enforces this in CI. .github/workflows/pre-commit.yml runs hack/check-commit-trailers.sh over the PR commits, and on this range it exits 1 with attribution trailer value must be exactly LLM. The only CI run on this head is from July, so it predates that check. After a rebase the required pre-commit check goes red. The repo merges with merge commits, so these trailers would land in main as is. I should have flagged this in July and missed it, sorry for the extra round.

Fix: reword 4214cfd with git rebase --interactive. Replace both lines with a single Assisted-by: LLM next to Signed-off-by, then rebase onto current main and force-push. The rebase also gets fresh CI on the branch.

Non-blocking

Main now takes the realm name from _cluster.oidc-realm-name, with cozy as the fallback. The new values.yaml comment and the PR body both say "the cozy realm". "The platform realm" would stay true for installs that rename it.

The keycloak-configure chart hardcoded the realm with the Organizations
feature off, with no value to enable it. Operators who flip
organizationsEnabled in the Keycloak admin console see it reverted on the
next ClusterKeycloakRealm reconcile, since the EDP operator pushes the
chart-rendered spec back to the realm.

Expose organizationsEnabled in values.yaml (default false, no behaviour
change) and map it to ClusterKeycloakRealm.spec.organizationsEnabled so
the feature can be enabled declaratively and survive reconciles.

Assisted-by: LLM
Signed-off-by: mattia-eleuteri <[email protected]>
Cover both paths of the new value: the chart default renders
spec.organizationsEnabled: false (no behaviour change), and setting
organizationsEnabled: true renders through to the ClusterKeycloakRealm.

Assisted-by: LLM
Signed-off-by: Mattia Eleuteri <[email protected]>
@mattia-eleuteri
mattia-eleuteri force-pushed the feature/keycloak-configure-organizations-toggle branch from 068df89 to 874590e Compare September 29, 2026 15:10
@mattia-eleuteri

Copy link
Copy Markdown
Collaborator Author

Aleksei Sviridkin (@lexfrei) B1 is fixed. I reworded 4214cfd: both trailers are gone, replaced by a single Assisted-by: LLM next to Signed-off-by. The test commit now carries the same trailer. The branch is rebased onto current main (0a2054e22) and force-pushed, so the head is now 874590e20. Locally, hack/check-commit-trailers.sh upstream/main..HEAD reports Commit trailers OK: 2 commit(s) checked, and helm unittest packages/system/keycloak-configure passes 6 suites and 13 tests.

Non-blocking: the values.yaml comment and the PR body now say "the platform realm" instead of "the cozy realm". I folded the comment change into the feat commit, since that commit was being rewritten anyway.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

mattia-eleuteri LGTM. Trailers are fixed, and the only other change is the comment wording.

@lexfrei
Aleksei Sviridkin (lexfrei) merged commit e56478c into cozystack:main Sep 29, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/keycloak Issues or PRs related to Keycloak (SSO / identity) area/platform Issues or PRs related to platform infrastructure (bundle, flux, talos, installer) area/uncategorized PR auto-labeler could not map title scope to a known area/*; please review kind/feature Categorizes issue or PR as related to a new feature size/M This PR changes 30-99 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants