How to Configure GKE Port Forward

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up gke port forward by granting pod port-forwarding rules in Kubernetes RBAC. Then your engineers open a local tunnel to a pod through the cluster API server. Most teams start by handing out broad developer roles across a namespace. That quick fix lets people debug apps from their laptops. Yet broad roles often give developers access to every pod in that namespace. One wide role can expose internal databases, caches, and admin ports to anyone. How gke port forward works with Kubernetes

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 port forward by granting pod port-forwarding rules in Kubernetes RBAC. Then your engineers open a local tunnel to a pod through the cluster API server. Most teams start by handing out broad developer roles across a namespace. That quick fix lets people debug apps from their laptops. Yet broad roles often give developers access to every pod in that namespace. One wide role can expose internal databases, caches, and admin ports to anyone.

How gke port forward works with Kubernetes RBAC

Kubernetes manages cluster permissions through roles and bindings in its native authorization API group. Every rule in this system is additive, which means there are no deny rules. You always start from zero permissions and add the exact rules a user needs. A Role sets permissions inside one single namespace. A ClusterRole sets permissions across the whole cluster and covers all namespaces at once. To grant those rules to a person, you create a binding object. A RoleBinding gives a user or group permissions inside one specific namespace. That binding can point to a Role or a reusable ClusterRole. A ClusterRoleBinding grants permissions across the entire cluster at once.

When an engineer runs a port tunnel, Kubernetes checks permissions on a specific subresource. In Kubernetes RBAC, subresources use a slash after the main resource name. Just as reading pod logs uses a log subresource, port forwarding uses a pod subresource. The user also needs permission to read the pod object itself. The API server checks these rules before it opens the network stream. If the role binding matches, the API server streams traffic to the target pod. The engineer can then send traffic to a local port on their own machine.

What native RBAC solves and what it misses

Native Kubernetes RBAC is great at controlling who can open a tunnel. By using a Role and a RoleBinding, you limit engineers to one namespace. You can keep staging users out of production namespaces with clear boundaries. You can also separate read-only log viewers from people who open network tunnels. The cluster API server logs the initial request when the tunnel starts.

Still, native RBAC only checks permissions at the moment the tunnel opens. Also, resource name filters on create actions do not work on subresources. That makes it hard to lock a create rule down to one named pod. Once the API server approves the stream, raw bytes flow through the tunnel. Kubernetes does not inspect the traffic moving inside that open port forward stream. If an engineer tunnels to a database pod, Kubernetes sees only an open stream. It does not know what queries run or what records return over that port. Sensitive fields like emails, phone numbers, card numbers, and national IDs flow back untouched. Native cluster logs record who opened the tunnel, not what happened inside it.

GKE Workload Identity + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Why teams review pod tunnel permissions

Many teams use pod tunnels to reach private services that lack public addresses. Developers forward ports to check an internal admin page or query a backing store. Over time, temporary debugging roles turn into permanent access for the whole engineering team. Because RBAC rules are only additive, layering extra roles makes permissions grow fast. You cannot write a deny rule to block one sensitive pod inside a shared namespace. Reviewing your bindings often helps you spot ClusterRoleBindings that should be single-namespace RoleBindings instead. Tightening those bindings is the first step toward safer cluster operations.

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 RBAC role scope should I use for gke port forward?

Use a Role and a RoleBinding scoped to one single namespace whenever you can. Avoid ClusterRoleBindings for port tunnels because they grant access across every namespace in the cluster.

Can I write a deny rule in Kubernetes RBAC to block one pod?

No, Kubernetes RBAC rules are purely additive and do not support deny rules. To block access, you must remove the broad binding and grant narrower roles instead.

Does Kubernetes log the commands or queries sent inside a port tunnel?

No, the Kubernetes API server only checks and logs the request that starts the tunnel. It does not read or log the database queries or HTTP calls sent inside.

The query runs. The emails stay hidden.