Repository navigation
fix(storage): keep passwords and connection strings out of config errors, destroy output and Debug - #1575
fix(storage): keep passwords and connection strings out of config errors, destroy output and Debug#1575navareamol wants to merge 14 commits into
Conversation
… 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
left a comment
There was a problem hiding this comment.
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.
|
@LJMart11 The Testing done table now says |
What
A password or connection string given to ExtendDB no longer appears in the config-file errors, the
extenddb destroyoutput, 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.--extenddb-passis compared withcheck_conflict_redacted, as PostgreSQL already does. The error names the flag and no value.extenddb_storage::config::redact::parse_toml(andtoml_error_text), used by the Cassandra, PostgreSQL, MongoDB and SQLite bootstrappers and byextenddb_config::loadforserve.secret_string::stringandsecret_string::opt_stringare thedeserialize_withfor Cassandrapassword, PostgreSQLconnection_stringand MongoDBconnection_string.extenddb destroyon MongoDB prints the connection string throughredact_connection_string.Debughides the secret onCassandraStorageConfig,PostgresStorageConfig,MongoStorageConfig,BootstrapConfig,AdminBootstrapResult, the backend-agnosticConnectionPartsincrates/storage/src/operations.rs,MongoTargetandPostgresTarget. The Cassandra struct with the same nameConnectionParts(crates/storage-cassandra/src/config.rs) already did.CREATE USER ... WITH PASSWORD '...', has sqlx statement logging off. The PostgreSQL server can still log the statement itself (see below).Why
Fixes #1441
The issue reports the
--extenddb-passconflict on Cassandra:check_conflictformats 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.--extenddb-passconflicts with the config fileFailed to parse configwith a syntax error on thepasswordline (unterminated string, bare value, text after the value)passwordlinepasswordline (the parser reports the next line)Invalid Cassandra configwithpassword = 7771441(a number)initandservepasswordas an array or a tableusername,max_connections,replication_factorconnection_stringlineconnection_stringlineconnection_string = 7771441inserveconnection_stringas an arrayInvalid connection string(wrong scheme, bad port, no host)init(it parses the whole file), andservefor every backendservepool_sizeandpathextenddb destroyprintsendpoint_info()user:passwordhost:port,host:port,sqlite:<path>{:?}of the config and bootstrap structs listed abovePgConnectOptionsalso prints its password with{:?})CREATE USER ... WITH PASSWORD '<sentinel>'with the slow-statement threshold at 0disable_statement_logging()CREATE USERfor an existing roleCREATE ROLE ... PASSWORDmismatched input 'SENTINEL' expecting STRING_LITERAL); no password in the driver logOn Cassandra,
ensure_app_useraccepts 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 fromcrates/storage-cassandra/src/bootstrapper.rs(the character check and the statement) and from the measurement above; no code change was made for it.servereads the file through theconfigcrate, whose message also quotes the line. Every row marked "Line printed" was seen in theiniterror and theserveerror 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,settingsand the config display: they go throughredact_password/redact_connection_string,should_redact, or print no credential. Theinitoutput that shows a generated admin password is the intended one-time display.Not measured or not covered:
initdid not report an error.redact_connection_stringfor MongoDB hides theuser:passwordpart of the URI. The rest of the URI prints as is, so a secret given as a query option (for exampletlsCertificateKeyFilePasswordor one inauthMechanismProperties) is not redacted indestroy. 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.Debug(KeyRingand similar) are outside this issue and unchanged.CREATE ROLEtakes no bind parameter, so the statement carries the password, and a server withlog_statementset toddloralllogs it. This PR does not change that; not measured.Testing done
Desktop, Linux, clippy on 1.97.0, on the merge of
origin/mainat b6c8595 (a conflict in the upgrade manual, resolved by keeping both v1.2.0 entries). The Mac and desktop trees match (08258e6696c484f2908c740846e1431d94e5f297).cargo fmt --checkcargo +1.97.0 clippy -p <crate> --all-targets -- -D warnings, with and without--features test-hookstest-hooksfeature and is clean without itcargo check --workspace --all-targetssecret_debug3, cassandraconfig_secret_errors5, postgres 4 (plus 1 lib test), mongodb 5, sqlite 1, configsecret_error2, storageconfig::redact5: 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.rscrates/storage-cassandra/tests/config_secret_errors.rscrates/storage-postgres/tests/config_secret_errors.rscrates/storage-mongodb/tests/config_secret_errors.rscrates/storage-sqlite/tests/config_secret_errors.rscrates/config/tests/secret_error.rsthe_admin_connection_does_not_log_statementsincrates/storage-postgres/src/bootstrapper.rsControls. Each was applied to the committed tree, the tests run, and the change reverted with
git checkout -- .(git status --shortempty after each).toml_error_textreturnserror.to_string()syntax_error_text_has_position_and_no_line; cassandra 2, postgres 1, mongodb 1, sqlite 1, config 1deserialize_withfrom Cassandrapassword, PostgreSQL and MongoDBconnection_stringserve_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)Debugprintsself.password/self.connection_stringdebug_of_the_config_hides_*test in each of cassandra, postgres, mongodbDebugprintscached_connection_stringdebug_of_the_config_hides_the_passwordtomlerrorextenddb_config::loadpasses theconfigcrate error throughsyntax_error_on_a_secret_line_names_the_line_and_not_its_textendpoint_inforeturns the raw stringdestroy_endpoint_has_no_passwordBootstrapConfig,AdminBootstrapResult,ConnectionPartsprint their passwordssecret_debug3 of 3 failMongoTargetDebugprints the stringdebug_of_the_migration_target_hides_the_connection_stringPostgresTargetDebugprints the options, or the connection string rowdebug_of_the_migration_target_hides_the_password(each alone)disable_statement_logging()from the admin connection optionsthe_admin_connection_does_not_log_statementsThe existing
check_conflict_redactedtest from the first commit (init_password_conflict_error_has_neither_password) fails when the Cassandra call is reverted tocheck_conflict(measured earlier on the same branch).Limits of the helpers:
toml_error_texttakes the line and column from the error's byte offset in the text it is given.extenddb_config::loadreads the file again by the path theconfigcrate reports; if that read fails, the line and column are wrong (the message still has no secret).secret_stringto 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-treeof the branch with its head (275405b) merged without conflict, and the branch carries a merge oforigin/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?