Kubernetes TLS Certificate

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a kubernetes tls certificate by storing a public cert and private key inside a Secret. Then you mount that Secret into your pods or ingress controller to encrypt traffic. Most teams pair this setup with role-based access control to protect the key material. Still, broad role rules often let too many users read Secrets or run pod commands. When a role grants wide cluster rights, any user with that role can pull private keys. How a kubernetes tls certificate and role rules work In 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.

You set up a kubernetes tls certificate by storing a public cert and private key inside a Secret. Then you mount that Secret into your pods or ingress controller to encrypt traffic. Most teams pair this setup with role-based access control to protect the key material. Still, broad role rules often let too many users read Secrets or run pod commands. When a role grants wide cluster rights, any user with that role can pull private keys.

How a kubernetes tls certificate and role rules work

In a cluster, a Secret object holds your public cert and private key pair. Workloads and ingress controllers read this Secret to handle encrypted connections between services or users. Because the private key is sensitive, you must limit who can read that Secret. Kubernetes uses roles and bindings in its authorization API group to control these permissions. Every rule in this system is additive, which means there are no deny rules. You start with zero access and add specific permissions for each user or group.

A Role sets rules within one single namespace for resources like Secrets or Pods. A ClusterRole sets rules across the whole cluster for nodes or all namespaces at once. To grant those rules to a user, you create a RoleBinding or a ClusterRoleBinding. A RoleBinding applies permissions inside one namespace, even if it points to a ClusterRole. A ClusterRoleBinding gives a user those permissions across every namespace in the entire cluster. If you bind a Secret reader role cluster-wide, that user can read every TLS key.

Why client certs and role bindings are not enough

Teams also use a kubernetes tls certificate to prove user identity to the API server. The API server checks the client cert and extracts the user name and group name. Then the authorization mode checks if a RoleBinding or ClusterRoleBinding allows the requested API action. This native setup is great at deciding who can log in and call an endpoint. It stops unauthorized users from listing Secrets or starting new workloads in a namespace.

Still, native role rules do not control what happens inside an active pod session. Kubernetes treats pod logs and pod command execution as subresources written with a slash. When a role grants access to the pod execution subresource, the user can open a shell. The API server checks the role rule only when the user starts that shell connection. Once the shell opens, native RBAC does not inspect or filter individual commands in flight. An engineer inside a pod can read mounted TLS files or query connected databases directly. Native roles also cannot mask sensitive fields like emails, phone numbers, or card numbers in output. Client certs and static bindings also stay valid until they expire or someone deletes them.

Kubernetes RBAC + Certificate-Based Authentication: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Tightening control over secrets and cluster sessions

To reduce risk, scope every Secret rule to a single namespace with a RoleBinding. Avoid using a ClusterRoleBinding for human users who only need access to one app. Separate the permission to view pod status from the permission to run pod exec subresources. Keep Secret read rules away from general developer roles whenever your workflow allows it. Even with tight bindings, you still need visibility into the commands users run after connecting.

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

How does Kubernetes store a TLS certificate?

Kubernetes stores the public certificate and private key inside a Secret object in a namespace. Pods and ingress controllers mount or read that Secret to encrypt network traffic.

Can a Role deny access to a specific TLS Secret?

No, permissions in Kubernetes RBAC are purely additive and never include deny rules. To block access, you must avoid granting a broad RoleBinding or ClusterRoleBinding in the first place.

Does RBAC inspect commands inside a pod exec session?

No, RBAC only checks if the user has permission to call the pod exec subresource. It does not inspect, block, or rewrite individual shell commands after the session starts.

The query runs. The emails stay hidden.