Kubernetes Security Features

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up kubernetes security features by defining roles and binding them to users. These native rules control who can read, write, or run commands on cluster resources. Many teams start by giving developers broad roles to speed up daily work. When roles are too broad, one bad command can break production pods or expose data. How native kubernetes security features work Role-based control is the core way a cluster checks user requests. The API server checks every request against a set of rul

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 set up kubernetes security features by defining roles and binding them to users. These native rules control who can read, write, or run commands on cluster resources. Many teams start by giving developers broad roles to speed up daily work. When roles are too broad, one bad command can break production pods or expose data.

How native kubernetes security features work

Role-based control is the core way a cluster checks user requests. The API server checks every request against a set of rules before it runs. In this system, all rules are additive. There are no deny rules in native role sets. You start with zero rights and add rules for each action you need.

Kubernetes splits roles into two main levels. A standard Role sets rules inside one single namespace. A ClusterRole sets rules across the whole cluster. A ClusterRole can control cluster-wide objects like nodes or rules across all namespaces. It can also control endpoints that are not tied to a specific resource.

Once you write a role, you must attach it to a user or team. A RoleBinding gives those rights inside one specific namespace. You can point a RoleBinding to a Role in that same namespace. You can also point a RoleBinding to a global ClusterRole to reuse common rules. This keeps your rule definitions dry while keeping permissions locked to one namespace. A ClusterRoleBinding gives rights across the entire cluster at once.

Controlling subresources and pod actions

Role rules match the exact resource names used in the API path. Some API calls target a subresource inside a main object. For example, reading pod logs or running a shell uses a subresource path. You write these in your rules by joining the main object and subresource with a slash.

Admins often separate read rights on pods from log or shell rights. A user might have rights to list pods in a namespace. That user still needs a separate rule for the log subresource to read app output. They also need a specific rule for the exec subresource to open a shell inside a container.

When you grant create rights on a subresource, name filters have limits. You cannot use resource name filters on create calls for subresources. Instead, you apply the name filter to the main object rule if the verb allows it. Careful admins split these subresource rules into separate roles so teams only get what they need.

Linkerd Security Features + Kubernetes Operator for Security: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native roles solve and what they miss

Native cluster roles are great at deciding who can reach an API endpoint. They stop unauthorized users from deleting deployments or reading secret objects in other namespaces. They give platform teams a clear way to divide a cluster between different product groups.

Still, native roles stop checking once the API call begins. If a role lets an engineer run a shell inside a pod, the check ends there. The cluster knows the user started an exec call, but it does not inspect the shell commands inside. An engineer with shell rights can run any tool installed in that container. They can query local databases, read files on disk, or pull raw card numbers and emails from memory.

The same gap happens with port forwarding and log reading. Native rules only check if the user can open the stream. They do not filter what flows back through that stream. If an app prints phone numbers or national IDs to standard output, anyone with log rights sees them. To close this gap, teams need controls that inspect commands and mask data in flight.

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

Can I write a deny rule in Kubernetes RBAC?

No, native Kubernetes role rules are strictly additive. You cannot write a rule that blocks a specific action from a broader role. To remove a right, you must remove the binding or edit the role itself.

What is the difference between a RoleBinding and a ClusterRoleBinding?

A RoleBinding applies permissions inside one single namespace. A ClusterRoleBinding applies permissions across all namespaces and cluster-wide nodes. You can use a RoleBinding with a ClusterRole to limit global rule templates to one namespace.

Does pod read permission allow a user to run a shell in a container?

No, basic read rights on a pod object only return the pod status and spec. Opening a shell requires explicit permission on the pod exec subresource. Reading container output also requires permission on the pod log subresource.

The query runs. The emails stay hidden.