The Simplest Way to Make Keycloak and Pulumi Work Like They Should
Keycloak and Pulumi work together by turning identity settings into versioned code. Teams use Pulumi to build and update Keycloak realms, clients, and user roles. Manual clicks in an identity portal often cause human mistakes. One wrong click can break user logins across your whole stack. Writing these rules as code stops drift between test and live setups. Your team can review every identity change in a pull request first. This workflow makes audits fast and keeps every login rule clear. How
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.
Keycloak and Pulumi work together by turning identity settings into versioned code. Teams use Pulumi to build and update Keycloak realms, clients, and user roles.
Manual clicks in an identity portal often cause human mistakes. One wrong click can break user logins across your whole stack. Writing these rules as code stops drift between test and live setups. Your team can review every identity change in a pull request first. This workflow makes audits fast and keeps every login rule clear.
How keycloak and pulumi pass identity and state
To link keycloak and pulumi, the build tool must log in first. You create a dedicated service client inside the admin realm for this job. Pulumi reads the client secret and requests a token from the server. It then sends API calls to read, create, or change realm items.
The tool stores the current state of your realms in a state file. Each time a pipeline runs, it checks the live server against your code. If someone changed a role by hand, the next run fixes that drift. Data flows one way from your git repo to the identity server. You can also pass new client IDs straight into your app stacks.
This link lets app code and login rules ship at the same time. When a new app goes live, its login client is ready to use. Engineers do not wait on tickets for manual portal setup. The whole flow stays in version control from start to finish.
Common failure modes with shared keys and broad roles
Many teams make the mistake of using one master admin account everywhere. They put a root password or broad key into their build server. If that key leaks, an attacker can take over every single realm. Shared service accounts also ruin your audit logs during an incident. You can see a change happened, but you cannot see who ran it.
Another common issue occurs when engineers run updates from their own laptops. This requires giving local machines network paths to the admin API. Broad network paths expose the identity server to too much risk. Unlogged API queries from local laptops also leave big gaps in your records.
Keycloak + Pulumi Policy as Code: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
To fix this, scope down the roles for each build pipeline. Give a project client permissions for its own target realm only. Never grant master realm admin rights to a standard app pipeline. Keep the admin endpoint on a private network away from public traffic. Rotate client secrets often and remove static keys from local laptops.
Keeping state files and secrets safe in production
State files hold sensitive details about your realms and client secrets. If you store state in plain text, anyone with repo read rights sees those secrets. Always turn on encryption for your state backend before your first run. Mark all client secrets and private keys as secret values in your code. This ensures the tool scrambles them inside the state file and build logs.
Separate your identity code into small stacks based on risk and team ownership. Put core realm settings in one base stack owned by the security team. Put app clients in separate stacks owned by the product teams. This split limits the blast radius if a bad change ships to production. A mistake in one app stack will not break the base realm.
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
How should Pulumi log in to Keycloak during a build?
Use a dedicated service client with the client credentials flow for builds. Grant this client only the exact realm roles needed for its stack.
What happens if someone changes a Keycloak role in the UI?
The next code run will detect the difference between the server and state. It will overwrite the manual UI change to match your git repo.
How do we keep client secrets out of plain text state files?
Mark every password and client secret as a secret output in your code. Use an encrypted state backend so all stored values stay locked at rest.
Related guides
In this post