Running Integration Tests in Kubernetes

Published
Length
3 min read

Luis Felipe Dias

All posts

Running integration tests in kubernetes starts with creating a dedicated namespace and a scoped role. You then run test jobs that check how your app services work together. Most teams set up automated pipelines or local tools to start these test pods. Still, giving test runners broad cluster roles often exposes live databases and shared secrets. A single bad test script can then alter or delete data outside its own space. How running integration tests in kubernetes works To run tests inside a

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.

Running integration tests in kubernetes starts with creating a dedicated namespace and a scoped role. You then run test jobs that check how your app services work together. Most teams set up automated pipelines or local tools to start these test pods. Still, giving test runners broad cluster roles often exposes live databases and shared secrets. A single bad test script can then alter or delete data outside its own space.

How running integration tests in kubernetes works

To run tests inside a cluster, you first isolate the test workload in one namespace. Kubernetes uses role-based access control to manage what users and test jobs can do. A Role sets permissions inside a single namespace. In contrast, a ClusterRole can cover resources across all namespaces or cluster-wide nodes. For integration tests, a single namespace Role is the safest way to start.

You attach this Role to your test runner account using a RoleBinding. That binding grants the permissions listed in the Role inside that specific namespace. Note that permissions in Kubernetes are purely additive. There are no deny rules in this system. You must start with zero permissions and add only what the test job needs.

During a test run, your pipeline creates pods, reads logs, and checks app status. In the API, features like pod logs or command execution are called subresources. You must grant permissions for these subresources explicitly in your Role rules. For example, reading test output requires permission on the log subresource of a pod. Running a setup script inside a live container requires permission on the exec subresource.

Setting up namespaces and roles for test runners

Good test isolation means keeping test runners away from production namespaces. Many teams create a new namespace for each pull request or build run. The pipeline sets up the app services, runs the test pod, and collects the output. When the test finishes, the pipeline deletes the temporary namespace and all its resources.

Problems happen when teams use a ClusterRoleBinding for convenience. A ClusterRoleBinding grants access across the entire cluster at once. If a test runner has cluster-wide rights, it can read secrets in other namespaces. It can also run commands inside pods that belong to other teams.

Developers also need to debug failing integration tests by hand. To fix a broken test, an engineer often opens a shell inside the test pod. They might also connect to a test database to inspect the tables and rows. Giving every developer permanent exec permissions in shared test namespaces creates a clear risk. Anyone with that role can run arbitrary commands or read raw database secrets.

Just-in-Time Access + Kubernetes RBAC: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native cluster roles solve and what they leave open

Native roles and bindings are great at controlling who can start pods or enter namespaces. The API server checks if the user or test runner has the right role. If the role matches, the API server allows the request to go through.

Still, native roles stop checking once the session or command starts running. A Role decides who can open a pod shell or reach a database service. It does not inspect the actual shell commands or database queries in flight. Once inside a pod, an engineer can dump sensitive keys or change service settings. If a test database holds real customer records, queries can return raw emails or card numbers.

Cluster audit logs also miss the details of what happens inside these sessions. The log shows that someone used the exec subresource on a specific pod. It does not show the exact commands typed or the data returned on screen. Teams need a way to check individual commands and mask sensitive fields like phone numbers.

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 integration tests use a Role or a ClusterRole?

Use a Role with a RoleBinding so permissions stay inside one test namespace. A ClusterRole can still work if you bind it with a namespace RoleBinding. Avoid using a ClusterRoleBinding because it grants permissions across every namespace in the cluster.

How do you limit test runners from reading pod logs in other namespaces?

Grant permission for the pod log subresource only inside the specific test namespace Role. Since Kubernetes permissions are additive and have no deny rules, avoid cluster-wide log bindings. Each test runner should only have a RoleBinding in its own namespace.

Why is pod exec access risky in shared test clusters?

The exec subresource lets a user run any command inside a running container. Native roles only check if the user is allowed to start that exec session. They cannot block dangerous shell commands or rewrite national IDs and emails in the output.

The query runs. The emails stay hidden.