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.
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.
via Teleport
via VNet
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.
tsh db ls --format=jsonFind 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.
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
- PostgreSQL guide: Run a demo PostgreSQL database and connect to it from a beam with read-only access.
- Enroll other databases in Teleport: Choose the enrollment instructions for your database engine and environment.