Repository navigation
Fail close on TOTP in SCRAM SHA-256 authentication - #117408
Conversation
The SCRAM client proof is derived from the password alone, so it cannot carry or verify a one-time password. `checkScramSHA256Authentication` ignored the configured TOTP secret and verified only the proof. The PostgreSQL frontend already refuses to run the SCRAM exchange for a `scram_sha256_password` method with a second factor (see `getScramSalt`), so the bypass was not reachable, but the check itself must not depend on every producer of `ScramSHA256Credentials` pre-filtering such users. Now `checkScramSHA256Authentication` fails closed when a one-time password is configured. Accordingly, the ambiguous-credentials combination in `getScramSalt` no longer exempts a same-salt `scram_sha256_password` method that carries a second factor: the proof can no longer be checked against it, so it would silently drop out of the fail-close combination instead of shortening the session lifetime; such a configuration is refused as unsupported instead. Also added an integration test for TOTP over the PostgreSQL protocol: a SCRAM user with TOTP is refused, and cleartext password authentication enforces the second factor. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Workflow [PR], commit [0ee378b] Summary: ✅
AI ReviewSummaryAdds a guard rejecting SCRAM proofs for authentication methods configured with TOTP. Request changes because the added PostgreSQL test never reaches the new guard, leaving the central security invariant without regression coverage. Findings
Tests
Final Verdict |
Build profile diff (arm_release)Commit See the job log for details. |
The flaky check runs the test file on several pytest-xdist workers in parallel, and `create_config` writes the shared `config/users.xml`. With a random module-level `TOTP_SECRET` the last writer wins, and the other workers' servers reject codes generated for their own secrets with `WRONG_PASSWORD`, failing every test that uses the random secret: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117407&sha=a9ca343fa63aa8299c12e5cb9cd68c96372ff03e&name_0=PR https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117408&sha=c88676cc0bc8587b70dfbb9fba92482587b74245&name_0=PR #117407 #117408 Also fix operator precedence in `get_one_time_password`: the intent is `int((timepoint or time.time()) / interval)`, not dividing only `time.time()` by the interval. Co-Authored-By: Claude Fable 5 <[email protected]>
The flaky check runs the test file on several pytest-xdist workers in parallel, and `create_config` writes the shared `config/users.xml`. With a random module-level `TOTP_SECRET` the last writer wins, and the other workers' servers reject codes generated for their own secrets with `WRONG_PASSWORD`, failing every test that uses the random secret: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117407&sha=a9ca343fa63aa8299c12e5cb9cd68c96372ff03e&name_0=PR https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117408&sha=c88676cc0bc8587b70dfbb9fba92482587b74245&name_0=PR #117407 #117408 Also fix operator precedence in `get_one_time_password`: the intent is `int((timepoint or time.time()) / interval)`, not dividing only `time.time()` by the interval. Co-Authored-By: Claude Fable 5 <[email protected]>
…pre-check With `BasicCredentials`, a method with a second factor yields `NeedSecondFactor` for the password alone, so `IAccessStorage::authenticateImpl` never folds it into the session limits. Treating an expired same-salt `scram_sha256_password` method with TOTP as one that must participate in the combination made the PostgreSQL frontend return `NOT_IMPLEMENTED` where the native protocol accepts the login through the live method. Revert that part of `getScramSalt` so both protocols behave the same; the fail-close check in `checkScramSHA256Authentication` stays. Addresses the review comment on #117408
Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
|
||
| # A SCRAM user with TOTP must be refused: the exchange cannot verify the second factor. | ||
| scram_user = "totuser_postgresql_scram" | ||
| with pytest.raises(psycopg2.OperationalError, match="not supported"): |
There was a problem hiding this comment.
[P2] Exercise the new SCRAM guard in a regression test
Both SCRAM attempts are rejected by the existing ScrambleSHA256Auth::getScramSalt pre-check: it detects TOTP, and authenticate throws NOT_IMPLEMENTED before constructing any ScramSHA256Credentials. The cleartext attempts exercise BasicCredentials. Consequently, this test still passes if the new getOneTimePassword guard in checkScramSHA256Authentication is removed, leaving the shared authenticator's second-factor enforcement unprotected against regressions.
Please add a focused test passing a valid ScramSHA256Credentials proof directly to Authentication::areCredentialsValid: the same stored SCRAM password should produce Success without TOTP and Fail with TOTP. That test should fail when the new guard is removed.
The SCRAM client proof is derived from the password alone, so it cannot carry or verify a one-time password.
checkScramSHA256Authenticationignored the configured TOTP secret and verified only the proof. The PostgreSQL frontend already refuses to run the SCRAM exchange for ascram_sha256_passwordmethod with a second factor (seegetScramSalt), so this was not reachable, but the check itself must not depend on every producer ofScramSHA256Credentialspre-filtering such users. It now fails closed when a one-time password is configured.Accordingly, the ambiguous-credentials pass in
getScramSaltno longer exempts a same-saltscram_sha256_passwordmethod that carries a second factor (only an expired one can reach that point): the proof can no longer be checked against it, so it would silently drop out of the fail-closeGRANTS/VALID UNTILcombination instead of shortening the session lifetime. Such a configuration is refused as unsupported instead.Added an integration test for TOTP over the PostgreSQL protocol: a
scram_sha256_passworduser with TOTP is refused as an unsupported configuration, and cleartext password authentication enforces the second factor (password+TOTP).Related: #117407
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
SCRAM SHA-256 authentication now fails closed for users with a time-based one-time password, because a SCRAM proof cannot carry a second factor.
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/117408]
Version info
26.11.1.86-master(included in26.11and later)