Kubernetes Security Architecture

Published
Length
3 min read

Luis Felipe Dias

All posts

You build a strong kubernetes security architecture by setting up strict roles and bindings on the API server. You must limit who can run commands or read logs inside each namespace. Most teams start by granting broad cluster roles so engineers can fix broken apps fast. Over time, these broad roles stay in place and expose sensitive data across every namespace. How native kubernetes security architecture handles roles and rules The native permission system runs on the API server and checks ev

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.

You build a strong kubernetes security architecture by setting up strict roles and bindings on the API server. You must limit who can run commands or read logs inside each namespace. Most teams start by granting broad cluster roles so engineers can fix broken apps fast. Over time, these broad roles stay in place and expose sensitive data across every namespace.

How native kubernetes security architecture handles roles and rules

The native permission system runs on the API server and checks every incoming request. It uses four main objects to control who can do what inside the cluster. A Role sets permissions inside one single namespace. A ClusterRole sets permissions across the whole cluster, including nodes and all namespaces.

All permissions in this system are additive. There are no deny rules at all. You start with zero rights and add rules one by one. To give these rules to a user or a team, you create a binding. A RoleBinding grants permissions inside one namespace. It can point to a Role in that same namespace or a shared ClusterRole. A ClusterRoleBinding grants permissions across every namespace in the entire cluster.

The API server also uses subresources to guard specific actions on pods. In permission rules, a subresource uses a slash after the main resource name. For example, reading pod logs uses a log subresource. Running interactive shell commands inside a container uses an exec subresource. You can separate who can view a pod from who can open a shell inside it.

What native cluster roles solve and what they leave open

Native roles and bindings do a great job of controlling API requests. They let you lock down who can create, delete, or list pods in a namespace. You can give developers read rights in production while keeping write rights for automated tools. You can also restrict shell subresources to a small group of on-call engineers.

Still, native access rules only check the start of a request. Once the API server lets an engineer open a shell on a pod, its job ends. The cluster knows who opened the session, but it does not inspect the commands inside it. An engineer with shell rights can read local files, inspect memory, or view database keys.

Event-Driven Architecture Security + Kubernetes Operator for Security: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

The same gap exists when users read pod logs or query internal data stores through a pod. Native permissions decide who can open the stream, not what data comes back. If an app prints emails, phone numbers, or card numbers to logs, the engineer sees them. Also, because rules are only additive, you cannot write a quick rule to block one bad command. Teams end up choosing between blocking shell access or giving broad control during an outage.

Closing the gap between cluster roles and live commands

To keep production safe, teams need controls that work after the API check passes. You should keep native roles narrow and avoid cluster-wide bindings for daily work. Bind engineers to single namespaces instead of the whole cluster. Separate regular pod viewing rules from exec and log subresources.

Even with tight roles, someone still needs to run live commands to fix broken services. Relying on static roles alone leaves a gap during those live debugging sessions. You need a way to check individual commands and rewrite sensitive fields like national IDs in results.

Add request guardrails and response masking beside Kubernetes

Cluster roles and service accounts govern who reaches the Kubernetes API. Still, a broad role or agent can delete workloads or print sensitive values from ConfigMaps and logs. In practice, hoop.dev sits inline beside the API server as a sidecar for your Kubernetes API. For every production API call an agent or human sends, hoop.dev decides whether to pass, mask, block, or escalate it for review alongside RBAC.

With hoop.dev Kubernetes controls, guardrails allow listing Secret names while refusing reads of Secret data before execution, and data masking redacts matched keys in returned JSON responses and log streams in memory. Furthermore, hoop.dev holds SOC 2 Type II and is MIT licensed on GitHub.

Frequently asked questions

Can I write a deny rule in native Kubernetes RBAC?

No, native permissions are purely additive. You must start with no access and grant only the specific rules each user needs.

What is the difference between a RoleBinding and a ClusterRoleBinding?

A RoleBinding grants permissions inside one specific namespace. A ClusterRoleBinding grants permissions across all namespaces and cluster-wide resources like nodes.

How do I stop users from running shell commands in pods?

Remove the exec subresource for pods from their assigned Role or ClusterRole. They can still view pod status without opening a shell.

The query runs. The emails stay hidden.