From 10e958f27b40b25399cbfd340fec2db761162e61 Mon Sep 17 00:00:00 2001 From: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com> Date: Sat, 21 Nov 2026 20:14:21 +0000 Subject: [PATCH 1/4] fix(init): read the admin variables alike on every backend On Cassandra, init with EXTENDDB_ADMIN_PASSWORD set and EXTENDDB_ADMIN_USER not set printed the supplied password on stdout, in its "shown once" credentials box. The Cassandra bootstrapper took the password as from the environment only when both variables were set. Otherwise it returned the password as a generated one. It now takes the password as from the environment whenever one is supplied, as the other backends do, and returns no password. On MongoDB and Cassandra, init took an empty EXTENDDB_ADMIN_USER or EXTENDDB_ADMIN_PASSWORD as the admin name or the password. SQLite and PostgreSQL treated an empty value as unset, each in its own bootstrapper. write_bootstrap_rows now passes an empty value on as no value for every backend, and the copies in the SQLite and PostgreSQL bootstrappers are gone. The SQLite server with an in-memory database or a dev build keeps its own check, because it writes its admin at start without write_bootstrap_rows. The Cassandra test of an init that finishes a stopped one now supplies a password without a user name. It fails on the Cassandra code before this change. A SQLite test runs write_bootstrap_rows over four pairs of the two values, and it fails without the shared check. The Cassandra image README no longer says that init prints a supplied password. The upgrade manual has a v1.1.0 entry for catalogs that an earlier release initialized with an empty password. Closes #1339 --- crates/storage-cassandra/src/bootstrapper.rs | 9 ++-- crates/storage-cassandra/tests/migrations.rs | 19 +++++-- crates/storage-postgres/src/bootstrapper.rs | 6 +-- crates/storage-sqlite/src/bootstrapper.rs | 55 ++++++++++++++++++-- crates/storage/src/bootstrapper.rs | 11 ++-- docker/README-cassandra.md | 5 +- docs/manuals/07-upgrade-manual.md | 6 +++ 7 files changed, 88 insertions(+), 23 deletions(-) diff --git a/crates/storage-cassandra/src/bootstrapper.rs b/crates/storage-cassandra/src/bootstrapper.rs index 6052d62a0..230b32e68 100644 --- a/crates/storage-cassandra/src/bootstrapper.rs +++ b/crates/storage-cassandra/src/bootstrapper.rs @@ -786,15 +786,12 @@ impl Bootstrapper for CassandraBootstrapper { let keyspace = self.engine.catalog_keyspace(); let username = env_user.unwrap_or("admin"); - let from_env = env_user.is_some() && env_password.is_some(); println!("--- Creating admin user..."); - // Generate or use provided password - let password = if let Some(pw) = env_password { - pw.to_string() - } else { - generate_random_password() + let (password, from_env) = match env_password { + Some(p) => (p.to_owned(), true), + None => (generate_random_password(), false), }; // Hash password (using bcrypt in blocking task to avoid blocking async runtime) diff --git a/crates/storage-cassandra/tests/migrations.rs b/crates/storage-cassandra/tests/migrations.rs index 387d29cae..d38f7d302 100644 --- a/crates/storage-cassandra/tests/migrations.rs +++ b/crates/storage-cassandra/tests/migrations.rs @@ -1521,6 +1521,7 @@ async fn init_refuses_an_account_keyspace_at_simple_strategy_until_it_is_altered .await; let admin = resume().await.expect("init finishes after ALTER KEYSPACE"); assert_eq!(admin.username, "admin"); + assert!(!admin.already_existed && !admin.from_env && admin.generated_password.is_some()); assert_eq!(store.list_all_accounts().await.expect("list"), accounts); drop(drops); helpers::flush_pending_drops(&session).await; @@ -1532,7 +1533,8 @@ async fn init_refuses_an_account_keyspace_at_simple_strategy_until_it_is_altered /// `init`, a new process, takes the keyspace as `init` does, and its steps /// under the lock run no migration, keep the key, create no second account /// and write the admin user; the `init` after that is refused as -/// initialized. +/// initialized. The next `init` has an admin password from the environment +/// and no user name, and gets no generated password back. #[tokio::test] async fn init_finishes_a_catalog_stopped_before_its_admin_user() { use extenddb_storage::bootstrapper::{ @@ -1606,13 +1608,22 @@ async fn init_finishes_a_catalog_stopped_before_its_admin_user() { .expect("decided") ); next.hold(&lock); - let admin = write_bootstrap_rows(&next, None, None).await.expect("rows"); + let admin = write_bootstrap_rows(&next, None, Some("Supplied-pw-1")) + .await + .expect("rows"); next.record_data_connection() .await .expect("data connection"); migrations.release(lock).await; - assert_eq!(admin.username, "admin"); - assert!(!admin.already_existed && admin.generated_password.is_some()); + assert_eq!( + ( + admin.username.as_str(), + admin.already_existed, + admin.from_env, + admin.generated_password + ), + ("admin", false, true, None) + ); assert_eq!( store.get_setting("encryption_key").await.expect("read"), key diff --git a/crates/storage-postgres/src/bootstrapper.rs b/crates/storage-postgres/src/bootstrapper.rs index f2cce5395..28a05d177 100755 --- a/crates/storage-postgres/src/bootstrapper.rs +++ b/crates/storage-postgres/src/bootstrapper.rs @@ -303,7 +303,7 @@ impl Bootstrapper for PostgresBootstrapper { env_password: Option<&str>, ) -> OpResult { let pool = self.app_pool(&self.config.catalog_db).await?; - let admin_name = env_user.filter(|s| !s.is_empty()).unwrap_or("admin"); + let admin_name = env_user.unwrap_or("admin"); let exists: bool = sqlx::query_scalar("SELECT EXISTS(SELECT 1 FROM admin_users WHERE admin_name = $1)") @@ -324,8 +324,8 @@ impl Bootstrapper for PostgresBootstrapper { println!("--- Creating admin user '{admin_name}'..."); let (password, from_env) = match env_password { - Some(p) if !p.is_empty() => (p.to_owned(), true), - _ => (generate_random_password(), false), + Some(p) => (p.to_owned(), true), + None => (generate_random_password(), false), }; let hash = hash_password_async(password.clone()).await?; diff --git a/crates/storage-sqlite/src/bootstrapper.rs b/crates/storage-sqlite/src/bootstrapper.rs index 89127b460..ab12aeef3 100644 --- a/crates/storage-sqlite/src/bootstrapper.rs +++ b/crates/storage-sqlite/src/bootstrapper.rs @@ -253,10 +253,7 @@ impl Bootstrapper for SqliteBootstrapper { env_password: Option<&str>, ) -> OpResult { let pool = self.pool().await?; - let username = env_user - .filter(|s| !s.is_empty()) - .unwrap_or("admin") - .to_owned(); + let username = env_user.unwrap_or("admin").to_owned(); let exists: bool = sqlx::query_scalar("SELECT EXISTS(SELECT 1 FROM admin_users WHERE admin_name = ?)") @@ -273,7 +270,7 @@ impl Bootstrapper for SqliteBootstrapper { }); } - let (password, from_env) = match env_password.filter(|s| !s.is_empty()) { + let (password, from_env) = match env_password { Some(p) => (p.to_owned(), true), None => (helpers::generate_random_password(), false), }; @@ -545,4 +542,52 @@ mod init_tests { ); let _ = std::fs::remove_dir_all(&dir); } + + /// `write_bootstrap_rows` passes an empty `EXTENDDB_ADMIN_USER` or + /// `EXTENDDB_ADMIN_PASSWORD` on as no value, and returns a password only + /// when it generated one. + #[tokio::test] + async fn empty_admin_variables_are_unset_and_a_supplied_password_is_not_returned() { + // (EXTENDDB_ADMIN_USER, EXTENDDB_ADMIN_PASSWORD, admin name, from the environment) + let cases = [ + (Some(""), Some(""), "admin", false), + (None, Some("Supplied-pw-1"), "admin", true), + (Some("ops"), None, "ops", false), + (Some("ops"), Some("Supplied-pw-1"), "ops", true), + ]; + let timeout = Duration::from_secs(10); + for (user, password, name, from_env) in cases { + let dir = std::env::temp_dir().join(format!( + "extenddb-admin-env-{}", + uuid::Uuid::new_v4().simple() + )); + let path = dir.join("extenddb.sqlite").to_string_lossy().into_owned(); + let bootstrapper = SqliteBootstrapper::new(path); + let migrations = SqliteCatalogMigrations; + let target = bootstrapper.init_target(); + bootstrapper.create_catalog_db().await.expect("file"); + let lock = migrations.lock(&target, timeout).await.expect("lock"); + let status = migrations + .status_under_lock(&lock, &target) + .await + .expect("status"); + run_with_status(&migrations, &status, &lock, "1.0.0-test", RunKind::Create) + .await + .expect("create"); + bootstrapper.hold(&lock); + let admin = write_bootstrap_rows(&bootstrapper, user, password).await; + migrations.release(lock).await; + let _ = std::fs::remove_dir_all(&dir); + let admin = admin.expect("rows"); + assert_eq!( + ( + admin.username.as_str(), + admin.from_env, + admin.generated_password.is_some() + ), + (name, from_env, !from_env), + "{user:?} {password:?}" + ); + } + } } diff --git a/crates/storage/src/bootstrapper.rs b/crates/storage/src/bootstrapper.rs index 46925cf62..6d359b1c3 100755 --- a/crates/storage/src/bootstrapper.rs +++ b/crates/storage/src/bootstrapper.rs @@ -70,7 +70,9 @@ pub trait Bootstrapper: Send + Sync { /// Create the default account. Idempotent — skips if any account exists. async fn bootstrap_default_account(&self) -> OpResult<()>; - /// Create the initial admin user. + /// Create the initial admin user. `init` passes `None` for an + /// `EXTENDDB_ADMIN_USER` or `EXTENDDB_ADMIN_PASSWORD` that is unset or + /// empty ([`write_bootstrap_rows`]). async fn bootstrap_admin_user( &self, env_user: Option<&str>, @@ -151,7 +153,7 @@ pub async fn finishes_a_stopped_init( /// writes its row only when the catalog lacks it, so on a catalog an earlier /// `init` stopped in this writes the rows that `init` did not. /// `admin_user` and `admin_password` come from `EXTENDDB_ADMIN_USER` and -/// `EXTENDDB_ADMIN_PASSWORD`. +/// `EXTENDDB_ADMIN_PASSWORD`. An empty value is passed on as no value. /// /// # Errors /// @@ -165,7 +167,10 @@ pub async fn write_bootstrap_rows( bootstrapper.bootstrap_default_account().await?; // REQ-AUTH-003 bootstrapper - .bootstrap_admin_user(admin_user, admin_password) + .bootstrap_admin_user( + admin_user.filter(|s| !s.is_empty()), + admin_password.filter(|s| !s.is_empty()), + ) .await } diff --git a/docker/README-cassandra.md b/docker/README-cassandra.md index fb39e9282..2a17d4e6d 100644 --- a/docker/README-cassandra.md +++ b/docker/README-cassandra.md @@ -83,8 +83,9 @@ Pass the passwords through the environment rather than as arguments: or check its password and writes the value you supplied into the config, so a wrong value surfaces only when `serve` fails to connect. * `EXTENDDB_ADMIN_USER` and `EXTENDDB_ADMIN_PASSWORD`: the first ExtendDB - administrator. Set both; with only the password set, `init` prints that - password in its output, and so in the container's logs. + administrator, named `admin` when `EXTENDDB_ADMIN_USER` is unset or empty. + Without `EXTENDDB_ADMIN_PASSWORD`, `init` generates a password and prints it + in its output, and so in the container's logs. `init` writes only the first of the `--cassandra-contact-points` into `extenddb.toml`; add the others to `contact_points` there afterwards. The file diff --git a/docs/manuals/07-upgrade-manual.md b/docs/manuals/07-upgrade-manual.md index ab3b307fe..5111af7da 100755 --- a/docs/manuals/07-upgrade-manual.md +++ b/docs/manuals/07-upgrade-manual.md @@ -388,6 +388,12 @@ Catalog upgrades change the schema; behavior changes alter how the running serve interprets existing data or configuration. Review these before upgrading a live deployment, even when no catalog migration is required. +### v1.1.0: `init` takes an empty admin variable as unset on every backend + +**What changed.** `extenddb init` takes an empty `EXTENDDB_ADMIN_USER` or `EXTENDDB_ADMIN_PASSWORD` as unset on every backend: it names the admin `admin`, or generates a password. On MongoDB and Cassandra, 1.0.0 took the empty string as the name or the password. On Cassandra, `init` with `EXTENDDB_ADMIN_PASSWORD` set and `EXTENDDB_ADMIN_USER` not set no longer prints the supplied password (#1339). + +**Who is affected.** A MongoDB or Cassandra catalog that an earlier release initialized with an empty `EXTENDDB_ADMIN_PASSWORD` keeps an admin whose password is empty. Give it a password with `extenddb manage change-admin-password`, with `EXTENDDB_PASSWORD` set to an empty value for the login. The output of a Cassandra `init` from an earlier release with only `EXTENDDB_ADMIN_PASSWORD` set holds that password, so change it if that output was kept. No catalog migration is required. + ### v1.0.0: Cassandra reads and writes at `LOCAL_QUORUM` **What changed.** The Cassandra backend runs its reads and writes at `LOCAL_QUORUM`. 0.1.15 ran many of them at `ONE`, the driver's default, in each area: items (the reads of GetItem, Query and Scan among them), transactions, TTL, streams, the catalog, IAM and `init`. A read with `ConsistentRead` `false` also runs at `LOCAL_QUORUM`. A lightweight transaction runs Paxos at `LOCAL_SERIAL` and commits at `LOCAL_QUORUM`. 0.1.15 ran many of its lightweight transactions at those levels already, and others, among them the admin user creation and most IAM writes, at the driver's defaults, `SERIAL` and `ONE`. Batches ran at `LOCAL_QUORUM` before and still do. No setting changes these levels (#945). From 7828f6b6c88052167dea3fbe149632ea863174a8 Mon Sep 17 00:00:00 2001 From: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com> Date: Sat, 21 Nov 2026 21:33:01 +0000 Subject: [PATCH 2/4] test(storage-sqlite): print the row number in the admin variables assert message The assert message of the admin variables test printed the password of its row, and code scanning reported it as cleartext logging of a password. The message now gives the row number. Refs #1339 --- crates/storage-sqlite/src/bootstrapper.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/storage-sqlite/src/bootstrapper.rs b/crates/storage-sqlite/src/bootstrapper.rs index ab12aeef3..47178309c 100644 --- a/crates/storage-sqlite/src/bootstrapper.rs +++ b/crates/storage-sqlite/src/bootstrapper.rs @@ -556,7 +556,7 @@ mod init_tests { (Some("ops"), Some("Supplied-pw-1"), "ops", true), ]; let timeout = Duration::from_secs(10); - for (user, password, name, from_env) in cases { + for (row, (user, password, name, from_env)) in cases.into_iter().enumerate() { let dir = std::env::temp_dir().join(format!( "extenddb-admin-env-{}", uuid::Uuid::new_v4().simple() @@ -586,7 +586,7 @@ mod init_tests { admin.generated_password.is_some() ), (name, from_env, !from_env), - "{user:?} {password:?}" + "row {row}" ); } } From c24442f9f54b04192f1c3ce8e5b78d46afdc9702 Mon Sep 17 00:00:00 2001 From: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com> Date: Wed, 25 Nov 2026 18:23:26 +0000 Subject: [PATCH 3/4] docs(upgrade): cover an empty EXTENDDB_ADMIN_USER in the init entry The v1.1.0 entry for #1339 covered only an empty EXTENDDB_ADMIN_PASSWORD. In 1.0.0, an empty EXTENDDB_ADMIN_USER had a different result on each backend: - MongoDB stored an admin with an empty name. extenddb manage logs in as that admin with --user '' and changes its password with --admin-name '', but delete-admin --admin-name '' gets HTTP 404. The entry gives the create-admin and mongosh commands that delete it. - Cassandra refused the empty key, so init stopped before the admin user and wrote none. An init of this release finishes that catalog. The entry also gives the full change-admin-password command for an admin with an empty password. --- docs/manuals/07-upgrade-manual.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/manuals/07-upgrade-manual.md b/docs/manuals/07-upgrade-manual.md index 53e1c764f..96ebcbff7 100755 --- a/docs/manuals/07-upgrade-manual.md +++ b/docs/manuals/07-upgrade-manual.md @@ -403,7 +403,13 @@ No catalog migration or configuration change is required. **What changed.** `extenddb init` takes an empty `EXTENDDB_ADMIN_USER` or `EXTENDDB_ADMIN_PASSWORD` as unset on every backend: it names the admin `admin`, or generates a password. On MongoDB and Cassandra, 1.0.0 took the empty string as the name or the password. On Cassandra, `init` with `EXTENDDB_ADMIN_PASSWORD` set and `EXTENDDB_ADMIN_USER` not set no longer prints the supplied password (#1339). -**Who is affected.** A MongoDB or Cassandra catalog that an earlier release initialized with an empty `EXTENDDB_ADMIN_PASSWORD` keeps an admin whose password is empty. Give it a password with `extenddb manage change-admin-password`, with `EXTENDDB_PASSWORD` set to an empty value for the login. The output of a Cassandra `init` from an earlier release with only `EXTENDDB_ADMIN_PASSWORD` set holds that password, so change it if that output was kept. No catalog migration is required. +**Who is affected.** MongoDB and Cassandra catalogs that an earlier release initialized with an empty `EXTENDDB_ADMIN_PASSWORD` or an empty `EXTENDDB_ADMIN_USER`. + +- An empty `EXTENDDB_ADMIN_PASSWORD` gave the admin an empty password. Log in with an empty `EXTENDDB_PASSWORD` and give the admin a password: `EXTENDDB_PASSWORD= extenddb manage --user change-admin-password --admin-name --new-password `. +- On MongoDB, an empty `EXTENDDB_ADMIN_USER` gave the admin an empty name, and `list-admins` shows it as `"admin_name": ""`. That admin logs in with `--user ''`, and `change-admin-password --admin-name ''` changes its password. `delete-admin --admin-name ''` fails with `HTTP 404`, because the request path `/management/admins/` names no admin. To delete the admin, first create another one: `extenddb manage --user '' create-admin --admin-name --admin-password `. Then delete its document in `mongosh`: `db.getSiblingDB("extenddb_catalog").admin_users.deleteOne({_id: ""})`. +- On Cassandra, `init` with an empty `EXTENDDB_ADMIN_USER` stopped with `Error: Create admin user: Internal error: Database error` and wrote no admin, because Cassandra refuses an empty key. Run the same `init` command with this release. It finishes the catalog and creates the admin, named `admin` when `EXTENDDB_ADMIN_USER` is empty or unset. + +The output of a Cassandra `init` from an earlier release with only `EXTENDDB_ADMIN_PASSWORD` set holds that password, so change it if that output was kept. No catalog migration is required. ### v1.0.0: Cassandra reads and writes at `LOCAL_QUORUM` From 138e712089482a6f66b1a0952630c82975b212a9 Mon Sep 17 00:00:00 2001 From: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com> Date: Wed, 25 Nov 2026 19:11:42 +0000 Subject: [PATCH 4/4] docs(upgrade): name each group the init entry covers, by backend The "Who is affected" lead now also names the Cassandra catalogs that init created with only EXTENDDB_ADMIN_PASSWORD set. The last paragraph of the entry gives them advice, and the lead left them out. "What changed" says what 1.0.0 did on each backend. On MongoDB it took the empty string as the name or the password. On Cassandra it took an empty password, and an empty name stopped init with an error. The MongoDB bullet no longer gives a cause for the HTTP 404 of delete-admin. The cause it gave did not tell that request apart from change-admin-password, which works. The mongosh step names the admin whose document it deletes. The Cassandra bullet drops a clause that repeats "What changed". --- docs/manuals/07-upgrade-manual.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/manuals/07-upgrade-manual.md b/docs/manuals/07-upgrade-manual.md index 96ebcbff7..0227f0530 100755 --- a/docs/manuals/07-upgrade-manual.md +++ b/docs/manuals/07-upgrade-manual.md @@ -401,13 +401,13 @@ No catalog migration or configuration change is required. ### v1.1.0: `init` takes an empty admin variable as unset on every backend -**What changed.** `extenddb init` takes an empty `EXTENDDB_ADMIN_USER` or `EXTENDDB_ADMIN_PASSWORD` as unset on every backend: it names the admin `admin`, or generates a password. On MongoDB and Cassandra, 1.0.0 took the empty string as the name or the password. On Cassandra, `init` with `EXTENDDB_ADMIN_PASSWORD` set and `EXTENDDB_ADMIN_USER` not set no longer prints the supplied password (#1339). +**What changed.** `extenddb init` takes an empty `EXTENDDB_ADMIN_USER` or `EXTENDDB_ADMIN_PASSWORD` as unset on every backend: it names the admin `admin`, or generates a password. On MongoDB, 1.0.0 took the empty string as the name or the password. On Cassandra, 1.0.0 took an empty password, and an empty name stopped `init` with an error. On Cassandra, `init` with `EXTENDDB_ADMIN_PASSWORD` set and `EXTENDDB_ADMIN_USER` not set no longer prints the supplied password (#1339). -**Who is affected.** MongoDB and Cassandra catalogs that an earlier release initialized with an empty `EXTENDDB_ADMIN_PASSWORD` or an empty `EXTENDDB_ADMIN_USER`. +**Who is affected.** MongoDB and Cassandra catalogs that `init` of an earlier release created with an empty `EXTENDDB_ADMIN_PASSWORD` or an empty `EXTENDDB_ADMIN_USER`, and Cassandra catalogs that it created with only `EXTENDDB_ADMIN_PASSWORD` set. - An empty `EXTENDDB_ADMIN_PASSWORD` gave the admin an empty password. Log in with an empty `EXTENDDB_PASSWORD` and give the admin a password: `EXTENDDB_PASSWORD= extenddb manage --user change-admin-password --admin-name --new-password `. -- On MongoDB, an empty `EXTENDDB_ADMIN_USER` gave the admin an empty name, and `list-admins` shows it as `"admin_name": ""`. That admin logs in with `--user ''`, and `change-admin-password --admin-name ''` changes its password. `delete-admin --admin-name ''` fails with `HTTP 404`, because the request path `/management/admins/` names no admin. To delete the admin, first create another one: `extenddb manage --user '' create-admin --admin-name --admin-password `. Then delete its document in `mongosh`: `db.getSiblingDB("extenddb_catalog").admin_users.deleteOne({_id: ""})`. -- On Cassandra, `init` with an empty `EXTENDDB_ADMIN_USER` stopped with `Error: Create admin user: Internal error: Database error` and wrote no admin, because Cassandra refuses an empty key. Run the same `init` command with this release. It finishes the catalog and creates the admin, named `admin` when `EXTENDDB_ADMIN_USER` is empty or unset. +- On MongoDB, an empty `EXTENDDB_ADMIN_USER` gave the admin an empty name, and `list-admins` shows it as `"admin_name": ""`. That admin logs in with `--user ''`, and `change-admin-password --admin-name ''` changes its password. `delete-admin --admin-name ''` fails with `HTTP 404`. To delete the admin, first create another one: `extenddb manage --user '' create-admin --admin-name --admin-password `. Then delete the document of the admin with the empty name in `mongosh`: `db.getSiblingDB("extenddb_catalog").admin_users.deleteOne({_id: ""})`. +- On Cassandra, `init` with an empty `EXTENDDB_ADMIN_USER` stopped with `Error: Create admin user: Internal error: Database error` and wrote no admin, because Cassandra refuses an empty key. Run the same `init` command with this release. It finishes the catalog and creates the admin `admin`. The output of a Cassandra `init` from an earlier release with only `EXTENDDB_ADMIN_PASSWORD` set holds that password, so change it if that output was kept. No catalog migration is required.