PostgreSQL is one of the supported plugins for the database secrets engine. This
plugin generates database credentials dynamically based on configured roles for
the PostgreSQL database, and also supports Static
Roles.
See the database secrets engine docs for
more information about setting up the database secrets engine.
The PostgreSQL secrets engine uses
pq, the same database
library as the PostgreSQL storage
backend. Connection string
options, including SSL options, can be found
here
Configure a role that maps a name in Vault to an SQL statement to execute to
create the database credential:
$ vault write database/roles/my-role \
db_name=my-postgresql-database \
creation_statements="CREATE ROLE \"{{name}}\" WITH LOGIN PASSWORD '{{password}}' VALID UNTIL '{{expiration}}'; \
GRANT SELECT ON ALL TABLES IN SCHEMA public TO \"{{name}}\";" \
default_ttl="1h" \
max_ttl="24h"
Success! Data written to: database/roles/my-role
$ vault write database/roles/my-role \ db_name=my-postgresql-database \ creation_statements="CREATE ROLE \"{{name}}\" WITH LOGIN PASSWORD '{{password}}' VALID UNTIL '{{expiration}}'; \ GRANT SELECT ON ALL TABLES IN SCHEMA public TO \"{{name}}\";" \ default_ttl="1h" \ max_ttl="24h"Success! Data written to: database/roles/my-role