How to Configure GKE Secrets

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up gke secrets by storing data in Kubernetes objects and binding roles. Then you mount those values into pods or pass them as variables. Many teams start by giving broad cluster roles to speed up work. When roles are too broad, any user or pod can read all secret keys. A single mistake or stolen token can expose database keys across the whole cluster. How to set up gke secrets with Kubernetes RBAC Kubernetes uses role-based rules on the API server to control who reads secret objects.

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 gke secrets by storing data in Kubernetes objects and binding roles. Then you mount those values into pods or pass them as variables. Many teams start by giving broad cluster roles to speed up work. When roles are too broad, any user or pod can read all secret keys. A single mistake or stolen token can expose database keys across the whole cluster.

How to set up gke secrets with Kubernetes RBAC

Kubernetes uses role-based rules on the API server to control who reads secret objects. Each Role or ClusterRole holds a list of rules that grant permissions. In Kubernetes, these rules only add permissions, and there are no deny rules. A Role sets permissions inside one single namespace for your team. A ClusterRole works across the whole cluster and covers all namespaces at once.

To grant these permissions, you create a RoleBinding or a ClusterRoleBinding. A RoleBinding gives a user or service account permissions inside one specific namespace. That RoleBinding can point to a local Role or a shared ClusterRole. A ClusterRoleBinding grants permissions across every namespace in the entire cluster. For tight security, bind secret read rules with a RoleBinding in one namespace.

You should also watch how you grant permissions for pod subresources. In Kubernetes RBAC, subresources like pod logs or pod exec use a slash format. If an engineer can run commands in a pod, they can read mounted files. That means pod exec permissions let users read the secret values inside that container. You must keep secret rules and pod exec rules tight for every role.

Why native roles leave a runtime gap

Native Kubernetes RBAC is great for deciding who can reach a resource object. It checks if a user or pod can read a secret from the API. Still, native setup only checks permissions when the session or API call starts. It does not inspect what individual commands or queries do during an active session.

Once a pod or engineer has a database key, Kubernetes steps out of the way. An engineer using pod exec can run any shell command inside that running container. They can dump mounted keys or connect to a database and run broad queries. Native roles cannot pause a dangerous command or rewrite sensitive fields in query results.

K8s Secrets Management + GKE Workload Identity: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Also, static keys stored in namespaces create long-term risk for your platform team. If a developer copies a key to a laptop, that key works until someone rotates it. Standard RBAC logs show who read the secret object from the cluster API. They do not show what database statements or shell commands ran with that key later. Teams need controls that work at the command level, not just at login.

Best practices for scoping secret permissions

Start by splitting your apps into separate namespaces based on team or service boundaries. Never use a ClusterRoleBinding to grant secret read rules across the whole cluster. Instead, create a separate Role and RoleBinding inside each namespace for each app. Give each pod its own service account so pods do not share default permissions.

Next, separate human debug roles from the roles that read raw secret objects. Most engineers only need to check pod status or read app log subresources. They rarely need to read raw keys or open an interactive shell in production. When someone needs to run a command or query, control that action in flight. Dynamic masking can also rewrite emails, phone numbers, card numbers, and national IDs in results.

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 proxy, a sidecar for your Kubernetes API, inline on the API connection. On every kubectl or API call an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human review.

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, or hold risky calls for approval. On the way back, hoop.dev data masking walks JSON responses by key and masks matched values in Secrets, ConfigMaps, and pod logs in memory. View the project on GitHub.

Frequently asked questions

What is the difference between a Role and a ClusterRole for secrets?

A Role applies secret rules inside one specific namespace only. A ClusterRole can apply secret rules across all namespaces in the whole cluster.

Can I write a deny rule in Kubernetes RBAC to block secret reads?

No, Kubernetes RBAC permissions are purely additive and do not support deny rules. To block secret reads, you must remove the role binding that grants that permission.

How can engineers read secrets without direct secret permissions?

If an engineer has pod exec permissions, they can open a shell inside a pod. From inside the pod, they can read any secret mounted as a file or variable.

The query runs. The emails stay hidden.