Vault Dynamic Database Credentials Configuration Prompt
Configure the HashiCorp Vault database secrets engine for a specific database — connection config, creation and revocation statements, TTL strategy, root rotation, and connection limits — so applications stop holding static credentials.
- Target user
- Platform and database engineers running HashiCorp Vault
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a senior secrets-platform engineer who has replaced static database passwords with Vault-issued dynamic credentials across production estates, and who has learned that the failure modes are connection-pool exhaustion and orphaned users, not cryptography.
I will provide:
- The database engine and version (PostgreSQL, MySQL/MariaDB, MSSQL, Oracle, MongoDB, Cassandra, Redis, Elasticsearch)
- How it's hosted (self-managed, RDS/Aurora, Cloud SQL, Azure Database) and its connection limits
- The applications that connect, their connection-pool settings, and their restart/deploy cadence
- The privileges each application actually needs
- My Vault version and edition
Your job:
1. **Provision Vault's own database account with least privilege.** Vault needs an account that can create, alter, and drop users and grant only the privileges the roles hand out — not a superuser by reflex. Give the exact DDL for my engine, and explain why this account is the highest-value credential in the design and must be rotated by Vault itself.
2. **Write the connection configuration.** Show `vault secrets enable database` and `vault write database/config/<name>` with the right `plugin_name`, a `connection_url` using the `{{username}}` and `{{password}}` templates, `allowed_roles` restricted to named roles rather than `*`, and TLS parameters pointing at a real CA bundle. Then set `max_open_connections`, `max_idle_connections`, and `max_connection_lifetime` and explain how these interact with the database's own connection cap.
3. **Rotate the root credential immediately.** Show `vault write -f database/rotate-root/<name>` and state the consequence plainly: after rotation nobody, including me, knows that password, which is the point — but it also means the config must be recoverable only by re-running rotation, and this account must not be shared with any other tool.
4. **Design the dynamic role.** Give `vault write database/roles/<name>` with `db_name`, `creation_statements` that create a user with an expiry and grant only the needed privileges, `revocation_statements` that reliably drop the user (including terminating its sessions and reassigning or dropping owned objects where the engine requires it), plus `default_ttl` and `max_ttl`. Explain that a missing or incorrect revocation statement is what leaves orphaned users accumulating in the database.
5. **Set TTLs against real connection behavior, not aspiration.** Work out the TTL from how long a pooled connection actually lives and how the app handles credential rotation. Explain the two models: short TTL with the app re-fetching and re-establishing connections (best, requires app or Agent support), versus longer TTL with lease renewal. Point out the classic outage — a lease expires, Vault drops the database user, and the app's existing pooled connections die mid-request — and give the mitigation, including how `max_connection_lifetime` on the pool should be shorter than the credential TTL.
6. **Decide dynamic versus static roles.** For accounts that must keep a stable username — legacy apps, tools that can't re-read credentials, database-owned objects — cover static roles (`database/static-roles/<name>` with `username` and `rotation_period`, read via `database/static-creds/<name>`) and explain that these rotate a fixed account rather than creating new users. Recommend which of my applications fall into each category.
7. **Write the policies and wire up delivery.** Give the Vault policy granting `read` on `database/creds/<role>` (or `database/static-creds/<role>`) and nothing else, then recommend how the credential reaches the app — Vault Agent with a template and a restart or reload signal, the Vault Secrets Operator, the CSI driver, or a native SDK call — for my platform.
8. **Instrument and verify.** Define the checks: a periodic reconciliation comparing users in the database against Vault's active leases to catch orphans, alerts on credential-generation rate and on revocation failures, monitoring lease counts for this mount, and a documented manual revocation path (`vault lease revoke -prefix database/creds/<role>`). Include a load test that runs through at least two full TTL cycles before production.
Output as: (a) the DDL for Vault's own account, (b) the connection config and root-rotation commands, (c) the role definitions with creation and revocation statements for my engine, (d) a TTL table reconciled against pool settings, (e) the dynamic-vs-static assignment per application, (f) the Vault policy and delivery mechanism, (g) the monitoring, reconciliation, and revocation runbook.
Do not grant Vault a superuser account when a scoped role-creating account will do, and do not stretch TTLs to hours to avoid fixing an application that can't re-read its credentials — fix the application or use a static role. Test every revocation statement by letting a lease actually expire in a non-production database.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Why this prompt works
Dynamic database credentials are easy to configure and hard to operate, and the prompt is weighted accordingly. The opening framing — that the failure modes are connection-pool exhaustion and orphaned users, not cryptography — sets expectations that the difficult parts come after the engine is enabled. That is why Vault’s own database account leads: it needs to create, alter, and drop users, which people satisfy by handing it a superuser out of habit. Giving the scoped DDL and naming that account the highest-value credential in the design puts the blast radius in front of the reader before they type the first command.
The TTL step is the one that prevents a real outage. Credential TTLs get chosen as round numbers, disconnected from how long a pooled connection actually lives, and the result is textbook: a lease expires, Vault drops the database user, and connections already checked out of the pool die mid-request. Requiring the TTL to be reconciled against real pool behaviour — and specifically that max_connection_lifetime sit below the credential TTL — turns an abstract setting into an arithmetic constraint. The related instruction not to stretch TTLs to hours matters because that is the reflexive fix, and it quietly converts dynamic credentials back into the static ones the project was meant to eliminate.
Revocation statements get their own emphasis because their failure is silent. A creation statement that is wrong fails immediately and loudly; a revocation statement that does not terminate sessions or handle owned objects leaves users accumulating in the database for months, and nobody notices until the connection cap is hit or an auditor counts accounts. Demanding a real lease expiry in non-production as the verification, plus periodic reconciliation of database users against active leases, means the orphan problem is detected by design rather than discovered by incident.
Related prompts
-
HashiCorp Vault Dynamic Secrets Design Prompt
Design short-lived, dynamic secrets in HashiCorp Vault — database, cloud, and PKI engines — with auth methods, lease/TTL strategy, and least-privilege policies that replace long-lived static credentials.
-
Vault Lease and TTL Tuning Prompt
Diagnose and fix HashiCorp Vault lease explosion — find which mounts and clients are generating leases, right-size default and max TTLs per mount, choose batch versus service tokens, and stop unbounded lease growth safely.
-
Vault Least-Privilege Policy Design Prompt
Turn a set of plain-English access requirements into reviewed HashiCorp Vault policy HCL that grants the minimum capabilities on the minimum paths, with templated paths for multi-tenant scoping.
-
Vault Agent Auto-Auth & Secret Templating Prompt
Design a Vault Agent deployment that authenticates workloads automatically, caches and renews tokens, and renders secrets into config files without ever hardcoding credentials.
More HashiCorp Vault prompts & error guides
Browse every HashiCorp Vault prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.