Skip to content

Commit

Permalink
fix scram auth (#1934)
Browse files Browse the repository at this point in the history
SASLScramAuthStartupHandler has state, so cannot be shared between connections
  • Loading branch information
serprex authored and Amogh-Bharadwaj committed Jul 14, 2024
1 parent be08053 commit 09c1769
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions nexus/server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ impl AuthSource for FixedPasswordAuthSource {

// randomly generate a 4 byte salt
let salt = rand::thread_rng().gen::<[u8; 4]>();
let password = &self.password;
let hash_password = gen_salted_password(password, &salt, 4096);
let hash_password = gen_salted_password(&self.password, &salt, 4096);
Ok(Password::new(Some(salt.to_vec()), hash_password))
}
}
Expand Down Expand Up @@ -1014,8 +1013,10 @@ async fn run_migrations<'a>(config: &CatalogConfig<'a>) -> anyhow::Result<()> {
}

pub struct Handlers {
authenticator:
Arc<SASLScramAuthStartupHandler<FixedPasswordAuthSource, NexusServerParameterProvider>>,
authenticator: (
Arc<FixedPasswordAuthSource>,
Arc<NexusServerParameterProvider>,
),
nexus: Arc<NexusBackend>,
}

Expand All @@ -1035,7 +1036,10 @@ impl PgWireHandlerFactory for Handlers {
}

fn startup_handler(&self) -> Arc<Self::StartupHandler> {
self.authenticator.clone()
Arc::new(SASLScramAuthStartupHandler::new(
self.authenticator.0.clone(),
self.authenticator.1.clone(),
))
}

fn copy_handler(&self) -> Arc<Self::CopyHandler> {
Expand All @@ -1050,10 +1054,10 @@ pub async fn main() -> anyhow::Result<()> {
let args = Args::parse();
let _guard = setup_tracing(args.log_dir.as_ref().map(|s| &s[..]));

let authenticator = Arc::new(SASLScramAuthStartupHandler::new(
let authenticator = (
Arc::new(FixedPasswordAuthSource::new(args.peerdb_password.clone())),
Arc::new(NexusServerParameterProvider),
));
);
let catalog_config = get_catalog_config(&args);

run_migrations(&catalog_config).await?;
Expand Down

0 comments on commit 09c1769

Please sign in to comment.