Keycloak Get Public Key

Published
Length
3 min read

Luis Felipe Dias

All posts

To complete a keycloak get public key task, fetch the key from the realm endpoint. You can also copy the active key text right from the admin panel. Teams use this public key so apps can check signed login tokens. Most setups pull the key list at startup and cache it in memory. Yet a valid token often grants broad database or server roles to users. How the keycloak get public key process works Keycloak signs every user token with a private key owned by the realm. Your backend apps need the ma

Keycloak + Public Key Infrastructure (PKI): the complete guide

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

Free white paper. No spam. Unsubscribe anytime.

To complete a keycloak get public key task, fetch the key from the realm endpoint. You can also copy the active key text right from the admin panel. Teams use this public key so apps can check signed login tokens. Most setups pull the key list at startup and cache it in memory. Yet a valid token often grants broad database or server roles to users.

How the keycloak get public key process works

Keycloak signs every user token with a private key owned by the realm. Your backend apps need the matching public key to check that signature. Apps can read this key from the standard discovery endpoint over the network. The server shares the active keys in a standard JSON web key format. Each key in that list has a unique ID tag attached to it. When an app gets a token, it reads the token header first. It matches the header ID tag to the right key from the list. Then the app checks the math on the token signature by itself. This local check is fast because the app does not call the server. Admins can also view and copy the raw key inside the realm settings. Manual copy tasks work well for quick tests or static app setups. Automated apps prefer the live endpoint because it handles key rotation well.

How key rotation affects your apps

Security teams rotate realm keys on a set schedule to limit risk. If someone steals an old key, rotation stops them from making fake tokens. During rotation, the server makes a new key pair for future user logins. It keeps the old public key on the list for a short time. This grace period lets active user tokens stay valid until they expire. Apps that hardcode a copied key string will break when rotation happens. Every login check will fail until an engineer updates the saved key text. Apps that poll the discovery endpoint pick up the new key without downtime. They see the new key ID tag and refresh their local cache right away. Teams must test this refresh flow before they put apps into production.

What token checks solve and what they miss

Checking a token with a public key proves who the user is. It confirms that the login server issued the token and nobody changed it. This step stops outside attackers from sending fake requests to your internal apps. Still, a valid token only answers the question of who logged in. It does not control what the user or app does after that check. When an engineer connects to a database, the token check ends at login. Once inside, the user can run broad queries or drop whole tables. A standard token check cannot inspect live database queries or shell commands. It cannot rewrite sensitive fields like emails, phone numbers, or card numbers. Teams still face huge risks if a valid user runs a bad command. You need controls that watch and filter each action during the active session.

Keycloak + Public Key Infrastructure (PKI): architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

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

Where do I find the public key in the admin console?

Open your realm settings and go to the keys tab to see active keys. You can view the public key string next to the active signing key row.

Should my app hardcode the realm public key or fetch it?

Your app should fetch the key list from the realm discovery endpoint. Fetching the list lets your app handle key rotation without manual code updates.

Does a public key check protect my database from bad queries?

No, the public key only checks that the user login token is real. It does not inspect or block queries after the database session starts.

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.