Skip to content

Commit fc09ad9

Browse files
committed
Catalog: add migration for mock_authentication_nonce setting
The [SASL/SCRAM](#33468) PR introduces the need for some stable, cluster wide, cryptographically random key material. We use this material to be able to present deterministic challenges for even users that don't exist to guard against enumeration attacks. However that PR made a bad assumption that the initialize step of catalog opening would always add this new key. But old versions that have already been initialized wouldn't have it! This PR add code to generate it for old versions
1 parent 474411f commit fc09ad9

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/adapter/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ mz-storage-types = { path = "../storage-types" }
7272
mz-tracing = { path = "../tracing" }
7373
mz-transform = { path = "../transform" }
7474
mz-timestamp-oracle = { path = "../timestamp-oracle" }
75+
openssl = { version = "0.10.73", features = ["vendored"] }
7576
opentelemetry = { version = "0.24.0", features = ["trace"] }
7677
prometheus = { version = "0.13.4", default-features = false }
7778
prost = { version = "0.13.5", features = ["no-recursion-limit"] }

src/adapter/src/catalog/migrate.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99

1010
use std::collections::BTreeMap;
1111

12+
use base64::prelude::*;
1213
use maplit::btreeset;
1314
use mz_catalog::builtin::BuiltinTable;
14-
use mz_catalog::durable::Transaction;
15+
use mz_catalog::durable::{MOCK_AUTHENTICATION_NONCE_KEY, Transaction};
1516
use mz_catalog::memory::objects::{BootstrapStateUpdateKind, StateUpdate};
1617
use mz_ore::collections::CollectionExt;
1718
use mz_ore::now::NowFn;
@@ -830,6 +831,17 @@ pub(crate) fn durable_migrate(
830831
Some(BUILTIN_MIGRATION_SHARD_MIGRATION_DONE),
831832
)?;
832833
}
834+
835+
if tx
836+
.get_setting(MOCK_AUTHENTICATION_NONCE_KEY.to_string())
837+
.is_none()
838+
{
839+
let mut nonce = [0u8; 24];
840+
let _ = openssl::rand::rand_bytes(&mut nonce).expect("failed to generate nonce");
841+
let nonce = BASE64_STANDARD.encode(nonce);
842+
tx.set_setting(MOCK_AUTHENTICATION_NONCE_KEY.to_string(), Some(nonce))?;
843+
}
844+
833845
Ok(())
834846
}
835847

0 commit comments

Comments
 (0)