Skip to content

Databases

Connect directly to authorized databases from a beam.

Build with agents
On this page

Use a native database client inside a beam to connect to a database enrolled in Teleport. The database stays on its private network.

Connect through the virtual network

A Teleport agent running the Database Service can reach the database and dials out to your Teleport cluster. The outbound tunnel makes the database reachable from the Beams runtime without opening an inbound port on your database network.

Inside the beam, connect to the database’s VNet hostname. The virtual network routes the connection through Teleport to the Database Service, which connects to the database. The beam’s delegated roles determine which databases and database users it can access.

Private database access from a beam

The Teleport agent dials out. The database client connects through VNet.

The Teleport agent initiates the outbound tunnel via Teleport. The database client in the Beams runtime initiates a connection through VNet, and the agent forwards it to the private database.

Beams runtime Database client
Outbound tunnel
via Teleport
Database connection
via VNet
Private network
Teleport agent Database Service
Database

Connect to PostgreSQL

Run these commands inside the beam. Make sure psql (the PostgreSQL command-line client) is installed there; psql --version checks it. You also need an enrolled PostgreSQL database and a delegated role that allows access as the database user you intend to use.

CLI · Inside the beam
tsh db ls --format=json

Find the entry for your database and copy its status.vnet_dns_name. This DNS label can differ from the Teleport resource name. If the database isn’t listed, check the beam’s delegated roles before continuing.

Replace example-postgres below with that DNS label, readonly with your allowed PostgreSQL user, and postgres with the database name. $TELEPORT_CLUSTER is already set inside the beam. Use sslmode=disable because the local VNet connection accepts cleartext and Teleport secures the tunnel.

CLI · Inside the beam
psql -w "host=example-postgres.db.$TELEPORT_CLUSTER port=5432 user=readonly dbname=postgres sslmode=disable" \
  -v ON_ERROR_STOP=1 -c 'SELECT current_user, current_database();'

Confirm the returned current_user and current_database match the user and database you intended to connect to. The -w flag prevents a password prompt; VNet uses the beam’s Teleport identity.

Get started

Search docs

Loading search and AI…

Skills

Install all available skills. All Beams and Teleport skills are hosted in our OSS Teleport repository.

npx skills add https://github.com/gravitational/teleport