Keycloak OIDC Provider

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a keycloak oidc provider by creating a realm and registering your client app. Then you map user roles and group claims to issue signed identity tokens. Most engineering teams use this flow to centralize login across internal tools and databases. Still, teams often map broad group roles that give users too much power after login. How a keycloak oidc provider works in your stack Keycloak acts as a central identity server that speaks the OpenID Connect protocol. First, you create a de

Keycloak + K8s OIDC Authentication: the complete guide

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

Free white paper. No spam. Unsubscribe anytime.

You set up a keycloak oidc provider by creating a realm and registering your client app. Then you map user roles and group claims to issue signed identity tokens. Most engineering teams use this flow to centralize login across internal tools and databases. Still, teams often map broad group roles that give users too much power after login.

How a keycloak oidc provider works in your stack

Keycloak acts as a central identity server that speaks the OpenID Connect protocol. First, you create a dedicated realm to hold your users, groups, and login rules. A realm keeps one team or project separate from other parts of your company. Inside that realm, you register each internal app or database tool as a client.

When a user tries to log in, the app redirects them to your identity server. The server checks the user password and any second factor like a phone code. After a good check, the server issues an authorization code back to the app. The app trades this code for an identity token and an access token.

These tokens are JSON files signed with a private key from your realm. The app reads the public key from a discovery URL to check the signature. Inside the token, mappers place user details like email, group names, and assigned roles. Your downstream tools read these claims to decide which screens or systems the user can open.

Why role mapping gets messy at scale

At first, mapping a few identity groups to app roles feels clean and simple. You might create a developer group and a support group inside your realm. Then you pass those group names straight into the token claims for your tools. Each tool reads the claim and grants a matching local role to the user.

Problems start when different teams need temporary or narrow rights for specific tasks. To fix a production bug, an engineer might need write rights for one hour. In a basic setup, admins add that person to a high-power group in the realm. People forget to remove the user later, so the broad role stays active for months.

Soon, your realm holds dozens of custom roles built for one-off requests. Admins struggle to track which token claim maps to which database or server permission. When an auditor asks who can delete production data, you must check many places. You have to inspect both the identity server groups and the local tool roles.

Keycloak + K8s OIDC Authentication: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native identity setup solves and what it misses

A central identity server solves the problem of scattered passwords and manual user accounts. When someone leaves the team, you disable one profile to block new logins everywhere. You also get one place to enforce strong passwords and multi-factor login rules. This stops attackers from using stolen passwords to enter your network.

Still, OpenID Connect only handles the front door when a session starts. Once the token is checked and the session opens, the identity server steps back. It cannot see which SQL queries or shell commands the user runs next. A valid token gives the user full freedom inside the bounds of their assigned role.

This leaves a big gap during live work on production databases and servers. An engineer with a valid token can still run a bad query that drops a table. They can also pull thousands of customer emails or card numbers in one select statement. Data masking is needed to rewrite matched fields like phone numbers or national IDs in results. Native login tools also cannot ask a peer to approve a single risky command in flight.

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

What is the difference between a realm and a client in Keycloak?

A realm is a top-level space that holds a set of users, roles, and groups. A client is a single app or service that asks the realm to log users in.

How do downstream tools check tokens from a keycloak oidc provider?

Downstream tools fetch public keys from the realm discovery endpoint over HTTPS. They use these keys to check the token signature and read the expiration time.

Can OpenID Connect restrict which SQL queries a user runs after login?

No, OpenID Connect only checks identity and passes role claims at login time. It does not inspect or filter database queries or shell commands during an active session.

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.