Configure dedicated connections to external database accounts
Vault Enterprise feature
To perform the steps in this tutorial use must use Vault Enterprise 1.18 or later.
In the dynamic secrets tutorial, you configured Vault to generate dynamic credentials for a PostgreSQL database. In this tutorial, you will learn how to configure Vault Enterprise to manage existing database accounts.
If you are not familar with how to configure Vault for dynamic credentials, follow the database secrets engine tutorial before you begin.
Scenario
HashiCups configured Vault to generate dynamic credentials for PostgreSQL. Steve and the SRE team needs to access PostgreSQL for troubleshooting with existing roles where the role name does not change, but want Vault to manage and rotate passwords.
Oliver from the operations team will need to configure Vault to manage credentials for static database roles. These roles are not created by Vault, but Vault will manage the passwords for these roles.
Prerequisites
This lab was tested on macOS using an x86_64 based and Apple silicon-based processors. You may also run this tutorial by clicking the Start interactive lab button.
To perform the tasks described in this tutorial, you need to have:
- Docker to run a Vault and PostgreSQL container.
- Vault binary installed.
- Git installed.
- Rootless static role password rotation requires HashiCorp Vault Enterprise and license key. For more information on installing a Vault enterprise license, refer to the Install a HashiCorp Enterprise license page.
Set up the lab
Open a terminal and export an environment variable with a valid Vault Enterprise license.
Clone the
learn-vault-dynamic-credentials
repository.Change into the
learn-vault-dynamic-credentials
directory.Deploy the Vault Enterprise and PostgreSQL containers.
Example output:
Copy the export command from the Terraform output and export the environment variables.
Example:
Verify the PostgreSQL and Vault containers have started.
Vault and PostgreSQL are running. You are ready to proceed with the tutorial.
Rootless static role rotation
A database secrets engine requires the configuration of a root connection with privileged database account. With this root connection, users are able to use Vault features like access-control and lease management to allow database roles and create new database users/credentials. The Databases section of the Vault documentation has details on the database secrets engine feature-set.
Initialization of a new database configuration creates this highly privileged connection over which all database resources are managed. These "Vault-managed" connections are responsible for making all the necessary queries/commands to the database to create, read, update, and delete users/credentials within the database.
Not only do these connections have excessive privileges, but each database connection requires individual setup. At a large enterprise, this results in hundreds of CLI commands or giant Terraform modules.
Administering hundreds of privileged accounts is also untenable, with creation and maintenance of these accounts being a burden on the Vault operator.
Static roles are a 1-to-1 mapping of a Vault role to a user in a database. With static roles, Vault stores and automatically rotates passwords for the associated database user based on a configurable period of time or rotation schedule. Static roles use the default database connection with unnecessarily high privileges for most use cases.
Rootless static role rotation enables customers to configure dedicated connections to external "self-managed" database accounts with lower-levels of privilege. Each connection maps to a static role with limited privileges, instead of managing all resources in Vault with a single "Vault-managed" dedicated connection to a highly privileged account.
Rootless static roles offer these advantages:
- Create static roles as needed to prevent long-lived user accounts, and reduce risk of leaked credentials.
- Vault does not store the root database credentials.
- Database administrators can trace actions back to specific users.
Configure PostgreSQL
Create a new user for use with rootless static roles.
Verify the user creation.
Create a table in the root database.
Write sample data to the table.
Grant
staticuser_pg
SELECT privileges on thecities
table.Check the permissions for
staticuser_pg
.Example output:
Configure Vault for rootless static role rotation
Enable the database secrets engine.
Create a connection configuration for the
postgresql-database-plugin
.The
self_managed
field on root configuration configuresdatabase
secrets engine to use the dedicated connection for thestaticuser
role.Create the
staticuser
role specified inallowed_roles
field in the database configuration.The
db_name
field indicates that this user has access to thepostgres-db-rootless
database connection, and credentials for static roles are automatically rotated based on therotation_period
. Theusername
field is referring to thestaticuser_pg
on the PostgresSQL side.Read the credentials from the
statcuser
role.Notice the username is the PostgreSQL user created earlier, it has an initial password that is different than was originally set (
staticpassrootless
) and the password will change in 5 minutes.Log in and query the cities table to verify the connection to PostgreSQL with the new
staticuser_pg
password.Enter the password from the
vault read
command.Example:
The static user
staticuser_pg
can access thecities
table with the password managed by Vault.
Clean up
Destroy the Terraform resources.
Unset the environment variables.
Summary
In this tutorial, you learned how to configure Vault Enterprise to manage static roles for existing database accounts. You created a new user in PostgreSQL and configured Vault to manage the role's password.