GKE Cluster Access via Teleport
This guide connects kubectl to GitLab’s GKE clusters through Teleport’s tsh command-line tool.
Teleport is the recommended, secure way to reach GKE clusters. Credentials come from Okta, last at most 12 hours, and need an approved request unless the role is standing.
Who has access
Section titled “Who has access”Okta group membership decides which Teleport roles a person holds (see Role-based access). Kubernetes roles currently go to these groups only:
| Team | Okta group | Standing role | Can request and approve access to |
|---|---|---|---|
| SRE | app.teleport.production.sre | kubernetes-admin | prod-kubernetes-admin, non-prod-kubernetes-admin |
| Infrastructure Security engineers | app.teleport.production.infrastructure_security_engineers | kubernetes-admin | prod-kubernetes-admin, non-prod-kubernetes-admin |
| DBRE | app.teleport.production.dbre | kubernetes-admin | prod-kubernetes-admin, non-prod-kubernetes-admin |
| SRE managers | app.teleport.production.sre_managers | None | prod-kubernetes-admin, non-prod-kubernetes-admin |
| Infrastructure Security managers | app.teleport.production.infrastructure_security_managers | None | prod-kubernetes-admin, non-prod-kubernetes-admin |
The group-to-role mapping is in groups.tf, and the Kubernetes roles are defined in roles_kubernetes.tf in config-mgmt.
Members of the first three groups can log in to any enrolled cluster without an access request. SRE and Infrastructure Security managers need an approved request first, and the requestable roles only reach some clusters (see Enrolled clusters).
No other group holds a Kubernetes role. To get one, request membership in one of these Okta groups with an Access Request (AR) issue. The team member’s manager approves the AR, and the group is added in Okta. For help with the AR, mention @gitlab-com/gl-security/product-security/infrastructure-security in it. For questions about how roles are assigned, ask in #security_help and ping @infrasec-team in Slack, or mention @gitlab-com/gl-security/product-security/infrastructure-security in GitLab.
Enrolled clusters
Section titled “Enrolled clusters”Only the regional GKE clusters are enrolled. Zonal clusters aren’t, so reach them through the paths in Kubernetes on-call setup.
| Cluster | environment label | Role to request |
|---|---|---|
gprd-gitlab-gke | gprd | prod-kubernetes-admin |
gstg-gitlab-gke | gstg | non-prod-kubernetes-admin |
pre-gitlab-gke | pre | non-prod-kubernetes-admin |
prdsub-customers-gke | prdsub | None (standing kubernetes-admin only) |
stgsub-customers-gke | stgsub | None (standing kubernetes-admin only) |
Each cluster’s Teleport agent is configured under services/teleport-agent/env/ in argocd/apps. The environment values each role matches are set in locals.tf in config-mgmt.
The requestable roles match on the environment label: prod-kubernetes-admin covers gprd, and non-prod-kubernetes-admin covers gstg and pre. Neither matches prdsub or stgsub, so the CustomersDot clusters are reachable only with the standing kubernetes-admin role today.
What the roles allow
Section titled “What the roles allow”All three Kubernetes roles grant the same access and differ only in which clusters they reach. Tested with the standing kubernetes-admin role:
| Command | Result |
|---|---|
kubectl get pods, get deploy, get statefulset | Works in any namespace |
kubectl get namespaces | Works |
kubectl logs | Denied (see Troubleshooting) |
kubectl exec | Untested |
For pod logs, use the on-call setup path.
Prerequisites
Section titled “Prerequisites”- Teleport access via Okta (see getting access).
tshis installed (see installation instructions).kubectlis installed (macOS, Linux).- Membership in one of the Okta groups listed in Who has access. Without one, open an Access Request (AR) issue first.
Process
Section titled “Process”Request access
Section titled “Request access”This section covers requesting temporary access (up to 12 hours) to the prod-kubernetes-admin or non-prod-kubernetes-admin role.
-
Log in to Teleport:
Terminal window tsh login --proxy=production.teleport.gitlab.net -
Request the role that covers the target cluster. These roles reach
gprd-gitlab-gke,gstg-gitlab-gke, andpre-gitlab-gkeonly; the CustomersDot clusters need the standing role (see Enrolled clusters).Terminal window # gprd-gitlab-gketsh request create \--roles=prod-kubernetes-admin \--reason="<GitLab issue URL>"# gstg-gitlab-gke, pre-gitlab-gketsh request create \--roles=non-prod-kubernetes-admin \--reason="<GitLab issue URL>" -
An automated message appears in the #teleport-requests Slack channel. Tag an approver: an SRE, a DBRE, an Infrastructure Security engineer, or another SRE or Infrastructure Security manager. Engineering managers outside these groups don’t hold a Kubernetes approver role, so #eng-managers can’t help here.
-
Once approved, the Slack bot posts a notification in #teleport-requests.
-
tsh request createprints a request ID and waits for approval. If it’s still running, it picks up the approved role on its own. Otherwise, log in totshagain with the request ID, which is also posted in #teleport-requests:Terminal window tsh login --request-id=<request-id> -
Confirm the role is active. The output of
tsh statusshould listprod-kubernetes-adminornon-prod-kubernetes-adminunder its roles:Terminal window tsh status
Log in
Section titled “Log in”-
Log in to Teleport (skip this if a session is already active):
Terminal window tsh login --proxy=production.teleport.gitlab.net -
List the clusters the current roles can reach:
Terminal window tsh kube lsWith the standing
kubernetes-adminrole, the output looks like this:Kube Cluster Name Labels Scope Selected-------------------- ----------------------------------------------------- ----- --------gprd-gitlab-gke environment=gprd,service=kubernetes,type=kubernetesgstg-gitlab-gke environment=gstg,service=kubernetes,type=kubernetesprdsub-customers-gke environment=prdsub,service=kubernetes,type=kubernetespre-gitlab-gke environment=pre,service=kubernetes,type=kubernetesstgsub-customers-gke environment=stgsub,service=kubernetes,type=kubernetes -
Log in to a cluster. This adds a context for the cluster to the local kubeconfig and makes it the current context:
Terminal window tsh kube login gstg-gitlab-gkeAfterwards,
tsh statusshowsKubernetes: enabledandKubernetes groups: system:masters. -
Run
kubectlcommands against the cluster, for example:$ kubectl get pods -n teleport-agentNAME READY STATUS RESTARTS AGEteleport-agent-0 1/1 Running 0 8dteleport-agent-1 1/1 Running 0 8dkubectl logsis denied with the current roles (see What the roles allow).
Next Steps
Section titled “Next Steps”- Sessions expire after 12 hours. Run
tsh loginagain to renew a standing role. Requested roles need a new request, using the same process. tsh kube loginswitches the current kubeconfig context. To switch away without logging out of Teleport, runkubectl config use-context <previous>(orglsh kube use-clusteras described in Kubernetes on-call setup for a VPN or SOCKS5 context).tsh logoutends the Teleport session.- Tools that read the local kubeconfig, such as k9s, use the Teleport context too. Log views are denied. These tools act with
system:mastersas well, so checkkubectl config current-contextbefore using them, especially after logging in togprd-gitlab-gke. - Learn about tsh’s features in Teleport’s docs.
Support
Section titled “Support”- For help with Teleport or the approval process, ask in #security_help and ping
@infrasec-teamin Slack, or mention@gitlab-com/gl-security/product-security/infrastructure-securityin GitLab. - To report a Teleport bug, open an issue with Infrastructure Security.
Troubleshooting
Section titled “Troubleshooting”tsh kube ls shows no clusters
Section titled “tsh kube ls shows no clusters”The current roles don’t match any enrolled cluster. Run tsh status and check the role list:
- Without
kubernetes-admin,prod-kubernetes-admin, ornon-prod-kubernetes-admin, request access first. - If a role was approved but isn’t listed, log in again with
tsh login --request-id=<request-id>.
Zonal clusters never appear here because they aren’t enrolled.
kubectl logs returns a NotFound error
Section titled “kubectl logs returns a NotFound error”kubectl logs fails with:
error: error from server (NotFound): Your user's Teleport role does not allow Kubernetes access. Please ask cluster administrator to ensure your role has appropriate kubernetes_groups and kubernetes_users set. in namespace "teleport-agent"The current Kubernetes roles don’t grant access to pod logs. This has been tested with the standing kubernetes-admin role on gstg-gitlab-gke and gprd-gitlab-gke. Read logs through the on-call setup path instead. To ask for log access through Teleport, raise it in #security_help (ping @infrasec-team) or open an issue with Infrastructure Security and mention @gitlab-com/gl-security/product-security/infrastructure-security in it.
tsh request create timed out
Section titled “tsh request create timed out”tsh request create waits for approval and returns once the request is approved, denied, or expires.
If it times out before a decision, check the #teleport-requests Slack channel or the Teleport Web UI for the request ID. An approved request doesn’t need to be made again.
failed to add one or more keys to the agent
Section titled “failed to add one or more keys to the agent”See getting_access.md: Troubleshooting.
Verbose output
Section titled “Verbose output”tsh --debug kube login <cluster>