Skip to content

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.

Okta group membership decides which Teleport roles a person holds (see Role-based access). Kubernetes roles currently go to these groups only:

TeamOkta groupStanding roleCan request and approve access to
SREapp.teleport.production.srekubernetes-adminprod-kubernetes-admin, non-prod-kubernetes-admin
Infrastructure Security engineersapp.teleport.production.infrastructure_security_engineerskubernetes-adminprod-kubernetes-admin, non-prod-kubernetes-admin
DBREapp.teleport.production.dbrekubernetes-adminprod-kubernetes-admin, non-prod-kubernetes-admin
SRE managersapp.teleport.production.sre_managersNoneprod-kubernetes-admin, non-prod-kubernetes-admin
Infrastructure Security managersapp.teleport.production.infrastructure_security_managersNoneprod-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.

Only the regional GKE clusters are enrolled. Zonal clusters aren’t, so reach them through the paths in Kubernetes on-call setup.

Clusterenvironment labelRole to request
gprd-gitlab-gkegprdprod-kubernetes-admin
gstg-gitlab-gkegstgnon-prod-kubernetes-admin
pre-gitlab-gkeprenon-prod-kubernetes-admin
prdsub-customers-gkeprdsubNone (standing kubernetes-admin only)
stgsub-customers-gkestgsubNone (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.

All three Kubernetes roles grant the same access and differ only in which clusters they reach. Tested with the standing kubernetes-admin role:

CommandResult
kubectl get pods, get deploy, get statefulsetWorks in any namespace
kubectl get namespacesWorks
kubectl logsDenied (see Troubleshooting)
kubectl execUntested

For pod logs, use the on-call setup path.

This section covers requesting temporary access (up to 12 hours) to the prod-kubernetes-admin or non-prod-kubernetes-admin role.

  1. Log in to Teleport:

    Terminal window
    tsh login --proxy=production.teleport.gitlab.net
  2. Request the role that covers the target cluster. These roles reach gprd-gitlab-gke, gstg-gitlab-gke, and pre-gitlab-gke only; the CustomersDot clusters need the standing role (see Enrolled clusters).

    Terminal window
    # gprd-gitlab-gke
    tsh request create \
    --roles=prod-kubernetes-admin \
    --reason="<GitLab issue URL>"
    # gstg-gitlab-gke, pre-gitlab-gke
    tsh request create \
    --roles=non-prod-kubernetes-admin \
    --reason="<GitLab issue URL>"
  3. 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.

  4. Once approved, the Slack bot posts a notification in #teleport-requests.

  5. tsh request create prints a request ID and waits for approval. If it’s still running, it picks up the approved role on its own. Otherwise, log in to tsh again with the request ID, which is also posted in #teleport-requests:

    Terminal window
    tsh login --request-id=<request-id>
  6. Confirm the role is active. The output of tsh status should list prod-kubernetes-admin or non-prod-kubernetes-admin under its roles:

    Terminal window
    tsh status
  1. Log in to Teleport (skip this if a session is already active):

    Terminal window
    tsh login --proxy=production.teleport.gitlab.net
  2. List the clusters the current roles can reach:

    Terminal window
    tsh kube ls

    With the standing kubernetes-admin role, the output looks like this:

    Kube Cluster Name Labels Scope Selected
    -------------------- ----------------------------------------------------- ----- --------
    gprd-gitlab-gke environment=gprd,service=kubernetes,type=kubernetes
    gstg-gitlab-gke environment=gstg,service=kubernetes,type=kubernetes
    prdsub-customers-gke environment=prdsub,service=kubernetes,type=kubernetes
    pre-gitlab-gke environment=pre,service=kubernetes,type=kubernetes
    stgsub-customers-gke environment=stgsub,service=kubernetes,type=kubernetes
  3. 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-gke

    Afterwards, tsh status shows Kubernetes: enabled and Kubernetes groups: system:masters.

  4. Run kubectl commands against the cluster, for example:

    $ kubectl get pods -n teleport-agent
    NAME READY STATUS RESTARTS AGE
    teleport-agent-0 1/1 Running 0 8d
    teleport-agent-1 1/1 Running 0 8d

    kubectl logs is denied with the current roles (see What the roles allow).

  • Sessions expire after 12 hours. Run tsh login again to renew a standing role. Requested roles need a new request, using the same process.
  • tsh kube login switches the current kubeconfig context. To switch away without logging out of Teleport, run kubectl config use-context <previous> (or glsh kube use-cluster as described in Kubernetes on-call setup for a VPN or SOCKS5 context). tsh logout ends 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:masters as well, so check kubectl config current-context before using them, especially after logging in to gprd-gitlab-gke.
  • Learn about tsh’s features in Teleport’s docs.
  • For help with Teleport or the approval process, ask in #security_help and ping @infrasec-team in Slack, or mention @gitlab-com/gl-security/product-security/infrastructure-security in GitLab.
  • To report a Teleport bug, open an issue with Infrastructure Security.

The current roles don’t match any enrolled cluster. Run tsh status and check the role list:

  • Without kubernetes-admin, prod-kubernetes-admin, or non-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 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 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.

Terminal window
tsh --debug kube login <cluster>