What Does This Tool Do?
pg_vault_rotate rotates the active database credentials of an existing Vault connection. It revokes the old lease in Vault, fetches fresh credentials from the Database Secret Engine, and automatically rebuilds the connection pool with the new user. Since this terminates active connections, the tool requires explicit confirmation (confirm: true).
How Is It Called?
Step 1: Establish Vault Connection
Before credentials can be rotated, a Vault connection must exist. The MCP server supports multiple simultaneous connections:
▶ Calling tools...
→ pg_vault_connect { "profile": "production" }
Connected via Vault:
Status: connected
Profile: production
Vault Role: pg-readonly
Username: v-approle-pg-readon-x9k2m
Step 2: Claude CLI (Natural Language)
▶ Calling tools...
→ pg_vault_rotate { "profile": "production", "confirm": true }
Credentials rotated:
Rotated: yes
Old Lease: revoked
New Username: v-approle-pg-readon-m7j4p
New Lease TTL: 3600s
Pool Reconnected: yes
MCP Protocol (Programmatic)
The following output is representative of Vault E2E tests — the structure matches the real tool output format (Vault tests run separately with VAULT_ADDR):
const result = await client.callTool("pg_vault_rotate", { "profile": "production", "confirm": true });
// Response:
{
"rotated": true,
"old_lease": "revoked",
"new_username": "v-approle-pg-readon-m7j4p",
"new_lease_ttl": 3600,
"pool_reconnected": true
}
What Happens Under the Hood?
Like pg_vault_connect, this tool executes no SQL. The entire workflow consists of Vault API calls and pool management:
- Revoke Lease —
PUT /v1/sys/leases/revokewith the active lease ID. Vault deletes the dynamic PostgreSQL user immediately. - Fetch New Credentials —
GET /v1/database/creds/{role}. Vault creates a new dynamic user. - Disconnect Pool —
pool.end()terminates all active connections in the old pool. - Rebuild Pool —
new Pool()with the new username and password. Connection verified withSELECT 1.
Why confirm: true? Rotation is a destructive operation. Active queries are aborted when the old pool is closed. In production environments, rotation should only be performed during planned maintenance windows or in response to security incidents.
Output in Detail
- rotated —
trueif rotation succeeded - old_lease — Status of the old lease (
revoked) - new_username — The freshly generated PostgreSQL username
- new_lease_ttl — Validity of the new credentials in seconds
- pool_reconnected —
trueif the new pool was successfully verified
What Does the Test Suite Validate?
The test suite validates pg_vault_rotate with an active Vault lease from pg_vault_connect:
✓ pg_vault_rotate > rotates credentials with confirm (new username, old lease revoked)
Test Files 1 passed (1)
Tests 2 passed (2)
Duration 1204ms
Test Data Scenario
The test environment requires an existing Vault connection:
- Active Vault Lease — Established by a prior
pg_vault_connectcall - Database Secret Engine — Vault role
pg-readonlywith dynamic user creation - PostgreSQL — Target database with Vault-managed users
Tests validate that:
- Without
confirm: true, rotation is rejected with a clear error message — no accidental rotations - With
confirm: true, a new username is generated, the old lease has statusrevoked, and the pool is reconnected
Summary
pg_vault_rotate is the emergency tool for compromised credentials and the routine tool for planned rotations. Combined with pg_vault_connect, it provides a complete credential lifecycle without static passwords.
Together with pg_vault_connect (→ initial connection) and pg_hba_analyze (→ authentication audit), it belongs to the /pg-security workflow skill.