Kubernetes Sidecar Authentication

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up kubernetes sidecar authentication by running a helper container inside your app pod. This helper container checks user or service identities before traffic reaches the main app. Teams often pair this pattern with native role bindings to control cluster entry. Still, broad permissions let users run unchecked commands once they get inside the pod. How kubernetes sidecar authentication works in practice A pod can run more than one container at the same time. In this pattern, the helpe

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 sidecar authentication by running a helper container inside your app pod. This helper container checks user or service identities before traffic reaches the main app. Teams often pair this pattern with native role bindings to control cluster entry. Still, broad permissions let users run unchecked commands once they get inside the pod.

How kubernetes sidecar authentication works in practice

A pod can run more than one container at the same time. In this pattern, the helper container sits next to your main app container. Both containers share the same local network space and storage volumes inside that pod. The helper handles identity checks so the main app code stays simple and clean.

At the cluster level, admins enable role-based rules on the API server. A Role sets permissions inside one namespace, while a ClusterRole covers the whole cluster. A RoleBinding grants those permissions to specific users or service accounts in a namespace. If a team needs cluster-wide rules, they use a ClusterRoleBinding instead.

In Kubernetes, all these rules are purely additive, which means there are no deny rules. You start with zero permissions and add rules for each needed action and resource. When a sidecar needs to talk to the API server, it uses the pod service account. That account gets its exact permissions from the bound Role or ClusterRole.

How pod subresources and shared permissions work

Sidecar containers share the exact same pod identity as the main app container. If you mount a service account into a pod, both containers can read it. This shared boundary matters when engineers debug issues or read logs from the cluster.

Kubernetes RBAC refers to resources by the exact name in the API URL. Some API calls use a subresource, such as reading pod logs or running commands. In RBAC rules, you write this subresource with a slash, like pods and log. You also grant command execution across the pod using the pods and exec subresource.

Admins often try to limit subresource rules to specific pod names. Still, the resource names filter on create calls applies only to top-level resources. It does not restrict subresources in the same way during creation steps. Once a user has exec rights in a namespace, they can enter any container.

Kubernetes RBAC + Multi-Factor Authentication (MFA): architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native setup solves and where gaps remain

Combining sidecar checks with cluster RBAC solves the initial login problem well. The cluster checks who can reach the pod API, and the sidecar checks app requests. This setup stops unauthorized services from talking to your backend ports over the network.

Still, this native setup leaves a major operational gap during live debugging sessions. RBAC and sidecars decide who logs in, not what individual commands do in flight. When an engineer runs an interactive shell via the exec subresource, the sidecar is bypassed. The engineer lands right inside the container with full access to local files.

From there, a user can read local secrets or query connected databases directly. Native RBAC cannot inspect shell commands or mask sensitive data like emails or card numbers. Teams need a way to govern individual actions and rewrite sensitive fields in results.

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 runs beside the API server as a sidecar for your Kubernetes API and checks every request and response alongside RBAC.

With hoop.dev Kubernetes controls, guardrails can allow listing Secret names while refusing reads of Secret data before execution. 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

Does a sidecar container have its own Kubernetes service account?

No, service accounts attach to the whole pod, not to single containers. Both the main app and the sidecar share the same pod service account permissions.

Can I use deny rules in Kubernetes RBAC to block sidecar access?

No, permissions in Kubernetes RBAC are purely additive and never support deny rules. You must grant only the exact roles needed through a RoleBinding or ClusterRoleBinding.

Does a sidecar inspect commands run through kubectl exec?

No, the exec subresource connects directly to the container runtime through the API server. Network sidecars do not intercept or filter interactive shell commands run this way.

The query runs. The emails stay hidden.