Every time an application requests credentials, Vault hands back a unique DB user and password that automatically expire when the TTL runs out. That is the core idea behind the Database secrets engine.
This article walks through why dynamic issuance is safer, the minimum setup steps, rotation and revocation, policy design, and the points that tend to show up on the exams — all in one place.
With dynamic credentials, Vault creates a short-lived DB user on each request and reliably tears it down when the TTL expires or it is explicitly revoked. Compared to long-lived shared passwords or manual handoffs, this dramatically shrinks the blast radius of any leak.
Auditability is also strong — Vault's audit log records who fetched credentials under which role and when. During incidents or rollbacks, revoking at the lease level takes effect immediately.
| Approach | Validity | Impact if leaked | Rotation workflow |
|---|---|---|---|
| Dynamic credentials (Vault) | Short-lived (TTL, Max TTL) | Low (expires or revokes instantly) | Automatic (new on each fetch) |
| Fixed in-app account | Long-lived or indefinite | High (spreads to every environment) | Manual or script-dependent |
| Manual issuance (ticket-based) | Case by case | Medium-high (revocation always lags) | Manual every time |
The Database secrets engine connects to the DB through a plugin (e.g. postgresql-database-plugin) and runs the SQL defined in the role to create a user. Vault binds the generated credentials to a lease and runs the revocation SQL when the TTL expires.
The application only needs read access to Vault — Vault handles the DB-side creation and deletion on its behalf. This decouples DB administrative privileges from the application itself.
Dynamic credential issuance flow
The following is a minimal walkthrough. The DB connection user (e.g. vault_admin) needs permission to create users, grant privileges, and drop users. Adjust the connection URL and TLS settings for your environment.
In creation_statements, accept the temporary username and password as Vault template variables, and grant only the minimum privileges required.
Configuration and credential fetch via the Vault CLI (PostgreSQL)
export VAULT_ADDR=https://vault.example.com
export VAULT_TOKEN=hvs.xxxxx
# 1) Databaseシークレットエンジンを有効化
vault secrets enable database
# 2) DB接続設定(postgresql-database-plugin)
vault write database/config/my-postgresql \
plugin_name=postgresql-database-plugin \
allowed_roles=app-readonly \
connection_url="postgresql://{{username}}:{{password}}@db.example.com:5432/postgres?sslmode=require" \
username="vault_admin" \
password="s3cr3t"
# 3) ロール定義(読み取り専用の一時ユーザを作成)
vault write database/roles/app-readonly \
db_name=my-postgresql \
creation_statements="CREATE ROLE \"{{name}}\" WITH LOGIN PASSWORD '{{password}}' VALID UNTIL '{{expiration}}'; GRANT SELECT ON ALL TABLES IN SCHEMA public TO \"{{name}}\"; ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO \"{{name}}\";" \
revocation_statements="REVOKE ALL PRIVILEGES ON ALL TABLES IN SCHEMA public FROM \"{{name}}\"; DROP ROLE IF EXISTS \"{{name}}\";" \
default_ttl=1h \
max_ttl=24h
# 4) アプリが資格情報を取得(動的)
vault read database/creds/app-readonly
# 出力例
# Key Value
# lease_id database/creds/app-readonly/xxxxx
# lease_duration 1h
# lease_renewable true
# password A1b2C3d4e5f6g7h8
# username v-token-app-readonly-1693258841-abcde
# 5) 最小権限ポリシー(アプリ用)
cat <<'EOF' > app-readonly.hcl
path "database/creds/app-readonly" {
capabilities = ["read"]
}
EOF
vault policy write app-readonly app-readonly.hcl
# 必要ならアプリ用トークンを発行(例)
vault token create -policy=app-readonly -display-name=app-A
# 6) 失効(インシデント対応など、即時剥奪)
vault lease revoke database/creds/app-readonly/xxxxx
# 7) 接続ユーザのローテーション(定期的なベストプラクティス)
vault write -f database/rotate-root/my-postgresqlLeases can be renewed within the bounds of max_ttl. Renewal extends Vault's revocation schedule and pushes back the user-drop timing. If long-lived connections are not required by the role, keep default_ttl short.
The connection user — the fixed account Vault uses to reach the DB — can be rotated with rotate-root. This shortens the window during which the static Vault-to-DB credential is exposed.
As a rule, give the application only read access on database/creds/<role>. Write and list operations are unnecessary. Separating paths per role clarifies the boundaries between services.
Even for the same application, use distinct role names for dev / staging / prod so credentials cannot cross environments. Separating namespaces or mount paths is also effective.
Common failures include insufficient privileges on the connection user (cannot CREATE ROLE or GRANT), bad escaping in creation_statements, and DB connections that don't meet TLS requirements. Start by reading both the Vault log and the DB server log side by side.
For the Associate / Ops exams, common topics include the relationship between Lease / TTL / Max TTL, the meaning of rotate-root, the effect of lease revoke, and constraints around allowed_roles.
Associate / Ops
問題 1
An application has just fetched credentials from database/creds/readrole via the Vault Database secrets engine. You want to invalidate those credentials immediately. Which is the most appropriate action?
正解: A
Revoking the lease is the fastest way to immediately invalidate a specific set of issued credentials. rotate-root rotates the Vault-to-DB connection user and does not affect already-issued temporary users. Revoking the token stops future fetches but leaves any already-issued DB users in place via a different path. Setting TTL to 0 does not retroactively affect existing leases.
What permissions does the connection user (the fixed account Vault uses to connect to the DB) need?
It needs whatever permissions the role's creation and revocation SQL statements require. Typically that means user creation, privilege granting, and deletion (CREATE ROLE / GRANT / DROP ROLE, etc.). Follow least-privilege and avoid unnecessary superuser rights.
Are usernames reused, or is a new one generated each time?
Dynamic credentials generate a unique username every time (e.g. v-token-...). When the lease expires, the user is removed via the configured revocation_statements.
Does renewing the TTL change the password on the database side?
Normally, renewing a lease only extends Vault's revocation schedule. The DB-side username and password stay the same (within max_ttl). The revocation SQL only runs at expiration or explicit revoke.
Practice with certification-focused question sets
無料で問題を解いてみるNicheeLab Editorial Team
NicheeLab editorial team focused on data engineering and cloud certification learning. Content is structured around practical study needs and official exam domains.
Vault Core Concepts: Sealed/Unsealed, Auth, Secrets (2026)
Vault fundamentals — sealed/unsealed state, auth methods, se...
Vault Operations Professional (VOP-003): Complete Guide (2026)
Pass the Vault Operations Professional exam — enterprise pat...
Vault Path-Based Routing: API URL Structure (2026)
How Vault's path-based routing works — mount points, sub-pat...
Vault Tokens: Auth Token Mechanics (2026)
Token fundamentals — service vs. batch tokens, accessor, ren...
Vault Token Types: Service, Batch, Periodic (2026)
Service vs. batch tokens compared — performance, ACL behavio...