Kubernetes Firewall Rules
You set up kubernetes firewall rules by filtering network traffic to nodes and pods. You also pair those network blocks with role rules on the API server. Teams often start by locking down ports between external networks and cluster nodes. Then they use built-in role checks to decide which engineers can run commands. When teams grant broad cluster roles to move fast, one mistake can break production. How kubernetes firewall rules and API roles work Cluster traffic moves through two main paths
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 firewall rules by filtering network traffic to nodes and pods. You also pair those network blocks with role rules on the API server. Teams often start by locking down ports between external networks and cluster nodes. Then they use built-in role checks to decide which engineers can run commands. When teams grant broad cluster roles to move fast, one mistake can break production.
How kubernetes firewall rules and API roles work
Cluster traffic moves through two main paths. The first path is network packets flowing between pods, nodes, and outside clients. Host firewalls and cluster network policies block or allow traffic by port and IP. They stop unknown machines from reaching the API server or app ports.
The second path is the control plane API. Engineers send requests to the API server to read logs or run commands. Network rules alone cannot tell a safe command from a dangerous one. Once an engineer can reach the API port, role rules take over.
In the native setup, a Role sets permissions inside one single namespace. A ClusterRole sets permissions across the whole cluster and covers cluster-scoped items like nodes. A ClusterRole can also cover resources across all namespaces at once. Permissions in this system only add access. There are no deny rules in native role sets.
To give those permissions to a user, you create a binding. A RoleBinding grants access inside one namespace. It can point to a Role in that namespace or a shared ClusterRole. A ClusterRoleBinding grants those permissions across the entire cluster.
The API also uses subresources for actions like reading pod logs or running shell commands. Role rules name the main resource and the subresource together to allow these tasks.
Where network blocks and role bindings fall short
Network blocks and API roles solve the first layer of cluster security. Host firewalls keep outsiders off your node ports. Role bindings make sure only approved engineers can start a shell session in a pod. Together, they decide who can reach the cluster and which API endpoints they can call.
Kubernetes RBAC + AWS Config Rules: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Still, this native setup leaves a big gap during live work. Role rules are purely additive and stop checking once the API call starts. When you grant an engineer access to the pod exec subresource, they get a shell. The API server checks if the user can open that shell. It does not check what commands the engineer types inside the container afterward.
Network rules also cannot help here. The engineer is already inside the allowed network path to the API server. Inside that pod shell, a user can read local files or dump app data. They might query an internal database from the pod and pull raw customer records. If the pod has broad network reach, the user inherits that same reach.
Teams also struggle to keep role bindings tight over time. Because there are no deny rules, you cannot easily block one risky action inside a broad role. Teams end up creating dozens of small roles or giving out wide ClusterRoleBindings during an outage. Those wide bindings often stay in place long after the fix is done.
Why command-level control matters for cluster safety
Relying only on port blocks and static roles forces a bad trade-off. If you lock down the exec subresource completely, engineers cannot fix broken apps fast. If you grant exec access across a namespace, you lose control over live shell commands. You also miss out on masking sensitive fields like emails, phone numbers, or card numbers in output.
Securing a cluster requires looking past the initial port check and role binding. Teams need a way to inspect individual commands and queries while they run. They also need a way to require quick peer approval before a risky shell session starts.
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
Do network firewall rules block kubectl exec commands?
Network rules only block traffic if the user cannot reach the API server port. If the user can reach the API server, role rules decide if exec is allowed.
Can I write a deny rule in native Kubernetes RBAC?
No, permissions in native Roles and ClusterRoles are purely additive. You must start with zero permissions and only bind the exact rules a 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-scoped resources like nodes.
Related guides
In this post