diff --git a/safekeeper/src/bin/safekeeper.rs b/safekeeper/src/bin/safekeeper.rs index 18aa710916..b8c122ea72 100644 --- a/safekeeper/src/bin/safekeeper.rs +++ b/safekeeper/src/bin/safekeeper.rs @@ -223,6 +223,9 @@ struct Args { /// Flag to use https for requests to peer's safekeeper API. #[arg(long)] pub use_https_safekeeper_api: bool, + /// Path to the JWT auth token used to authenticate with other safekeepers. + #[arg(long)] + auth_token_path: Option, } // Like PathBufValueParser, but allows empty string. @@ -341,14 +344,24 @@ async fn main() -> anyhow::Result<()> { }; // Load JWT auth token to connect to other safekeepers for pull_timeline. + // First check if the env var is present, then check the arg with the path. + // We want to deprecate and remove the env var method in the future. let sk_auth_token = match var("SAFEKEEPER_AUTH_TOKEN") { Ok(v) => { info!("loaded JWT token for authentication with safekeepers"); Some(SecretString::from(v)) } Err(VarError::NotPresent) => { - info!("no JWT token for authentication with safekeepers detected"); - None + if let Some(auth_token_path) = args.auth_token_path.as_ref() { + info!( + "loading JWT token for authentication with safekeepers from {auth_token_path}" + ); + let auth_token = tokio::fs::read_to_string(auth_token_path).await?; + Some(SecretString::from(auth_token.trim().to_owned())) + } else { + info!("no JWT token for authentication with safekeepers detected"); + None + } } Err(_) => { warn!("JWT token for authentication with safekeepers is not unicode");