Kubernetes Integration Test
A kubernetes integration test runs your app against real cluster services to check how parts work together. You set this up by deploying test pods into an isolated namespace with scoped permissions. Many teams grant broad cluster roles to their test runners so tests pass fast. When permissions are too wide, a test script or engineer can touch live workloads by mistake. How a native kubernetes integration test works To run tests inside a cluster, your test runner needs an identity and a role.
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 kubernetes integration test runs your app against real cluster services to check how parts work together. You set this up by deploying test pods into an isolated namespace with scoped permissions. Many teams grant broad cluster roles to their test runners so tests pass fast. When permissions are too wide, a test script or engineer can touch live workloads by mistake.
How a native kubernetes integration test works
To run tests inside a cluster, your test runner needs an identity and a role. Kubernetes uses Role-Based Access Control on the API server to manage these permissions. In this system, permissions are additive, and there are no deny rules.
A Role sets rules within a single namespace. A ClusterRole covers cluster-wide resources like nodes, or resources across all namespaces. You connect a runner to these rules using a RoleBinding or a ClusterRoleBinding. A RoleBinding grants permissions inside one namespace, even when it points to a ClusterRole. A ClusterRoleBinding grants permissions across the whole cluster.
During a test run, the runner deploys apps, reads pod status, and checks service outputs. It also interacts with subresources, which match the names in the API URL. For example, reading pod logs or running commands inside a pod uses subresources. You must grant permissions for both the main resource and the specific subresource. If you restrict access by resource name, that limit only works on top-level resources for create actions.
What native cluster roles solve and what they leave open
Native roles and bindings do a good job of scoping where a test runner can act. By using a Role and a RoleBinding, you keep the test inside one namespace. This stops a test suite from deleting pods in other namespaces. It also blocks the runner from changing cluster-wide node settings.
Still, native access rules only check who starts an action against the API server. Once a user or runner gets permission to exec into a pod, the cluster steps back. The role cannot inspect the individual shell commands run inside that container. If a test connects to a shared staging database, cluster roles cannot check the queries sent. They also cannot rewrite sensitive fields like emails, phone numbers, card numbers, or national IDs in results.
Kubernetes RBAC: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
When a test fails, engineers often need to jump into the test namespace to fix the issue. Giving engineers permanent role bindings for pod exec or database checks creates standing risk. Teams must manage static keys and update role bindings by hand after every debug session. Native RBAC decides who can open the door, not what commands or queries run in flight.
Scoping test runner permissions in practice
Start by creating a dedicated namespace for every test run or staging branch. Define a narrow Role inside that namespace instead of using a ClusterRoleBinding. List only the specific resources your test runner needs to create, read, or delete. Avoid wildcard rules that grant access to all resources or all verbs at once.
Separate the permissions for automated test runners from the permissions for human engineers. Test runners rarely need interactive shell access once the test script starts. Keep pod exec subresources out of the default runner role whenever you can. When engineers must inspect a broken test pod, require approval for that specific command. Mask sensitive test data in query outputs so emails and card numbers do not leak into logs.
Govern kubectl and API calls in flight
Identity providers and Kubernetes RBAC decide who logs into a cluster. They cannot redact keys inside returned JSON objects or hold a risky delete call for review. By design, hoop.dev sits inline as an open-source proxy, a sidecar for your Kubernetes API, without replacing RBAC. On every production call from an engineer or AI agent, hoop.dev decides to pass, mask, block, or hold it for human approval.
First, hoop.dev guardrails refuse banned methods, paths, or headers before they run or hold risky deletes for review. Next, hoop.dev data masking rewrites sensitive keys in returned Secret, ConfigMap, and log responses in memory, and writes each decision to the audit trail. Explore the repo on GitHub.
Frequently asked questions
Should a kubernetes integration test use a Role or a ClusterRole?
Use a Role with a RoleBinding so permissions stay inside a single test namespace. Only use a ClusterRole if the test must read cluster-scoped resources like nodes.
How do I let a test runner read pod logs without full admin rights?
Add a rule in your namespace Role that grants read access to the pods log subresource. This lets the runner fetch logs without allowing it to change or delete pods.
Why can native RBAC not block specific commands inside a test pod?
Kubernetes RBAC only checks if an identity can call the pod exec subresource API. Once the session starts, RBAC does not inspect or filter the shell commands run inside.
Related guides
In this post