Skip to content

fix(storage): keep passwords and connection strings out of config errors, destroy output and Debug - #1575

Open
navareamol wants to merge 14 commits into
mainfrom
fix/1441-cassandra-redact-pass
Open

navareamol wants to merge 14 commits into
mainfrom
fix/1441-cassandra-redact-pass

Conversation

@navareamol

@navareamol navareamol commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

What

A password or connection string given to ExtendDB no longer appears in the config-file errors, the extenddb destroy output, the {:?} output of the config and bootstrap structs, or the sqlx client-side statement log on PostgreSQL. The paths covered are the ones listed in the table under Why; nothing else was audited beyond the searches described there.

  • Cassandra --extenddb-pass is compared with check_conflict_redacted, as PostgreSQL already does. The error names the flag and no value.
  • A TOML syntax error is reported with its line, column and kind, without the text of the line. New helper extenddb_storage::config::redact::parse_toml (and toml_error_text), used by the Cassandra, PostgreSQL, MongoDB and SQLite bootstrappers and by extenddb_config::load for serve.
  • A secret field given a value of the wrong type is refused with the key name and no value: secret_string::string and secret_string::opt_string are the deserialize_with for Cassandra password, PostgreSQL connection_string and MongoDB connection_string.
  • extenddb destroy on MongoDB prints the connection string through redact_connection_string.
  • Debug hides the secret on CassandraStorageConfig, PostgresStorageConfig, MongoStorageConfig, BootstrapConfig, AdminBootstrapResult, the backend-agnostic ConnectionParts in crates/storage/src/operations.rs, MongoTarget and PostgresTarget. The Cassandra struct with the same name ConnectionParts (crates/storage-cassandra/src/config.rs) already did.
  • The PostgreSQL admin connection, which runs CREATE USER ... WITH PASSWORD '...', has sqlx statement logging off. The PostgreSQL server can still log the statement itself (see below).
  • One entry in the upgrade manual under v1.2.0 says that config error messages no longer quote the line.

Why

Fixes #1441

The issue reports the --extenddb-pass conflict on Cassandra: check_conflict formats both values into the error, which goes to stderr, and in a container stderr is the log stream. The neighbouring paths were measured with sentinel values in throwaway config files and on live containers, and the same kind of output was found in several of them.

Path Backend Result before this change
--extenddb-pass conflicts with the config file Cassandra Both values printed (issue)
Same conflict PostgreSQL Redacted already
Failed to parse config with a syntax error on the password line (unterminated string, bare value, text after the value) Cassandra Line printed with the password
Syntax error on a line next to the password line Cassandra Not printed (the message shows only the line with the error)
An unclosed array before the password line (the parser reports the next line) Cassandra Password line printed
Invalid Cassandra config with password = 7771441 (a number) Cassandra, init and serve Number printed
Same with password as an array or a table Cassandra Not printed
Wrong type in username, max_connections, replication_factor Cassandra The value of that field is printed, not the password
Syntax error on the connection_string line PostgreSQL, MongoDB Line printed with the connection string
Syntax error beside the connection_string line PostgreSQL, MongoDB Not printed
connection_string = 7771441 in serve PostgreSQL, MongoDB Number printed
connection_string as an array PostgreSQL, MongoDB Not printed
Invalid connection string (wrong scheme, bad port, no host) PostgreSQL Not printed
Driver errors for a malformed URI (bad port, scheme, option, unescaped password characters, bad percent escape, SRV lookup) MongoDB Not printed
Wrong admin password against a live server PostgreSQL, Cassandra Not printed
Unreachable server with a password given PostgreSQL, Cassandra Not printed
Syntax error on a password line in another section of the file SQLite init (it parses the whole file), and serve for every backend Line printed
Syntax error beside such a line SQLite, serve Not printed
Type error on pool_size and path SQLite The value of that field is printed (not a secret)
extenddb destroy prints endpoint_info() MongoDB The connection string as configured, with user:password
Same, read in the code PostgreSQL, Cassandra, SQLite host:port, host:port, sqlite:<path>
{:?} of the config and bootstrap structs listed above Cassandra, PostgreSQL, MongoDB Password or connection string printed (PgConnectOptions also prints its password with {:?})
sqlx statement log for CREATE USER ... WITH PASSWORD '<sentinel>' with the slow-statement threshold at 0 PostgreSQL Statement text with the password in the log
Same with disable_statement_logging() PostgreSQL Not in the log
Error of a second CREATE USER for an existing role PostgreSQL Names the role; the statement is not echoed
Server and driver errors and driver logs at TRACE for a malformed CREATE ROLE ... PASSWORD Cassandra Server errors quote the tokens near the error (for example mismatched input 'SENTINEL' expecting STRING_LITERAL); no password in the driver log

On Cassandra, ensure_app_user accepts only the characters -_.,!@#$%^&*()+=~ and space besides letters and digits in the password and puts it inside a fixed statement, so the statement does not have a syntax error at the password. A failure of the statement (permissions, timeout) is not a syntax error and quotes no tokens. This is read from crates/storage-cassandra/src/bootstrapper.rs (the character check and the statement) and from the measurement above; no code change was made for it.

serve reads the file through the config crate, whose message also quotes the line. Every row marked "Line printed" was seen in the init error and the serve error unless the row names one of them.

Other places that print a connection string or a config value were searched in init, serve, destroy, verify, migrate, settings and the config display: they go through redact_password / redact_connection_string, should_redact, or print no credential. The init output that shows a generated admin password is the intended one-time display.

Not measured or not covered:

  • A wrong password against a live MongoDB server. The driver connects lazily, so the connection check in init did not report an error.
  • redact_connection_string for MongoDB hides the user:password part of the URI. The rest of the URI prints as is, so a secret given as a query option (for example tlsCertificateKeyFilePassword or one in authMechanismProperties) is not redacted in destroy. A password containing a literal @ is split at the first @, so the part after it prints; that URI is invalid and this PR does not change that function.
  • Types holding wrapped keys that derive Debug (KeyRing and similar) are outside this issue and unchanged.
  • The PostgreSQL server's own statement log: CREATE ROLE takes no bind parameter, so the statement carries the password, and a server with log_statement set to ddl or all logs it. This PR does not change that; not measured.

Testing done

Desktop, Linux, clippy on 1.97.0, on the merge of origin/main at b6c8595 (a conflict in the upgrade manual, resolved by keeping both v1.2.0 entries). The Mac and desktop trees match (08258e6696c484f2908c740846e1431d94e5f297).

Check Result
cargo fmt --check clean
cargo +1.97.0 clippy -p <crate> --all-targets -- -D warnings, with and without --features test-hooks clean for extenddb-storage, -storage-cassandra, -storage-postgres, -storage-mongodb, -storage-sqlite; extenddb-config has no test-hooks feature and is clean without it
cargo check --workspace --all-targets passes
Lib tests storage 300 passed, cassandra 195, postgres 95, mongodb 197 (86 ignored, as before), sqlite 337 (1 ignored), config 25; no failures
New tests storage secret_debug 3, cassandra config_secret_errors 5, postgres 4 (plus 1 lib test), mongodb 5, sqlite 1, config secret_error 2, storage config::redact 5: all pass; each integration binary 20 of 20 runs (before the merge, on the same code)

The new tests use sentinel secrets and need no database:

  • crates/storage/src/config/redact.rs (unit tests)
  • crates/storage/tests/secret_debug.rs
  • crates/storage-cassandra/tests/config_secret_errors.rs
  • crates/storage-postgres/tests/config_secret_errors.rs
  • crates/storage-mongodb/tests/config_secret_errors.rs
  • crates/storage-sqlite/tests/config_secret_errors.rs
  • crates/config/tests/secret_error.rs
  • the_admin_connection_does_not_log_statements in crates/storage-postgres/src/bootstrapper.rs

Controls. Each was applied to the committed tree, the tests run, and the change reverted with git checkout -- . (git status --short empty after each).

Control Change Failing tests
C1 toml_error_text returns error.to_string() redact syntax_error_text_has_position_and_no_line; cassandra 2, postgres 1, mongodb 1, sqlite 1, config 1
C2 remove deserialize_with from Cassandra password, PostgreSQL and MongoDB connection_string cassandra 2 (serve_password_of_the_wrong_type_has_no_value, init_password_of_the_wrong_type_has_no_value); postgres 1 and mongodb 1 (serve_connection_string_of_the_wrong_type_has_no_value)
C3 Debug prints self.password / self.connection_string one debug_of_the_config_hides_* test in each of cassandra, postgres, mongodb
C4 Cassandra Debug prints cached_connection_string cassandra debug_of_the_config_hides_the_password
C5 the four bootstrappers parse with the stock toml error cassandra 2, postgres 1, mongodb 1, sqlite 1
C6 extenddb_config::load passes the config crate error through config syntax_error_on_a_secret_line_names_the_line_and_not_its_text
C7 MongoDB endpoint_info returns the raw string mongodb destroy_endpoint_has_no_password
C8 BootstrapConfig, AdminBootstrapResult, ConnectionParts print their passwords storage secret_debug 3 of 3 fail
C9 MongoTarget Debug prints the string mongodb debug_of_the_migration_target_hides_the_connection_string
C10, C10b PostgresTarget Debug prints the options, or the connection string row postgres debug_of_the_migration_target_hides_the_password (each alone)
C11 remove disable_statement_logging() from the admin connection options postgres the_admin_connection_does_not_log_statements

The existing check_conflict_redacted test from the first commit (init_password_conflict_error_has_neither_password) fails when the Cassandra call is reverted to check_conflict (measured earlier on the same branch).

Limits of the helpers:

  • toml_error_text takes the line and column from the error's byte offset in the text it is given. extenddb_config::load reads the file again by the path the config crate reports; if that read fails, the line and column are wrong (the message still has no secret).
  • The column counts bytes. The stock message may count characters, so a line with non-ASCII text before the error can give a different column.
  • A future config field that holds a secret needs secret_string to get the same wrong-type behaviour. Other fields still print their value in a type error, as before.

Overlap: open PR #1528 changes two test strings in crates/storage-cassandra/src/bootstrapper.rs. git merge-tree of the branch with its head (275405b) merged without conflict, and the branch carries a merge of origin/main.

Open question

Operators who scripted against the old text of these messages see different wording. The upgrade manual entry covers it in one paragraph. Is that the right place for it?

Amol Navare added 13 commits December 3, 2026 01:07
… with the config

init compared --extenddb-pass with the config file password through
check_conflict, whose error names both values. The message goes to stderr,
which is the log stream in a container. The call now uses
check_conflict_redacted, as the PostgreSQL bootstrapper does, so the error
names the flag and no value. A test runs the conflict through from_config
and asserts neither password is in the error.

Refs #1441
A TOML syntax error prints the line it found the error on, and a serde type
error prints the value it found. For init on every backend, and for serve
through the config loader, an error on a password or connection string line
put the secret in the message, as did a number given for a password. The
errors now give the line, column and kind of error without the line, and a
secret of the wrong type is refused without its value. The Debug output of the
Cassandra, PostgreSQL and MongoDB config structs no longer prints the password
or connection string.

Fixes #1441
extenddb destroy printed the MongoDB connection string as given, with any
user:password. The endpoint is now the redacted string. The Debug output of
BootstrapConfig, AdminBootstrapResult, the backend-agnostic ConnectionParts and
MongoTarget no longer prints a password or connection string.

Refs #1441
…d Debug

The admin connection runs CREATE USER ... WITH PASSWORD '...'. sqlx logs the
text of a statement at its slow-statement threshold, one second by default, so
a slow statement would have put the password in a warning. The admin
connection now has statement logging off. PostgresTarget printed the catalog
connection options, whose Debug output includes the password, and the
connection string row; its Debug no longer does.

Refs #1441
…dact-pass

# Conflicts:
#	docs/manuals/07-upgrade-manual.md
…ion message

The Debug text of PgConnectOptions holds the password, so the test's
failure message no longer prints it.

Refs #1441

@LJMart11 LJMart11 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 3524e89. 1 finding: 1 Docs.

The change keeps passwords and connection strings out of TOML/serde config errors, destroy output and Debug for the config and bootstrap structs, and turns off sqlx statement logging on the PostgreSQL admin connection. Confirmed: 20 TOML syntax and type-error shapes (bad escapes, bare values, trailing text, unterminated strings, dotted and inline tables, non-ASCII lines) put through parse_toml printed line and column and never the secret; 8 config files (CRLF, BOM, non-ASCII, duplicate key, no extension) through extenddb_config::load printed none either. Putting check_conflict back in the Cassandra bootstrapper fails init_password_conflict_error_has_neither_password; removing disable_statement_logging() fails the_admin_connection_does_not_log_statements. The head merged with current main builds and passes the storage, config and SQLite tests (301, 25+2, 338).

  • Docs PR description — The description gives 295 storage lib tests; the head runs 300.

Docs — outside the diff

PR description
Docs
The Testing done table gives storage 295 passed. cargo test -p extenddb-storage on the head runs 300 lib tests (301 on the head merged with current main).

Fix: update the number in the description.

Evidence: test result: ok. 300 passed; 0 failed for the storage lib binary on 3524e89; cassandra 195, mongodb 197, sqlite 337 and config 25 match the description.

@navareamol

Copy link
Copy Markdown
Collaborator Author

@LJMart11 The Testing done table now says storage 300 passed, as you measured at 3524e89. No code change.

@navareamol
navareamol requested a review from LJMart11 December 4, 2026 18:36

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cassandra init prints both passwords when --extenddb-pass conflicts with the config file

3 participants