Skip to main content

Using Teleport's Certificate Authority with GitHub

Teleport supports exporting user SSH certificates with configurable key extensions. This allows the Teleport CA to be used in conjunction with GitHub's support for SSH Certificate Authorities. This way, users can access their organizations' repositories with short-lived, signed SSH certificates.

Prerequisites

  • A running Teleport cluster version 15.4.22 or above. If you want to get started with Teleport, sign up for a free trial or set up a demo environment.

  • The tctl admin tool and tsh client tool.

    On Teleport Enterprise, you must use the Enterprise version of tctl, which you can download from your Teleport account workspace. Otherwise, visit Installation for instructions on downloading tctl and tsh for Teleport Community Edition.

  • Access to GitHub Enterprise and permissions to modify GitHub's SSH Certificate Authorities.
  • To check that you can connect to your Teleport cluster, sign in with tsh login, then verify that you can run tctl commands using your current credentials. tctl is supported on macOS and Linux machines. For example:
    $ tsh login --proxy=teleport.example.com [email protected]
    $ tctl status
    # Cluster teleport.example.com
    # Version 15.4.22
    # CA pin sha256:abdc1245efgh5678abdc1245efgh5678abdc1245efgh5678abdc1245efgh5678
    If you can connect to the cluster and run the tctl status command, you can use your current credentials to run subsequent tctl commands from your workstation. If you host your own Teleport cluster, you can also run tctl commands on the computer that hosts the Teleport Auth Service for full permissions.

Step 1/3. Import the Teleport CA into GitHub

In order to export the Teleport CA, execute the following command, assigning proxy to the address of your Teleport Proxy Service:

$ curl 'https://proxy/webapi/auth/export?type=user' | sed 's/^cert-authority //g'

Next, follow the instructions in the guide below to import your Teleport CA into GitHub:

Managing your organization's SSH certificate authorities

The contents of the exported teleport.ca file should by pasted into the "Key" field after clicking "New CA".

Step 2/3. Configure the GitHub key extension

Create or update a role to include the cert_extensions option. The value of name must be [email protected].

kind: role
version: v5
metadata:
name: developer
spec:
options:
cert_extensions:
- type: ssh
mode: extension
name: [email protected] # required to be `[email protected]`.
value: "{{ external.logins }}"

Assign the developer role to your Teleport user by running the appropriate commands for your authentication provider:

  1. Retrieve your local user's roles as a comma-separated list:

    $ ROLES=$(tsh status -f json | jq -r '.active.roles | join(",")')
  2. Edit your local user to add the new role:

    $ tctl users update $(tsh status -f json | jq -r '.active.username') \
    --set-roles "${ROLES?},developer"
  3. Sign out of the Teleport cluster and sign in again to assume the new role.

Step 3/3. Issue a user certificate

When you authenticated to Teleport to assume the developer role we defined earlier, Teleport added the certificate extensions you configured to your user certificate. You can then refer to this path in your local SSH configuration.

For convenience, open a terminal and assign an environment variable to the location of your user certificate. Replace example.teleport.sh with the domain name of your Teleport cluster and myuser with the name of your Teleport user:

$ export TELEPORT_CERT=~/.tsh/keys/example.teleport.sh/myuser-ssh/example.teleport.sh-cert.pub

To test that authentication with this signed certificate is working correctly, SSH into github.com with your organization's user:

$ ssh -i $TELEPORT_CERT org-<ID>@github.com

If authentication is successful, a "You've successfully authenticated" message should be displayed in the terminal.

This newly generated certificate may then be used when interacting with GitHub over SSH by adding the following to the ~/.ssh/config file:

Host github.com
HostName github.com
IdentityFile path/to/cert.pub

When using SSH Certificate Authorities, you should retrieve your GitHub repository's SSH URL from the GitHub UI so the correct SSH user is used for authentication. For more information, see About SSH URLs with SSH certificates.