Using Teleport with OpenSSH in agentless mode (manual installation)
In this guide, we will show you how to configure the OpenSSH server sshd
to
join a Teleport cluster. Existing fleets of OpenSSH servers can be configured to
accept SSH certificates dynamically issued by a Teleport CA.
Using Teleport and OpenSSH has the advantage of getting you up
and running, but in the long run, we would recommend replacing sshd
with teleport
.
teleport
SSH servers have support for multiple features that are incompatible with OpenSSH:
- RBAC and resource filtering based on dynamically updated labels
- Session recording without SSH connection termination
- Session sharing
- Advanced session recording
Teleport supports OpenSSH by proxying SSH connections through the Proxy Service. When a Teleport user requests to connect to an OpenSSH node, the Proxy Service checks the user's Teleport roles.
If the RBAC checks succeed, the Proxy Service authenticates to the OpenSSH node with a dynamically generated certificate signed by a Teleport CA. This allows the Proxy Service to record and audit connections to OpenSSH nodes.
The Proxy Service prevents Teleport users from bypassing auditing by requiring a certificate signed by a Teleport CA that only the Auth Service possesses.
In this setup, the Teleport SSH Service performs RBAC checks as well as audits and records sessions on its host, which eliminates the need for connection termination when recording SSH sessions.
This guide shows you how to register an OpenSSH node by creating a node resource
and configuring OpenSSH to trust the Teleport CA. If you can copy the
teleport
binary onto your OpenSSH node and execute it however, you can follow
the standard registration guide instead, which has fewer steps.
Teleport is able to perform many of the steps we show in this guide automatically.
Prerequisites
-
OpenSSH version 6.9 or above on your local machine. View your OpenSSH version with the command:
$ ssh -V
-
A running Teleport cluster version 16.4.8 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 andtsh
client tool.Visit Installation for instructions on downloading
tctl
andtsh
.
- A Linux host with the OpenSSH server
sshd
version 7.4 or above installed, but not Teleport. The SSH port on this host must be open to traffic from the Teleport Proxy Service host. - To check that you can connect to your Teleport cluster, sign in with
tsh login
, then verify that you can runtctl
commands using your current credentials. For example:If you can connect to the cluster and run the$ tsh login --proxy=teleport.example.com --user=email@example.com
$ tctl status
# Cluster teleport.example.com
# Version 16.4.8
# CA pin sha256:abdc1245efgh5678abdc1245efgh5678abdc1245efgh5678abdc1245efgh5678tctl status
command, you can use your current credentials to run subsequenttctl
commands from your workstation. If you host your own Teleport cluster, you can also runtctl
commands on the computer that hosts the Teleport Auth Service for full permissions.
Upgrading to v14 from legacy OpenSSH nodes
If you have previously configured OpenSSH nodes to trust a Teleport CA without registering them and you upgrade your Teleport cluster to Teleport 14, you won't be able to connect to them anymore by default. This is because open dialing to OpenSSH servers not registered with the cluster is no longer allowed in Teleport 14. To ensure that you will retain access to your OpenSSH nodes you will need to follow this guide to register every OpenSSH node with Teleport that you previously configured. This must be done before your Teleport cluster is upgraded to Teleport 14.
If you are having issues registering OpenSSH nodes or need to upgrade your
Teleport cluster to Teleport 14 before registering all of your OpenSSH nodes, you can
pass the TELEPORT_UNSTABLE_UNLISTED_AGENT_DIALING
environment variable to your
Proxy Service and set it to yes
. This will allow connections to unregistered
OpenSSH nodes but will be removed in Teleport v15.
Step 1/5. Add a node resource to your Teleport cluster
When you request an SSH connection to a OpenSSH node, Teleport needs to be able to find the node's IP address so it can establish a connection to it.
Declare a node
resource so Teleport knows how to reach your OpenSSH server.
On your local machine, create a file called openssh-node-resource.yaml
with the following content:
kind: node
version: v2
sub_kind: openssh
metadata:
name: a100fdd0-52db-4eca-a7ab-c3afa7a1564a
labels:
env: prod
spec:
addr: 1.2.3.4:22
hostname: openssh-node
spec.addr
and spec.hostname
are mandatory. Assign spec.addr
to the address and port of your node
and spec.hostname
to the name of the node as you would like users to see it in Teleport.
The metadata.labels
field labels the SSH Service instance so you can apply RBAC rules to it.
The metadata.name
field isn't mandatory, but setting it here will save you some work later.
To generate a new universal unique identifier (UUID) suitable for a node
name, use the uuidgen
on Linux or macOS, or use the New-Guid
cmdlet in Powershell on Windows.
Create the node resource:
$ tctl create openssh-node-resource.yaml
This step can be done with Infrastructure-as-Code (IaC) tools (tctl, Terraform, or Kubernetes Operator). This is described in the OpenSSH server IaC guide.
Step 2/5. Configure sshd
to trust the Teleport CA
Later in this guide, we will generate an SSH client configuration that will use
a certificate signed by the Teleport Auth Service to authenticate to your SSH
server. For this to work, sshd
must be told to allow users to log in with
certificates generated by the Teleport Auth Service.
Start by exporting the Teleport CA public key.
On the host where you are running sshd
, run the following commands, assigning proxy to the address of your Teleport Proxy Service:
$ export KEY=$(curl 'https://proxy/webapi/auth/export?type=openssh' | sed "s/cert-authority\ //")
Make the public key accessible to sshd
:
$ sudo bash -c "echo \"$KEY\" > /etc/ssh/teleport_openssh_ca.pub"
$ sudo bash -c "echo 'TrustedUserCAKeys /etc/ssh/teleport_openssh_ca.pub' >> /etc/ssh/sshd_config"
Restart sshd
. For systemd-enabled hosts, run the following command:
$ sudo systemctl restart sshd
Now, sshd
will trust users who present a Teleport-issued certificate.
Step 3/5. Configure host authentication
Next, ask Teleport to issue a valid host certificate for your sshd
host. Later
in this guide, we will configure your SSH client to trust the certificate,
authenticating your sshd
host for your SSH client. Like the user certificate
we created earlier, the host certificate will be signed by the Teleport Auth
Service.
Ensure that your user has the correct privileges
Your user must be authorized to read and write host certificates.
On your local machine, create a file called host-certifier.yaml
with the
following content:
kind: role
version: v5
metadata:
name: host-certifier
spec:
allow:
rules:
- resources:
- host_cert
verbs:
- list
- create
- read
- update
- delete
Create the role resource:
$ tctl create host-certifier.yaml
# role 'host-certifier' has been created
Assign the host-certifier
role to your Teleport user by running the appropriate
commands for your authentication provider:
- Local User
- GitHub
- SAML
- OIDC
-
Retrieve your local user's roles as a comma-separated list:
$ ROLES=$(tsh status -f json | jq -r '.active.roles | join(",")')
-
Edit your local user to add the new role:
$ tctl users update $(tsh status -f json | jq -r '.active.username') \
--set-roles "${ROLES?},host-certifier" -
Sign out of the Teleport cluster and sign in again to assume the new role.
-
Open your
github
authentication connector in a text editor:$ tctl edit github/github
-
Edit the
github
connector, addinghost-certifier
to theteams_to_roles
section.The team you should map to this role depends on how you have designed your organization's role-based access controls (RBAC). However, the team must include your user account and should be the smallest team possible within your organization.
Here is an example:
teams_to_roles:
- organization: octocats
team: admins
roles:
- access
+ - host-certifier -
Apply your changes by saving closing the file in your editor.
-
Sign out of the Teleport cluster and sign in again to assume the new role.
-
Retrieve your
saml
configuration resource:$ tctl get --with-secrets saml/mysaml > saml.yaml
Note that the
--with-secrets
flag adds the value ofspec.signing_key_pair.private_key
to thesaml.yaml
file. Because this key contains a sensitive value, you should remove the saml.yaml file immediately after updating the resource. -
Edit
saml.yaml
, addinghost-certifier
to theattributes_to_roles
section.The attribute you should map to this role depends on how you have designed your organization's role-based access controls (RBAC). However, the group must include your user account and should be the smallest group possible within your organization.
Here is an example:
attributes_to_roles:
- name: "groups"
value: "my-group"
roles:
- access
+ - host-certifier -
Apply your changes:
$ tctl create -f saml.yaml
-
Sign out of the Teleport cluster and sign in again to assume the new role.
-
Retrieve your
oidc
configuration resource:$ tctl get oidc/myoidc --with-secrets > oidc.yaml
Note that the
--with-secrets
flag adds the value ofspec.signing_key_pair.private_key
to theoidc.yaml
file. Because this key contains a sensitive value, you should remove the oidc.yaml file immediately after updating the resource. -
Edit
oidc.yaml
, addinghost-certifier
to theclaims_to_roles
section.The claim you should map to this role depends on how you have designed your organization's role-based access controls (RBAC). However, the group must include your user account and should be the smallest group possible within your organization.
Here is an example:
claims_to_roles:
- name: "groups"
value: "my-group"
roles:
- access
+ - host-certifier -
Apply your changes:
$ tctl create -f oidc.yaml
-
Sign out of the Teleport cluster and sign in again to assume the new role.
You will now have the required permissions to export a host key for your sshd
host.