Skip to content

Database Access via Teleport

Use this guide to connect to a PostgreSQL database shell using Teleport’s tsh command-line tool. If you prefer, you can alternatively open a session directly through the web UI.

  • Teleport access via Okta (see getting access).

  • tsh is installed (see installation instructions).

  • psql installed. It is recommended to install it via Homebrew as the mise or asdf builds lack the OpenSSL support required by Teleport and will cause SSL errors.

    Terminal window
    brew install postgresql@14
  1. Identify the role you need:

    DatabaseEnvAccess typeRole
    main, ci, or secNon-prodRead-onlyNo request needed, skip to Log in.
    main, ci, or secNon-prodRead/writenon-prod-database-rw
    registryNon-prodRead-onlyNo request needed, skip to Log in.
    registryNon-prodRead/writenon-prod-database-registry-rw
    main, ci, or secProdRead-onlyprod-database-ro
    main, ci, or secProdRead/writeprod-database-rw
    registryProdRead-onlyprod-database-registry-ro
    registryProdRead/writeprod-database-registry-rw
  2. Log in to Teleport:

    Terminal window
    tsh login --proxy=production.teleport.gitlab.net
  3. Request the role:

    Terminal window
    tsh request create \
    --roles=<Role> \
    --reason="<GitLab issue URL / ZenDesk ticket URL>"
  4. An automated message will appear in the #teleport-requests Slack channel. If you’re a member of Engineering or Security, tag your direct manager to review the request. Otherwise, ask in the #eng-managers channel for review by any available engineering manager.

    For more information, refer to the Teleport Approver Workflow.

  5. Once approved, the Slack bot will notify you in #teleport-requests.

  1. Log in to tsh again, providing the ID of your approved access request

    Terminal window
    tsh login --request-id=<request-id>
  2. Gather the necessary details

    Three items of information are needed to log into a database:

    • db-user: console-ro for read-only, or console-rw for read/write
    • db-name: Usually gitlabhq_production, or gitlabhq_registry for registry dbs
    • Teleport database name (db): Can be found using tsh db ls. Common database names are also listed below for your convenience.
    Terminal window
    tsh db ls # all registered databases
    tsh db ls environment=gstg # non-production
    tsh db ls environment=gprd # production
  3. Log in to retrieve database credentials

    Terminal window
    tsh db login \
    --db-user=<db-user> \ # `console-ro` or `console-rw`
    --db-name=<db-name> \ # usually `gitlabhq_production`
    <db> # See "Gather the necessary details" above
  4. Connect to the database shell:

    Terminal window
    tsh db connect <Database Name>

The database-admin role grants superuser access to any database.

Terminal window
tsh request create \
--proxy=production.teleport.gitlab.net \
--request-roles=database-admin \
--request-reason="<GitLab issue URL or ZenDesk ticket URL>"
tsh login --request-id=<request-id>
  • Access requests are temporary and expire after 12 hours, but may be used across multiple sessions. Renew it before or after expiration using the same request process.
  • Learn how to connect a database GUI client such as pgadmin in Teleport’s docs
  • For help with Teleport or the approval process, ask in #security_help.
  • To report a Teleport bug, open an issue with Infrastructure Security.
DescriptionEnvdbdb-name
MainNon-proddb-main-replica-gstggitlabhq_production
CINon-proddb-ci-replica-gstggitlabhq_production
SecurityNon-proddb-sec-replica-gprdgitlabhq_production
RegistryNon-proddb-registry-replica-gstggitlabhq_registry
DR archive — mainNon-proddb-main-dr-archive-gstggitlabhq_production
DR archive — CINon-proddb-ci-dr-archive-gstggitlabhq_production
DR archive — registryNon-proddb-registry-dr-archive-gstggitlabhq_registry
MainProddb-main-replica-gprdgitlabhq_production
CIProddb-ci-replica-gprdgitlabhq_production
SecurityProddb-sec-replica-gprdgitlabhq_production
RegistryProddb-registry-replica-gprdgitlabhq_registry
DR archive — mainProddb-main-dr-archive-gprdgitlabhq_production
DR archive — CIProddb-ci-dr-archive-gprdgitlabhq_production
DR archive — registryProddb-registry-dr-archive-gprdgitlabhq_registry

tsh request create will wait for approval and return once the request is approved, denied, or expires.

If it times out before a decision, check #teleport-requests slack channel or the Teleport Web UI for the request ID — you don’t need to re-request if it was approved.

psql: error: could not connect to server: Connection refused

Section titled “psql: error: could not connect to server: Connection refused”

The local psql client may be overriding the user and database name. Pass them explicitly:

Terminal window
tsh db connect \
--db-user=console-ro \
--db-name=<gitlabhq_production|gitlabhq_registry> \
<database_name>

psql: error: SSL SYSCALL error: ... signal: segmentation fault

Section titled “psql: error: SSL SYSCALL error: ... signal: segmentation fault”

This occurs when psql is installed via asdf or mise. Use the Homebrew version instead:

  1. Install via Homebrew if not already done:

    Terminal window
    brew install postgresql@14
  2. Get the full connection command from tsh:

    Terminal window
    tsh db config --format=cmd <database_name>
  3. Re-run the command, replacing the psql binary path with the Homebrew one:

    Terminal window
    $(brew --prefix postgresql@14)/bin/psql "<connection string from step 2>"

psql: error: sslmode value "verify-full" invalid when SSL support is not compiled in

Section titled “psql: error: sslmode value "verify-full" invalid when SSL support is not compiled in”

Your psql binary was not compiled with OpenSSL support. Switch to the Homebrew version as described above.

failed to add one or more keys to the agent

Section titled “failed to add one or more keys to the agent”

See getting_access.md — Troubleshooting.

Terminal window
tsh --debug db connect <database_name>