Container and Kubernetes Security

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up container and kubernetes security by defining strict role rules and namespace bindings. Then you limit who can run commands inside live pods and read logs. Most teams start by giving developers broad cluster roles to speed up work. When roles are too wide, one bad command can break workloads across every namespace. Overbroad permissions also let users read sensitive data from every running pod. How native container and kubernetes security works Kubernetes manages permissions throug

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 container and kubernetes security by defining strict role rules and namespace bindings. Then you limit who can run commands inside live pods and read logs. Most teams start by giving developers broad cluster roles to speed up work. When roles are too wide, one bad command can break workloads across every namespace. Overbroad permissions also let users read sensitive data from every running pod.

How native container and kubernetes security works

Kubernetes manages permissions through role objects that hold sets of rules. These rules are only additive, which means there are no deny rules. You start with zero access and add rules for each needed action. A basic role sets permissions inside one single namespace. A cluster role is not tied to a single namespace. It can cover cluster-wide resources like nodes or resources across all namespaces.

To give these permissions to a user, you create a binding object. A role binding grants permissions inside one specific namespace. That role binding can point to a basic role in that same namespace. It can also point to a global cluster role while keeping access inside one namespace. A cluster role binding grants access across the entire cluster at once. You enable this authorization mode directly on the API server.

Rules also control subresources, which appear with a slash in the API URL. For example, reading pod logs or running commands inside a pod uses subresources. You must grant permission for the pod log subresource or the pod exec subresource. If you restrict rules by specific resource names, know how creation rules work. Name limits on create actions apply only to top-level resources, not to subresources.

Where native cluster roles fall short

Native role bindings do a great job of deciding who can enter a namespace. They check if a user can open a shell session on a pod. They also verify if a team member can request pod log files. Still, native permissions stop checking once the session starts.

Once a user gets pod exec access, the cluster cannot filter individual shell commands. Any user with exec access can run destructive commands inside that container. They can also read raw database keys or customer emails and card numbers from memory. Pod log permissions have a similar blind spot during daily work. When an app prints phone numbers or national IDs to logs, anyone can read them. Native roles decide who connects to the API, not what commands or data flow inside.

Container Runtime Security + Kubernetes Operator for Security: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Steps to tighten pod and namespace permissions

First, remove cluster-wide bindings from human users and daily developer groups. Give each team a role binding that applies only to their specific app namespace. You can reuse a single cluster role across namespaces by attaching it with role bindings. This keeps your rule definitions clean while limiting where each team can work.

Second, separate read permissions from action permissions on pod subresources. Allow developers to read the pod log subresource for daily debugging work. Hold back permission for the pod exec subresource until an urgent fix is needed. Since rules are only additive, keeping exec out of base roles prevents accidental shell access. Review your bindings often to make sure old roles do not pile up.

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 Kubernetes RBAC?

No, permissions in Kubernetes RBAC are purely additive and never support deny rules. You must start with no permissions and grant only the exact access each user needs.

What is the difference between a role binding and a cluster role binding?

A role binding grants access inside one specific namespace. A cluster role binding grants access across all namespaces and cluster-scoped resources like nodes.

How do I control access to pod logs and container shells?

You write rules that target the specific subresource name with a slash. Use the pod log subresource for reading logs and the pod exec subresource for shells.

The query runs. The emails stay hidden.