Skip to content

[system] Fix Keycloak proxy configuration for v26.x#2125

Merged
kvaps merged 1 commit intomainfrom
fix/keycloak-proxy-headers
Mar 2, 2026
Merged

[system] Fix Keycloak proxy configuration for v26.x#2125
kvaps merged 1 commit intomainfrom
fix/keycloak-proxy-headers

Conversation

@sircthulhu
Copy link
Contributor

@sircthulhu sircthulhu commented Mar 2, 2026

What this PR does

Replace deprecated KC_PROXY=edge with KC_PROXY_HEADERS=xforwarded and KC_HTTP_ENABLED=true in the Keycloak StatefulSet template.

KC_PROXY was removed in Keycloak 26.x, causing "Non-secure context detected" warnings and broken cookie handling when running behind a reverse proxy with TLS termination.

Release note

[system] Fix Keycloak proxy headers configuration for compatibility with Keycloak 26.x

Summary by CodeRabbit

Release Notes

  • Chores
    • Updated system configuration to improve proxy header handling and enable direct HTTP support for enhanced compatibility with reverse proxy environments.

KC_PROXY=edge was deprecated and removed in Keycloak 26.x, causing
"Non-secure context detected" warnings and broken cookie handling
behind reverse proxy. Replace with KC_PROXY_HEADERS=xforwarded and
KC_HTTP_ENABLED=true.

Co-Authored-By: Claude <[email protected]>
Signed-off-by: Kirill Ilin <[email protected]>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 2, 2026

📝 Walkthrough

Walkthrough

This change updates Keycloak's environment configuration by replacing the KC_PROXY setting with KC_PROXY_HEADERS and adding KC_HTTP_ENABLED. The modification alters how proxy headers are handled and enables HTTP protocol support within the Keycloak container.

Changes

Cohort / File(s) Summary
Keycloak Configuration
packages/system/keycloak/templates/sts.yaml
Replaced KC_PROXY: "edge" with KC_PROXY_HEADERS: "xforwarded" and added KC_HTTP_ENABLED: "true" to update proxy and HTTP settings.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A hop, a skip, through proxy's way,
Headers now flow with xforwarded sway,
HTTP enabled, connections take flight,
Keycloak's config shines ever so bright! 🌟

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly describes the main change: updating Keycloak proxy configuration to address compatibility with v26.x by replacing deprecated environment variables.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/keycloak-proxy-headers

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
Copy link
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 updates the Keycloak StatefulSet configuration to ensure compatibility with Keycloak version 26.x and later. The changes resolve issues related to proxy handling and secure context detection that arose from the removal of a deprecated environment variable, thereby maintaining proper functionality when Keycloak is deployed behind a reverse proxy.

Highlights

  • Keycloak Proxy Configuration Update: Replaced the deprecated KC_PROXY=edge environment variable with KC_PROXY_HEADERS=xforwarded and KC_HTTP_ENABLED=true in the Keycloak StatefulSet template.
  • Keycloak 26.x Compatibility: Addressed compatibility issues with Keycloak 26.x, where the KC_PROXY variable was removed, leading to "Non-secure context detected" warnings and broken cookie handling when Keycloak runs behind a reverse proxy with TLS termination.

🧠 New Feature in Public Preview: You can now enable Memory 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.

Changelog
  • packages/system/keycloak/templates/sts.yaml
    • [system] Fix Keycloak proxy headers configuration for compatibility with Keycloak 26.x
Activity
  • No specific activity has been recorded for this pull request yet.
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-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 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 counter productive. You can react with 👍 and 👎 on @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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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.

@sircthulhu sircthulhu marked this pull request as ready for review March 2, 2026 09:37
@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. bug Something isn't working labels Mar 2, 2026
Copy link
Contributor

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

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 updates the Keycloak proxy configuration to align with the changes in Keycloak v26.x. The deprecated KC_PROXY environment variable is correctly replaced with KC_PROXY_HEADERS and KC_HTTP_ENABLED. This is a necessary change to ensure Keycloak functions correctly behind a reverse proxy that terminates TLS, and it resolves issues like incorrect cookie handling. The implementation is correct and follows the official Keycloak migration guide.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/system/keycloak/templates/sts.yaml`:
- Around line 85-88: Add the KC_PROXY_TRUSTED_ADDRESSES environment variable
alongside KC_PROXY_HEADERS and KC_HTTP_ENABLED to restrict which proxy IPs
Keycloak will trust; set KC_PROXY_TRUSTED_ADDRESSES to the ingress/proxy CIDR(s)
or comma-separated IPs (e.g., the cluster/load‑balancer subnet) so forwarded
headers cannot be spoofed, and ensure this env var is applied in the same
container spec where KC_PROXY_HEADERS and KC_HTTP_ENABLED are defined.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 12fec9b and 14228aa.

📒 Files selected for processing (1)
  • packages/system/keycloak/templates/sts.yaml

Comment on lines +85 to +88
- name: KC_PROXY_HEADERS
value: "xforwarded"
- name: KC_HTTP_ENABLED
value: "true"
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🌐 Web query:

Keycloak 26 KC_PROXY deprecation migration KC_PROXY_HEADERS

💡 Result:

In Keycloak 26, the old --proxy / KC_PROXY setting is removed (it was deprecated since Keycloak 24). You must migrate to --proxy-headers / KC_PROXY_HEADERS, typically together with hostname (v2) options. [1] [2]

What to change

Before (deprecated/removed):

  • KC_PROXY=edge|reencrypt|passthrough|...

After (supported):

  • KC_PROXY_HEADERS=forwarded (if your proxy sets the standard Forwarded header), or
  • KC_PROXY_HEADERS=xforwarded (if your proxy sets X-Forwarded-* headers). [3] [4]

Keycloak explicitly documents the mapping:

  • CLI: --proxy-headers
  • Env: KC_PROXY_HEADERS
  • Values: forwarded, xforwarded [4]

Typical “edge termination” replacement (TLS ends at the proxy)

If TLS is terminated at the reverse proxy (common “edge” setup), you usually need:

  • KC_PROXY_HEADERS=xforwarded
  • KC_HTTP_ENABLED=true (because proxy → Keycloak is plain HTTP)
  • KC_HOSTNAME=... (often best as a full external URL, e.g. https://auth.example.com, to avoid mixed/incorrect URLs) [3]

Security hardening you should add in 26+

If you enable proxy header parsing, consider restricting which proxy IPs are trusted:

  • CLI: --proxy-trusted-addresses=...
  • Env: KC_PROXY_TRUSTED_ADDRESSES=... [4]

This feature was added alongside the proxy changes and is recommended to avoid trusting spoofed forwarded headers. [1] [2]

Sources: Keycloak 26 release announcement & release notes, and the official Reverse Proxy guide. [1] [2] [3] [4]


🏁 Script executed:

# First, locate and examine the file to understand its context
find . -path "*packages/system/keycloak/templates/sts.yaml" -type f

Repository: cozystack/cozystack

Length of output: 108


🏁 Script executed:

# Examine the file content around the changed lines and broader context
cat -n packages/system/keycloak/templates/sts.yaml | head -150 | tail -80

Repository: cozystack/cozystack

Length of output: 3381


🏁 Script executed:

# Also check if KC_PROXY_TRUSTED_ADDRESSES is configured anywhere in the file
grep -n "KC_PROXY_TRUSTED_ADDRESSES\|PROXY_TRUSTED" packages/system/keycloak/templates/sts.yaml

Repository: cozystack/cozystack

Length of output: 45


🏁 Script executed:

# Verify the file structure - is this a custom template or vendored chart?
ls -la packages/system/keycloak/

Repository: cozystack/cozystack

Length of output: 482


Configuration is correct for Keycloak 26.x, but add proxy trust restrictions for security.

The replacement of KC_PROXY=edge with KC_PROXY_HEADERS=xforwarded and KC_HTTP_ENABLED=true correctly aligns with Keycloak 26.x requirements (KC_PROXY was removed, KC_PROXY_HEADERS is the documented replacement). The configuration correctly enables HTTP when TLS is terminated at the ingress and trusts X-Forwarded-* headers.

Consider adding KC_PROXY_TRUSTED_ADDRESSES to restrict which proxy IPs are trusted and prevent spoofed forwarded headers—this is a recommended security hardening measure in Keycloak 26+ when proxy header parsing is enabled.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/system/keycloak/templates/sts.yaml` around lines 85 - 88, Add the
KC_PROXY_TRUSTED_ADDRESSES environment variable alongside KC_PROXY_HEADERS and
KC_HTTP_ENABLED to restrict which proxy IPs Keycloak will trust; set
KC_PROXY_TRUSTED_ADDRESSES to the ingress/proxy CIDR(s) or comma-separated IPs
(e.g., the cluster/load‑balancer subnet) so forwarded headers cannot be spoofed,
and ensure this env var is applied in the same container spec where
KC_PROXY_HEADERS and KC_HTTP_ENABLED are defined.

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Mar 2, 2026
@kvaps kvaps added the backport Should change be backported on previus release label Mar 2, 2026
@kvaps kvaps merged commit 0a46195 into main Mar 2, 2026
11 of 12 checks passed
@kvaps kvaps deleted the fix/keycloak-proxy-headers branch March 2, 2026 17:29
@github-actions
Copy link

github-actions bot commented Mar 2, 2026

Successfully created backport PR for release-1.0:

kvaps added a commit that referenced this pull request Mar 2, 2026
…v26.x (#2134)

# Description
Backport of #2125 to `release-1.0`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport Should change be backported on previus release bug Something isn't working lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants