Getting Started With Teleport Access Controls
Teleport Role-Based Access Control (RBAC) is a system for managing who can access what within your infrastructure. Instead of assigning permissions directly to users, you create roles that define sets of permissions, then assign those roles to users.
This guide helps you understand RBAC in Teleport by walking you through the process of applying labels to resources, setting up minimal roles, and accessing resources available to a particular role.
How it works
This guide illustrates how to register a server with Teleport using a Docker container and the Teleport SSH Service in order to apply RBAC rules for accessing the server. While the example uses a Teleport-protected server, applying RBAC rules for accessing infrastructure resources works in similar ways for any Teleport-protected resource.
Prerequisites
-
A running Teleport cluster. If you want to get started with Teleport, sign up for a free trial or set up a demo environment.
-
The
tctl
andtsh
clients.Installing
tctl
andtsh
clients-
Determine the version of your Teleport cluster. The
tctl
andtsh
clients must be at most one major version behind your Teleport cluster version. Send a GET request to the Proxy Service at/v1/webapi/find
and use a JSON query tool to obtain your cluster version. Replace teleport.example.com:443 with the web address of your Teleport Proxy Service:TELEPORT_DOMAIN=teleport.example.com:443TELEPORT_VERSION="$(curl -s https://$TELEPORT_DOMAIN/v1/webapi/find | jq -r '.server_version')" -
Follow the instructions for your platform to install
tctl
andtsh
clients:- Mac
- Windows - Powershell
- Linux
Download the signed macOS .pkg installer for Teleport, which includes the
tctl
andtsh
clients:curl -O https://cdn.teleport.dev/teleport-${TELEPORT_VERSION?}.pkgIn Finder double-click the
pkg
file to begin installation.dangerUsing Homebrew to install Teleport is not supported. The Teleport package in Homebrew is not maintained by Teleport and we can't guarantee its reliability or security.
curl.exe -O https://cdn.teleport.dev/teleport-v${TELEPORT_VERSION?}-windows-amd64-bin.zipUnzip the archive and move the `tctl` and `tsh` clients to your %PATH%
NOTE: Do not place the `tctl` and `tsh` clients in the System32 directory, as this can cause issues when using WinSCP.
Use %SystemRoot% (C:\Windows) or %USERPROFILE% (C:\Users\<username>) instead.
All of the Teleport binaries in Linux installations include the
tctl
andtsh
clients. For more options (including RPM/DEB packages and downloads for i386/ARM/ARM64) see our installation page.curl -O https://cdn.teleport.dev/teleport-v${TELEPORT_VERSION?}-linux-amd64-bin.tar.gztar -xzf teleport-v${TELEPORT_VERSION?}-linux-amd64-bin.tar.gzcd teleportsudo ./installTeleport binaries have been copied to /usr/local/bin
-
- 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, run the following command, assigning teleport.example.com to the domain name of the Teleport Proxy Service in your cluster and [email protected] to your Teleport username:If you can connect to the cluster and run thetsh login --proxy=teleport.example.com --user=[email protected]tctl statusCluster teleport.example.com
Version 19.0.0-dev
CA pin sha256:abdc1245efgh5678abdc1245efgh5678abdc1245efgh5678abdc1245efgh5678
tctl 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. - A Teleport user with permissions to create join tokens and other roles. We
recommend using a demo cluster with the preset
editor
role. - Docker installed on your workstation. Docker is only required for the local demo environment used in this guide. You can find installation instructions for Docker on Docker's website. If you want to register servers in Teleport without using Docker, see the getting started guide for server access.
Step 1/2. Enroll resources with labels
In this section, you will enroll two servers with your Teleport cluster. One
server will have the env:local-dev
label and the other will have the
env:local-prod
. Later in this guide, you will create a role that will allow a
user to access a server with the env:local-dev
label and deny access to the
env:local-prod
label.
Enroll a server with the env:local-dev
label
-
Create a join token for the server to use to join the cluster:
tctl tokens add --type=node -
Assign the token to token and the host and web port of your Teleport Proxy Service to example.teleport.sh:443.
-
Copy the following Teleport configuration to a file called
local-dev.yaml
:version: v3 teleport: data_dir: /var/lib/teleport join_params: token_name: token method: token proxy_server: example.teleport.sh:443 auth_service: enabled: "false" ssh_service: enabled: "true" labels: env: local-dev proxy_service: enabled: "false"
This Teleport configuration enables the Teleport SSH Service, which enrolls a server in your Teleport cluster. The
ssh_service.labels
field adds a label to the server calledenv:local
. -
Assign the absolute path to the configuration file you created to dev-config-path.
-
Start the Teleport SSH Service on a local Docker container with the configuration and join it to your cluster:
docker run -v dev-config-path:/etc/teleport/teleport.yaml public.ecr.aws/gravitational/teleport-ent-distroless-debug:13.3.7 -
Wait for a minute or so. Verify that you have logged in via tsh login and check that the server has joined your cluster by listing enrolled servers by label. You should see the server you just enrolled:
tsh ls env=local-devNode Name Address Labels------------ ---------- -------------80f60427d316 ⟵ Tunnel env=local-dev
Enroll a server with the env:local-prod
label
-
Open a separate terminal.
-
Create a join token for the server to use to join the cluster:
tctl tokens add --type=node -
Assign the token to token.
-
Copy the following YAML document to a file called
local-prod.yaml
. This configuration starts the Teleport SSH Service with the labelenv:local-prod
:version: v3 teleport: data_dir: /var/lib/teleport join_params: token_name: token method: token proxy_server: example.teleport.sh:443 auth_service: enabled: "false" ssh_service: enabled: "true" labels: env: local-prod proxy_service: enabled: "false"
-
Assign the absolute path to the configuration file you created to prod-config-path.
-
Start the Teleport SSH Service on a local Docker container with the configuration and join it to your cluster:
docker run -v prod-config-path:/etc/teleport/teleport.yaml public.ecr.aws/gravitational/teleport-ent-distroless-debug:13.3.7 -
Ensure that the server has joined the cluster:
tsh ls env=local-prodNode Name Address Labels------------ ---------- --------------ba2290caf694 ⟵ Tunnel env=local-prod
Step 2/3. Create a Teleport role
Create a role that can access servers with the env:local-dev
label but not the
env:local-prod
label.
-
Create a file called
role.yaml
with the following content:kind: role version: v7 metadata: name: local-dev-only spec: allow: logins: [root] node_labels: env: local-dev
The
allow
block indicates what the user is allowed to access. By default, nothing is allowed, so each role must include at least oneallow
field to provide permissions.The
spec.allow.logins
field allows the user to assume theroot
login when connecting to a server. You can change this to a less permissive login, but we are usingroot
because it is the only available login on the Docker containers we spun up.spec.allow.node_labels
uses wildcard syntax, which matches one or more characters, to allow users to connect to any server with a label that beginsenv:local-
, such as theenv:local-dev
andenv:local-prod
labels we assigned to our servers.However, since the
deny.node_labels
field specifiesenv:local-prod
, a user with this role would only be able to access the server with theenv:local-dev
label. -
Create the role:
tctl create role.yaml
Step 3/3. Access your server
In this step, you will create a local Teleport user with the local-dev-access
role, then list available servers and connect the one with the label
env:local-dev
.
-
Create a local user named
alice
with thelocal-dev-access
role:tctl users add alice --roles=local-dev-access -
Follow the instructions in your terminal to sign in as
alice
. -
In your terminal, log out of your cluster and log in again, assigning example.teleport.sh to the domain name of your Teleport Proxy Service:
tsh logouttsh login --user=alice --proxy=example.teleport.sh -
List all servers available for your user to access. You should only see one:
tsh lsNode Name Address Labels------------ ---------- -------------ba2290caf694 ⟵ Tunnel env=local-devSince
alice
is denied access to servers with theenv:local-prod
label, only the server with theenv:local-dev
label is available to connect to. -
Access the server using the value of the
Node Name
field as shown intsh ls
. Assign ba2290caf694 to then ame of your server:tsh ssh root@ba2290caf694
Next steps
In this guide, you created a Teleport role that allowed and denied access to SSH servers based on the labels that the servers were enrolled with. Read about more things you can do with Teleport roles.
Learn more Teleport RBAC fundamentals
Read more about using Teleport roles to govern RBAC:\
Configure RBAC for specific kinds of resources
You can label all Teleport-protected resources and use those labels to set RBAC policies. In addition, each kind of Teleport resource also has more specific attributes that you can use to control access. Read the guides below to refine your RBAC for each kind of resource:
Reference guide
For a full description of the fields you can configure in a Teleport role, see the Teleport Access Controls Reference.