Fork me on GitHub

Teleport Kubernetes Access for CI/CD

Short-Lived Certs for Kubernetes CI/CD

CI/CD tools like Jenkins can use short-lived certificates to talk to the Kubernetes API.

Create a non-interactive local Teleport user.

Non-interactive users don't have username or password defined and can't log in, but can be used to create credentials.

kind: role
version: v4
  name: robot
  # The allow section declares a list of resource/verb combinations that are
  # allowed for the users of this role. By default, nothing is allowed.
    # This field is used for SSH logins. You have to keep 'logins' as a non-empty random value
    # for Kubernetes to work until we fix it.
    logins: ['keep any value here']
    # A list of kubernetes groups to assign
    kubernetes_groups: ['system:masters']
kind: user
version: v2
  name: jenkins
  - robot

The examples below may include the use of the sudo keyword, token UUIDs, and users with admin privileges to make following each step easier when creating resources from scratch.


  1. We discourage using sudo in production environments unless it's needed.
  2. We encourage creating new, non-root, users or new test instances for experimenting with Teleport.
  3. We encourage adherence to the Principle of Least Privilege (PoLP) and Zero Admin best practices. Don't give users the admin role when giving them the more restrictive access,editor roles will do instead.
  4. Saving tokens into a file rather than sharing tokens directly as strings.

Learn more about Teleport Role-Based Access Control best practices.

Generate a kubeconfig using the jenkins user and its roles using tctl auth sign:

Create a new local user for Jenkins

tctl users add jenkins --roles=robot

Creates a token for 25hrs

tctl auth sign --user=jenkins --format=kubernetes --out=kubeconfig --ttl=25h

The credentials have been written to kubeconfig

cat kubeconfig

apiVersion: v1


- cluster:

certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZ....

This kubeconfig can now be exported and will provide access to the automation tooling.

Uses kubectl to get pods, using the provided kubeconfig.

kubectl --kubeconfig /path/to/kubeconfig get pods
Short-Lived Certs
Short-lived certificates expire in hours or minutes. You don't have to revoke them if the host gets compromised. Generate a new kubeconfig every hour using tctl or API and publish it to secret storage, like AWS or GCP secret managers.
Have a suggestion or can’t find something?