Keycloak Deployment on Kubernetes
A keycloak deployment on kubernetes runs an identity app inside a dedicated cluster namespace. You set up a database, create cluster roles, and expose the service to users. Most teams start by granting broad admin roles to get the pods running fast. Overly broad roles let any user read secrets or run commands inside identity pods. Planning a keycloak deployment on kubernetes Your identity app needs a clean namespace and strict role rules from day one. Kubernetes role-based access control uses
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.
A keycloak deployment on kubernetes runs an identity app inside a dedicated cluster namespace. You set up a database, create cluster roles, and expose the service to users. Most teams start by granting broad admin roles to get the pods running fast. Overly broad roles let any user read secrets or run commands inside identity pods.
Planning a keycloak deployment on kubernetes
Your identity app needs a clean namespace and strict role rules from day one. Kubernetes role-based access control uses roles and bindings to manage who touches cluster objects. In Kubernetes, permissions are purely additive, meaning there are no deny rules at all. A Role sets permissions inside one single namespace for your identity pods and secrets. A ClusterRole covers the whole cluster, including nodes and resources across all namespaces.
To keep your setup safe, use a Role inside the dedicated identity namespace. Then link that Role to specific team members using a RoleBinding in that namespace. Do not use a ClusterRoleBinding for routine app work, as it grants access cluster-wide. Your identity pods also need a backing store to save realms, users, and client rules. You store the database login keys inside Kubernetes secrets within the same namespace. Only the identity pod service account and key admins should read those secret objects.
How native cluster permissions work in practice
Kubernetes checks every API request against the rules defined in your active role bindings. It refers to objects by the exact same name that appears in the API URL. Some API calls use a subresource, such as reading pod logs or running pod commands. In role rules, you write a subresource with a slash, like the pod log path.
During setup or outages, engineers often ask for permission to run commands inside pods. They also ask to read pod logs to check startup errors or database links. If you grant broad subresource rules, engineers can open a shell inside the identity container. Once inside the container, a user can read memory, dump keys, or change app files. Native role bindings only check if a user can start that pod shell session.
Keycloak + Kubernetes RBAC: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
What native roles solve and what they leave open
Native cluster roles do a great job of blocking strangers from touching your namespace. They let you separate cluster node admins from the engineers who manage the identity app. You can give an engineer read access to pod status while hiding other namespaces. This basic setup solves who can talk to the cluster API server and start sessions.
Still, native role rules stop working once a shell session or database link begins. The cluster checks who logs in, not what individual commands or queries do in flight. If an engineer opens a pod shell, the cluster API does not inspect their commands. If an admin queries the backing database, native roles do not mask sensitive fields. A query result can return raw emails, phone numbers, card numbers, or national IDs. Teams need a way to approve individual commands and rewrite sensitive fields in results.
Check Kubernetes API requests and responses on the wire
Kubernetes RBAC decides who may call the API server. RBAC does not check response payloads or split listing Secret names from reading Secret values when a role grants get access. With hoop.dev, you run an open-source HTTP proxy, a sidecar for your Kubernetes API. The kubectl client changes only the server address it talks to while RBAC stays in place.
On each call, hoop.dev guardrails read the method, normalized path, and headers to refuse bad deletes or full Secret reads with a 403 error. On the way back, hoop.dev data masking walks JSON responses by key and masks matched values in Secrets, ConfigMaps, and pod logs. Every request and verdict is logged without storing bearer tokens. View the project on GitHub.
Frequently asked questions
Should I use a Role or a ClusterRole for my identity namespace?
Use a Role paired with a RoleBinding for your identity app namespace. A Role keeps permissions inside that single namespace, while a ClusterRoleBinding grants access cluster-wide.
Can I write a deny rule in Kubernetes RBAC to block secret access?
No, Kubernetes permissions are purely additive and there are no deny rules. To block access to secrets, remove the secret read rule from the user role.
Why is granting pod exec access risky for an identity service?
Pod exec access lets a user run any command inside the running identity container. Native roles cannot check individual commands inside that shell or mask data in results.
Related guides
In this post