Keycloak User Login
You set up a keycloak user login by creating a realm, registering a client, and adding user accounts. The service then checks user passwords and sends signed tokens back to your app. Most teams link this flow to their central directory so staff use one password everywhere. Still, broad roles in those tokens often give users too much power inside backend systems. How the keycloak user login flow works Keycloak groups all your users, roles, and apps inside a single space called a realm. Each re
Keycloak + User Provisioning (SCIM): the complete guide
Architecture patterns, implementation strategies, and security best practices. Delivered to your inbox.
You set up a keycloak user login by creating a realm, registering a client, and adding user accounts. The service then checks user passwords and sends signed tokens back to your app. Most teams link this flow to their central directory so staff use one password everywhere. Still, broad roles in those tokens often give users too much power inside backend systems.
How the keycloak user login flow works
Keycloak groups all your users, roles, and apps inside a single space called a realm. Each realm acts as an isolated boundary with its own login rules and signing keys. When you add an app as a client, you tell the realm where to send users after they sign in. You also pick a standard protocol like OpenID Connect or SAML to carry the user details.
When a person visits your app, the app sends their browser over to the realm sign-in page. The user types in their username, password, and a second factor code if required. The identity server checks these details against its local database or an external company directory. If the check passes, the server builds a signed token that lists the user identity and assigned roles.
The browser then carries an authorization code back to the app, which trades it for the token. Your app reads the token claims to learn who the person is and what role they hold. This step lets teams manage passwords and multi-factor rules in one central place. Admins can also revoke a session in the realm when a worker leaves the team.
Where native identity tokens stop
A central sign-in flow is great at proving who a person is before they enter a web app. It stops bad logins at the front door and enforces strong password rules across the company. Yet the job of the identity provider ends the moment the app accepts the login token. It does not watch or control what the user does inside databases, servers, or cloud tools after sign-in.
Engineering teams still need to run SQL queries on Postgres or run shell commands on Linux hosts. In many setups, passing the SSO check just hands the engineer a shared database role or a static key. Once inside, that role can run any query, drop tables, or read tables full of sensitive user records. The identity server has no idea which SQL statements or terminal commands the person runs next.
Keycloak + User Provisioning (SCIM): architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Because roles are coarse, admins often grant wide write permissions so developers can fix live bugs fast. Those wide permissions stay active all day and expose raw emails, phone numbers, and card numbers in query results. Audit logs in the identity server only show that a login happened at a certain time. They do not record the actual commands ran or mask private fields returned by a database.
Adding runtime controls after login
To close this gap, teams pair their realm login with runtime checks at the database and command level. Instead of mapping an SSO group to a wide database account, you check every action as it runs. A developer still signs in through the same realm flow they use every day. Their identity then attaches to each individual query or command they send to a target system.
With runtime controls in place, you can require a quick peer approval before a risky command runs. You can also apply data masking that rewrites emails, phone numbers, or national IDs in query results. Every query and command links back to the exact person who signed in through the realm. This setup keeps the simple single sign-on experience while protecting data during live sessions.
Add runtime guardrails and masking beside your databases and APIs
Login rules, role grants, and CI checks govern who connects to your stack. Yet any allowed script, engineer, or AI agent still runs commands with the full scope of its role. For workloads on Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes, SSH, or internal HTTP services, hoop.dev sits beside the service as an open-source proxy, a sidecar for your database or API.
Before a query runs, hoop.dev guardrails check the statement against your rules. An AI Analyzer you configure can score intent or hold risky calls for human review. Next, hoop.dev data masking rewrites sensitive fields in responses, and each verdict is logged per listener. Explore the MIT-licensed project on GitHub.
Frequently asked questions
How do I link a keycloak user login to a company directory?
You can link a realm to an external LDAP or Active Directory server using the user federation settings. You can also connect another identity provider over OpenID Connect or SAML so users sign in with existing accounts.
What is the difference between realm roles and client roles?
Realm roles apply across every app inside that realm and work well for broad team groups. Client roles belong to one specific app and help you manage permissions that only matter inside that single tool.
Does Keycloak log the database queries a user runs after signing in?
No, the identity server only logs sign-in events, token refreshes, and admin changes inside the realm. To log SQL queries or shell commands, you need a system that inspects traffic at the database or server level.
Related guides
In this post