Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/gravitational/teleport/llms.txt

Use this file to discover all available pages before exploring further.

Teleport roles are the primary mechanism for controlling what users can access and what they can do inside a Teleport cluster. Every role is a YAML document that describes two lists of rules — allow and deny — plus a set of behavioral options. Deny rules take priority over allow rules, and nothing is allowed by default. You can manage roles through the Teleport Web UI, with tctl, the Terraform provider, or the Kubernetes operator.
# View all roles in your cluster
tsh login --proxy=example.teleport.sh --user=myuser
tctl get roles

Full role spec

The following YAML shows every commonly used field in a role resource. Fields marked (optional) can be omitted:
kind: role
version: v8           # v3–v8 supported; v8 is current
metadata:
  name: example-role
  description: "Example role showing all major fields"
spec:
  # allow rules grant access when matched
  allow:
    # SSH logins the user may assume on Linux servers
    logins:
      - "{{internal.logins}}"
      - ubuntu
      - ec2-user

    # Kubernetes principals
    kubernetes_groups:
      - "{{internal.kubernetes_groups}}"
      - developers
    kubernetes_users:
      - "{{internal.kubernetes_users}}"

    # Database access
    db_names:
      - "{{internal.db_names}}"
      - "*"
    db_users:
      - "{{internal.db_users}}"
      - alice
    db_roles:
      - reader

    # Resource label selectors (all must match — logical AND across keys)
    node_labels:
      env: production
      team: platform
    app_labels:
      env: production
    kubernetes_labels:
      env: "*"          # wildcard matches any value
    db_labels:
      env: production
    windows_desktop_labels:
      env: production

    # Label expression (alternative to label maps, supports OR / AND / NOT)
    node_labels_expression: |
      labels["env"] == "production" ||
      contains(user.spec.traits["teams"], labels["team"])

    # Windows logins
    windows_desktop_logins:
      - Administrator
      - "{{internal.windows_logins}}"

    # RBAC for Teleport resources (who can manage what via tctl/API)
    rules:
      - resources: [role, auth_connector, user, token]
        verbs: [list, create, read, update, delete]
      - resources: [session]
        verbs: [list, read]
      - resources: [event]
        verbs: [list, read]

    # Access Requests — which roles a user may request
    request:
      roles:
        - prod-access
      search_as_roles:
        - prod-access
      max_duration: 8h
      reason:
        mode: required

    # Review permissions — which requests this role may review
    review_requests:
      roles:
        - prod-access
      preview_as_roles:
        - prod-access

  # deny rules override allow rules
  deny:
    node_labels:
      env: "lab"
    logins:
      - root

  # options control session behavior
  options:
    max_session_ttl: 12h
    forward_agent: true
    ssh_port_forwarding:
      local:
        enabled: true
      remote:
        enabled: false
    ssh_file_copy: true
    client_idle_timeout: 30m
    disconnect_expired_cert: false
    require_session_mfa: "no"     # no | yes | hardware_key | hardware_key_touch
    device_trust_mode: "optional" # off | optional | required | required-for-humans
    record_session:
      default: "best_effort"
    create_host_user_mode: "keep" # off | keep | insecure-drop
    create_db_user_mode: "off"    # off | keep | best_effort_drop
    max_connections: 0            # 0 = unlimited
    lock: "best_effort"           # best_effort | strict
    desktop_clipboard: true
    desktop_directory_sharing: true

allow and deny blocks

Label selectors

Label selectors restrict which enrolled resources a user can access. Each key-value pair in a map is a logical AND; multiple values for the same key are an OR.
allow:
  db_labels:
    env: production          # AND
    region: [us-east-1, eu-west-1]   # OR within the key
A wildcard "*": "*" grants access to all resources of that type. Role versions v3 and below defaulted to this; v4 and higher default to an empty set (no access).

Principal fields

These fields set the principals (logins, groups, database users, etc.) a user can assume when connecting to resources:
FieldResource Type
loginsSSH login username on Linux servers
windows_desktop_loginsWindows login username
kubernetes_groupsKubernetes groups to impersonate
kubernetes_usersKubernetes users to impersonate
db_namesDatabase names accessible within a server
db_usersDatabase user accounts
db_rolesDatabase roles (for auto-provisioning)
aws_role_arnsAWS IAM roles accessible via App Service
azure_identitiesAzure managed identities
gcp_service_accountsGCP service accounts

RBAC rules for Teleport resources

The rules field controls which Teleport API resources users can manage via tctl, the Web UI, or the API:
allow:
  rules:
    - resources: [node, app, db, kube_cluster, windows_desktop]
      verbs: [list, read]
    - resources: [role]
      verbs: [list, create, read, update, delete]
    - resources: [session]
      verbs: [list, read]
      where: contains(session.participants, user.metadata.name)
Available verbs: list, create, read, update, delete. The where clause filters access to individual resources using a predicate expression.

options block reference

OptionTypeMulti-role behaviorDescription
max_session_ttldurationShortest winsMaximum certificate lifetime.
forward_agentboolORAllow SSH agent forwarding.
ssh_port_forwardingobjectANDAllow TCP port forwarding (local/remote).
ssh_file_copyboolANDAllow SCP/SFTP file transfers.
client_idle_timeoutdurationShortest winsDisconnect idle sessions.
disconnect_expired_certboolORDisconnect when certificate expires.
require_session_mfastringORPer-session MFA requirement.
device_trust_modestringRequire verified device access.
max_sessionsintLowest winsMax concurrent sessions per SSH connection.
max_connectionsintLowest winsMax concurrent Teleport sessions per user.
record_sessionobjectStrictest winsSession recording mode.
create_host_user_modestringANDAuto-create Linux host user.
create_db_user_modestringORAuto-provision database user.
lockstringstrict winsLocking mode.
desktop_clipboardboolANDAllow clipboard sharing for RDP sessions.
desktop_directory_sharingboolANDAllow local directory sharing for RDP.
pin_source_ipboolORPin SSH certs to the source IP.

Template variables

Role fields support template variables that are expanded at login time using traits from the Teleport user database or an SSO provider.

Internal traits (local users)

VariableExpands to
{{internal.logins}}SSH logins configured on the user record.
{{internal.kubernetes_groups}}Kubernetes groups configured on the user record.
{{internal.kubernetes_users}}Kubernetes users configured on the user record.
{{internal.db_names}}Database names configured on the user record.
{{internal.db_users}}Database users configured on the user record.
{{internal.windows_logins}}Windows logins configured on the user record.
{{internal.aws_role_arns}}AWS role ARNs configured on the user record.

External traits (SSO providers)

SSO providers populate external traits from SAML attributes or OIDC claims:
VariableExpands to
{{external.groups}}Value of the groups claim/attribute from the IdP.
{{external.username}}Value of the username claim/attribute.
{{external.email}}User’s email address from the IdP.
{{external["http://schemas.example.com/attr"]}}Bracket notation for attribute URIs.

Template functions

FunctionDescription
{{email.local(variable)}}Extracts the local part of an email (before @).
{{regexp.replace(variable, pattern, replacement)}}Regex substitution in a trait value.

Other variables

VariableDescription
{{user.metadata.name}}The Teleport username; useful for ownership-based access.

Example roles

Admin role

Full administrative access to the cluster:
kind: role
version: v8
metadata:
  name: admin
spec:
  allow:
    logins: ["root", "ubuntu", "{{internal.logins}}"]
    node_labels:
      "*": "*"
    db_labels:
      "*": "*"
    kubernetes_labels:
      "*": "*"
    kubernetes_groups: ["system:masters"]
    app_labels:
      "*": "*"
    windows_desktop_labels:
      "*": "*"
    rules:
      - resources: ["*"]
        verbs: ["*"]
  options:
    max_session_ttl: 24h
    forward_agent: true

Developer role

Production read access with the ability to request elevated privileges:
kind: role
version: v8
metadata:
  name: developer
spec:
  allow:
    logins: ["{{internal.logins}}", "dev"]
    node_labels:
      env: staging
    db_names: ["{{internal.db_names}}"]
    db_users: ["{{internal.db_users}}"]
    db_labels:
      env: staging
    kubernetes_labels:
      env: staging
    kubernetes_groups: ["developers"]
    app_labels:
      env: staging
    request:
      roles: [prod-access]
      reason:
        mode: required
  options:
    max_session_ttl: 8h
    require_session_mfa: "yes"

Read-only auditor role

View sessions and events but no infrastructure access:
kind: role
version: v8
metadata:
  name: auditor
spec:
  allow:
    rules:
      - resources: [session, event]
        verbs: [list, read]
      - resources: [node, app, db, kube_cluster]
        verbs: [list, read]
  options:
    max_session_ttl: 4h

Managing roles with tctl

1

List all roles

tctl get roles
To see a single role in YAML format:
tctl get role/developer --format=yaml
2

Create or update a role from a file

# Create (or update) a role from a YAML file
tctl create -f developer-role.yaml
3

Edit a role interactively

# Opens the role in $EDITOR
tctl edit role/developer
4

Delete a role

tctl rm role/developer
Deleting a role that is assigned to users will not immediately revoke their active sessions, but they will lose access on their next login or certificate renewal.

Build docs developers (and LLMs) love