Keycloak Architecture Diagram

Published
Length
3 min read

Luis Felipe Dias

All posts

You map a keycloak architecture diagram by placing the identity server between users and apps. The server checks user logins, reads directory stores, and sends signed tokens to apps. Teams often set up one central realm to handle logins for every internal tool. This setup makes user login easy across the whole company. Still, broad roles often give users full control over sensitive databases and servers. Once a user logs in, the identity server stops watching their active session. Core compone

Keycloak + Zero Trust Architecture: the complete guide

Architecture patterns, implementation strategies, and security best practices. Delivered to your inbox.

Free white paper. No spam. Unsubscribe anytime.

You map a keycloak architecture diagram by placing the identity server between users and apps. The server checks user logins, reads directory stores, and sends signed tokens to apps. Teams often set up one central realm to handle logins for every internal tool. This setup makes user login easy across the whole company. Still, broad roles often give users full control over sensitive databases and servers. Once a user logs in, the identity server stops watching their active session.

Core components of a keycloak architecture diagram

A clear keycloak architecture diagram starts with realms at the top level. A realm holds a distinct group of users, login rules, and role maps. Each realm stays isolated from other realms on the same identity server. Inside a realm, you define clients for every web app or backend service. Clients represent the tools that ask the identity server to check a user.

When a user tries to log in, the app redirects them to Keycloak. The server checks the user against its own database or an external directory. Many teams link their realm to an existing corporate directory for user sync. You can also set up identity brokering to trust external login providers. After a valid check, the server builds a signed token using standard protocols. Most modern setups use OpenID Connect or SAML to pass these identity tokens.

The signed token holds user claims, group memberships, and role names. The user sends this token back to the target app with each request. For high availability, teams run multiple server nodes behind a load balancer. These nodes share login sessions through a distributed cache layer and one shared database. If one node fails, another node keeps active user sessions alive without issues.

How login flows and role mappings work in practice

Role mappings decide what a user can do after they log into an app. Keycloak lets admins create both realm roles and client roles for teams. Realm roles apply across every app inside that specific realm. Client roles belong to one single app and control actions inside that tool. Admins also group roles together into composite roles to make setup faster.

During login, the server reads the user groups and attaches matching roles. Protocol mappers then write those roles into the user token as text claims. When a web app receives the token, it checks the signature first. Next, the app reads the role claims to open or block specific screens. This flow works well for web apps built to read standard tokens.

Backend databases and command-line servers handle this flow in a different way. Many legacy databases cannot read web tokens out of the box. Teams often map broad identity groups to shared database admin accounts instead. A developer logs in with their single sign-on account and gets a database role. That database role stays active until the token expires or the user disconnects.

Keycloak + Zero Trust Architecture: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Where identity architecture stops and runtime gaps begin

An identity server handles the front door for your apps and internal tools. Your architecture proves who a person is before they start a session. It also passes their group names to the target system at login time. That setup removes shared passwords and centralizes user removal when someone leaves.

Still, the identity server steps out of the way after login finishes. It does not inspect what happens inside the session while the user works. A user with a valid token can run destructive commands or drop tables. They can also query large tables full of customer emails and card numbers. The identity server never sees those queries or commands in flight.

Static role mappings also create risk when developers need temporary production fixes. Admins often grant permanent write roles because revoking them later takes manual work. Over time, too many engineers hold high-level roles across critical production systems. Relying only on login tokens leaves a gap between login checks and runtime safety. Teams need controls that inspect individual commands and rewrite sensitive fields like phone numbers.

Check database and API queries on the wire

Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.

Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.

Frequently asked questions

What belongs in a production keycloak architecture diagram?

A production diagram shows users, a load balancer, server nodes, and a shared database. It also maps external user directories, target client apps, and the distributed session cache.

How does Keycloak share sessions across multiple server nodes?

Server nodes use a built-in distributed cache to sync active login sessions and tokens. When a load balancer routes a user to a new node, the session continues.

Can Keycloak control individual database queries after login?

No, Keycloak only handles user login and passes role claims inside identity tokens. Once a database session starts, the identity server cannot inspect or block individual queries.

Save the open-source gateway.

hoop is MIT-licensed infrastructure for controlling how AI agents reach production data. Star hoophq/hoop so you can inspect it, deploy it, or share it when your team starts governing agent access.