How to Configure GKE Service Account

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a gke service account by creating an identity and binding roles. Next, you attach that identity to your pods or users for cluster tasks. Most teams start by granting broad roles to get apps running fast. Overly broad roles let one bad command break many workloads across the cluster. Scoping each role early keeps your cluster safe from wide mistakes. How a gke service account works with native RBAC Kubernetes role-based access control uses four main objects to manage permissions. 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 gke service account by creating an identity and binding roles. Next, you attach that identity to your pods or users for cluster tasks. Most teams start by granting broad roles to get apps running fast. Overly broad roles let one bad command break many workloads across the cluster. Scoping each role early keeps your cluster safe from wide mistakes.

How a gke service account works with native RBAC

Kubernetes role-based access control uses four main objects to manage permissions. A Role holds a set of rules that work inside one single namespace. A ClusterRole holds rules that work across the whole cluster and all namespaces. It can also cover cluster-wide items like nodes and non-resource endpoints. All rules in this system are additive. There are no deny rules in standard Kubernetes role setups. You start with zero permissions and add rules one by one.

To give permissions to a gke service account, you create a binding object. A RoleBinding grants permissions inside one specific namespace. That RoleBinding can point to a local Role or a shared ClusterRole. A ClusterRoleBinding grants permissions across the entire cluster at once. When a pod or user sends a request, the API server checks these bindings. If a matching rule exists, the API server lets the request run.

Scoping subresources and namespace permissions

Many cluster actions use subresources instead of just top-level objects. The API server names these subresources with a slash in the path. Reading pod logs uses the pods and log subresource path. Running a shell inside a container uses the pods and exec subresource path. If a role allows create on the exec subresource, anyone with that role can open a shell.

Teams often try to limit subresources to specific named pods in a rule. Still, resource name restrictions on create actions only work on top-level objects. They do not filter subresources during a create request. When you grant exec rights in a namespace, the identity can enter any pod there. Using a RoleBinding instead of a ClusterRoleBinding helps contain this risk to one namespace. You should create one account per app rather than sharing one default account.

Service-to-Service Authentication + Service Account Governance: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native roles solve and what they leave open

Native roles and bindings do a good job of guarding the front door. They decide which identity can talk to the API server and which namespace it can touch. They also block unauthorized apps from reading cluster state or changing pod specs. This setup stops outsiders and untrusted workloads from making direct API calls.

Still, native role bindings stop checking once a session starts. Once an engineer or script opens an exec session, RBAC does not inspect individual commands. It cannot approve a single command inside a container or mask sensitive output in flight. If a pod prints emails, phone numbers, card numbers, or national IDs, raw text appears on screen. Native roles also do not link static account keys to a specific human user during live fixing. Teams need runtime controls to inspect commands and rewrite matched fields 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

Can I add a deny rule to a gke service account role?

No, native Kubernetes RBAC rules are only additive and do not support deny rules. To remove permissions, you must delete the binding or edit the role rules directly.

When should I use a RoleBinding instead of a ClusterRoleBinding?

Use a RoleBinding whenever an app or team only needs permissions inside one namespace. You can bind a shared ClusterRole with a RoleBinding to keep permissions inside that single namespace.

Why can a role still run commands in all pods in a namespace?

Granting the exec subresource in a role applies to the whole namespace in that binding. Name restrictions on create actions apply to top-level resources, not to subresources like pod exec.

The query runs. The emails stay hidden.