Database role
Maps a request to SQL creation and revocation statements.
Chapter 8 of 16 · Application/workload user · orders-api
Replace a shared database password with leased PostgreSQL users, least privilege, pool rotation, and revocation.
Chapter 7 complete, PostgreSQL healthy, and the learner token available.
orders-api can query PostgreSQL with a unique leased principal and prove revocation on a new connection.
| Owner | Consumer-facing responsibility |
|---|---|
| You own | Defines consumption, validation, reload, and stop-using behavior. |
| Platform team owns | Provides trusted runtime identity, protected delivery, network, and telemetry. |
| Vault owns | Operates auth mounts, policies, engines, audit, and recovery. |
Maps a request to SQL creation and revocation statements.
A unique principal generated for one lease.
Build a replacement pool before draining old connections.
Change the privileged credential Vault uses to manage principals.
source learn-vault/.runtime/learner.env
cd learn-vault/labs/dynamic-db
./request-and-query.sh
jq '{lease_id_present:(.lease_id|length>0),lease_duration,renewable}' ../../.runtime/db-lease.json
./revoke.sh| Symptom | Fresh credentials work, then the application gets password failures. |
|---|---|
| Likely causes | Lease expired, renewal failed, clock margin too small, or pool retained revoked principals. |
| Inspect safely | Check lease age, renew result, pool generation, SQLSTATE class, and Vault health. |
| Do not print | Generated username, password, DSN, SQL environment, or lease response. |
Break it: Revoke the dynamic DB lease before opening a new connection.
Fix it: Acquire a new lease, validate a replacement pool, then drain the old generation.
Escalate with time, endpoint, auth path, role, mount, namespace when relevant, status code, request ID, and sanitized error class. Never attach a credential or response body.
labs/bootstrap owns the disposable server, auth mounts, policies, roles, and engines; learner actions begin after setup.
$0; local containers only
Run labs/bootstrap/setup.sh and source .runtime/learner.env unless the chapter lab says AppRole alone is sufficient.
Request a lease, run SELECT current_database(), revoke it, then prove a new connection fails.
cd learn-vault/labs/dynamic-db
./request-and-query.sh
jq -e '.lease_duration>0 and (.lease_id|length>0)' ../../.runtime/db-lease.json
./revoke.sh
./verify-revoked.sh
./cleanup.sh
Complete every item in the Verify section using metadata-only evidence; no secret value appears in terminal output or tracked files.
Use the Failure drill and Break it / fix it evidence fields. Stop before broadening policy, weakening identity or TLS checks, or copying secret-bearing diagnostics.
Revoke before deleting the response. Cleanup does both when a lease ID exists.
orders-api no longer owns a shared DB password; readiness tracks lease margin and pool generation.
It improves attribution and permits per-workload revocation.
No. Validate a new pool with margin, then drain the old one.
An already-established DB session.
The database owner; Vault policy cannot define database privilege.
Dynamic DB credentials reduce sharing, but applications must rotate pools before the lease clock wins.