-
Notifications
You must be signed in to change notification settings - Fork 4.6k
PostgreSQL SCRAM-SHA-256 password hashing ignores server's scram_iterations setting #31853
Description
Describe the bug
When password_authentication is set to scram-sha-256, Vault hashes passwords client-side using SCRAM-SHA-256 with a hardcoded iteration count of 4096 (plugins/database/postgresql/scram/scram.go).
PostgreSQL 16 introduced the scram_iterations server parameter, allowing operators to configure the iteration count for password hashing (default 4096). Because Vault performs the hashing itself with a fixed value, the server's scram_iterations setting is effectively bypassed.
This matters in both directions:
- Operators who increase iterations for security get weaker hashing than expected, with no indication.
- Operators who decrease iterations for performance (e.g. when Vault rotates passwords frequently, making brute-force protection less relevant) are stuck paying the CPU cost of 4096 iterations per password creation/rotation, for negligible security gain.
In both cases, the operator has no reason to expect that their PostgreSQL server configuration is being ignored — the setting simply doesn't apply when the client sends a pre-hashed password.
To Reproduce
- Configure PostgreSQL 16+ with a non-default
scram_iterationsvalue (e.g.SET scram_iterations = 100000orSET scram_iterations = 1000) - Configure Vault's database secrets engine with
password_authentication = scram-sha-256 - Create or rotate a user's password via Vault
- Inspect the stored password hash in
pg_authid— the iteration count will be 4096 regardless of the server setting
Expected behavior
I expected Vault to respect the server's scram_iterations setting by default.
Ideally, Vault would also allow an explicit override via its own configuration, for cases where the operator wants Vault to use a different value than the server's configured value.
Environment:
- Vault Server Version (retrieve with
vault status): Latest (v1.21.4) - Vault CLI Version (retrieve with
vault version): N/A - Server Operating System/Architecture: All
Vault server configuration file(s): N/A
Additional context
The hardcoded constant is at plugins/database/postgresql/scram/scram.go:30. The scram.Hash() function signature doesn't accept an iteration parameter.