How to Configure Keycloak Proxy Configuration

Published
Length
3 min read

Luis Felipe Dias

All posts

A keycloak proxy configuration controls how your identity server reads client network traffic behind a load balancer. You set it up safely by choosing the right forwarding mode and trusting only known network addresses. Teams often run their identity servers inside private networks to keep them safe from direct web attacks. A reverse load balancer sits in front to take incoming public requests and pass them inside. Without the right setup, the identity server only sees the internal network addr

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

A keycloak proxy configuration controls how your identity server reads client network traffic behind a load balancer. You set it up safely by choosing the right forwarding mode and trusting only known network addresses.

Teams often run their identity servers inside private networks to keep them safe from direct web attacks. A reverse load balancer sits in front to take incoming public requests and pass them inside. Without the right setup, the identity server only sees the internal network address of the load balancer. This causes login redirects to fail and breaks IP-based security rules.

How keycloak proxy configuration works in practice

When a user logs in, their browser talks to the public load balancer over an encrypted link. The load balancer adds special headers to the request before sending it to the identity server. These headers carry the original client IP address, the public host name, and the web protocol used.

Your keycloak proxy configuration tells the identity server how to read and trust these incoming headers. This setup affects every human user, service account, and web app that asks for a login token. If the server ignores these headers, it builds redirect links using its own private address. Users then see broken links in their browsers because they cannot reach the private network directly.

You can choose between a few main TLS modes when you set up the server. In edge mode, the load balancer ends the encrypted link and sends plain traffic to the server. In re-encrypt mode, the load balancer ends the public link and starts a new encrypted link inside. In passthrough mode, the load balancer sends encrypted traffic straight to the server without reading it.

For safe defaults, teams should always set strict hostname rules alongside their forwarding mode. You must also restrict network paths so only the load balancer can send traffic to the server. If any machine can send fake headers directly to the server, attackers can spoof their IP address. Locking down the private network stops attackers from bypassing IP blocklists or falsifying login logs.

Checking your setup and closing session gaps

After you set up the server, you should check the well-known discovery page from a public browser. Every link on that page must show your public web address and use HTTPS. Next, perform a test login and check the server audit logs right away. The event log must show your real public IP address instead of the load balancer IP address.

Keycloak + Database Proxy (ProxySQL, PgBouncer): architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

If the log shows the internal IP, the server is not reading the forwarded headers properly. You should also test what happens when an app asks for a token refresh. Make sure the token issuer field matches the public domain name in every case.

Setting up your identity server behind a load balancer fixes web login flows and cleans up login logs. Still, static identity settings only check who a user is at the moment they log in. Once a developer or app gets a valid token, the identity server steps out of the way. It cannot see what queries an engineer runs on a database during an active session.

Identity servers also cannot stop an approved user from running a bad command on a live server. They do not mask sensitive fields like emails, phone numbers, card numbers, or national IDs in query results. To protect production data, teams need runtime controls that inspect every action after the initial login.

Govern statements and responses across databases and APIs

Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev runs beside each supported service as an open-source proxy, a sidecar for your database or API.

First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.

Frequently asked questions

Why do login redirects switch to HTTP instead of HTTPS?

This happens when the load balancer ends the TLS link and sends plain traffic to the server. You must set the server to read forwarded protocol headers so it builds HTTPS links.

Why do all login events show the same internal IP address?

The identity server is recording the network address of your load balancer instead of the real user. Ensure your load balancer sends forwarding headers and tell the identity server to trust them.

Which TLS mode is safest for production networks?

Re-encrypt mode or passthrough mode is safest when your internal network is shared with other workloads. Edge mode is fine only if the private link between the load balancer and server is isolated.

The query runs. The emails stay hidden.