TheDocumentation 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.
github.com/gravitational/teleport/api/client package provides an official Go client for the Teleport Auth Service gRPC API. You can use this client to build custom automation — provisioning users, managing roles, listing infrastructure, processing Access Requests, and more — using the same API that tctl, the Terraform provider, and the Kubernetes operator all use.
The client automatically handles TLS certificate rotation, retries, and connection multiplexing, so you can focus on your business logic.
Installation
Pin the client module to the major version of your Teleport cluster to ensure API compatibility. Check the Go module proxy for available versions:
Connecting to a cluster
client.New
New opens a gRPC connection to a Teleport Auth or Proxy Service using the provided configuration and credentials. It tries all combinations of addresses and credentials and returns the first successful connection.
client.Config fields
| Field | Type | Description |
|---|---|---|
Addrs | []string | Addresses to try: Auth Service (host:3025), Proxy HTTPS (host:443), or Proxy SSH (host:3080). |
Credentials | []Credentials | One or more credential sources (see below). |
Dialer | ContextDialer | Optional custom dialer for use with reverse tunnels or proxies. |
DialInBackground | bool | Don’t block New on connection establishment. |
ALPNSNIAuthDialClusterName | string | Cluster name for TLS Routing through a Proxy Service. |
Authentication / credential sources
LoadProfile — use current tsh login session
LoadProfile — use current tsh login session
The simplest approach for development. Reads credentials from the
tsh profile on disk.LoadIdentityFile — use an exported identity file
LoadIdentityFile — use an exported identity file
tbot (Machine ID) can output identity files that contain a TLS certificate, private key, and CA chain. Use this for production automation.tbot or for a one-off:LoadTLS — use a crypto/tls.Config directly
LoadTLS — use a crypto/tls.Config directly
For advanced scenarios where you manage your own certificate rotation:
Key client methods
All methods accept acontext.Context as their first argument. Pass a context with a timeout or cancellation signal to avoid blocking indefinitely.
Node management
GetNodes
Returns all SSH nodes registered in a namespace. Use defaults.Namespace ("default") for the standard namespace.
Role management
GetRoles
Returns all roles in the cluster.
CreateRole
Creates a new role. Returns an error if the role already exists.
UpsertRole
Creates a role or replaces an existing role with the same name.
DeleteRole
Deletes a role by name.
User management
GetUsers
Returns all local users. Pass withSecrets = false for read-only access; true also returns password hashes (requires elevated permissions).
CreateUser
Creates a new local user.
DeleteUser
Deletes a user by username.
Token management
CreateToken
Creates a new provisioning (join) token.
GetTokens
Returns all provisioning tokens.
Database, Kubernetes, and Application servers
GetDatabaseServers
Returns all database server instances (not the database resources themselves).
GetKubernetesServers
Returns all Kubernetes Service instances.
GetApplicationServers
Returns all Application Service instances.
GetApps
Returns all Application resources (the registered apps, not the service instances).
Access Requests
SubmitAccessReview
Approves or denies an Access Request, optionally adding a review note.
Complete example: connect and list nodes
The following program connects to a Teleport cluster using the currenttsh profile, lists all SSH nodes, and prints their names and labels.
Authentication patterns
tsh Profile (development)
Call
client.LoadProfile("", "") after tsh login. The profile is read from ~/.tsh/ automatically. TTL is capped by the cluster’s max_session_ttl setting.Identity File (production)
Use
tbot to continuously renew an identity file and load it with client.LoadIdentityFile("/path"). Certificates can be as short as 1 minute for zero-standing-privilege automation.TLS Config (advanced)
Build a
crypto/tls.Config manually and pass it to client.LoadTLS(tlsCfg). Useful when certificates are managed by an external PKI or rotated by a sidecar.Environment Variables
TELEPORT_IDENTITY_FILE, TELEPORT_IDENTITY_FILE_NO_CREDENTIALS, and TELEPORT_AUTH_SERVER are read automatically by client.LoadProfile when set. Useful for containerised workloads.