mirror of
https://github.com/neondatabase/neon.git
synced 2025-12-25 23:29:59 +00:00
Add support to specify auth token via --auth-token-path (#11443)
Before we specified the JWT via `SAFEKEEPER_AUTH_TOKEN`, but env vars are quite public, both in procfs as well as the unit files. So add a way to put the auth token into a file directly. context: https://neondb.slack.com/archives/C033RQ5SPDH/p1743692566311099
This commit is contained in:
@@ -223,6 +223,9 @@ struct Args {
|
|||||||
/// Flag to use https for requests to peer's safekeeper API.
|
/// Flag to use https for requests to peer's safekeeper API.
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
pub use_https_safekeeper_api: bool,
|
pub use_https_safekeeper_api: bool,
|
||||||
|
/// Path to the JWT auth token used to authenticate with other safekeepers.
|
||||||
|
#[arg(long)]
|
||||||
|
auth_token_path: Option<Utf8PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Like PathBufValueParser, but allows empty string.
|
// 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.
|
// 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") {
|
let sk_auth_token = match var("SAFEKEEPER_AUTH_TOKEN") {
|
||||||
Ok(v) => {
|
Ok(v) => {
|
||||||
info!("loaded JWT token for authentication with safekeepers");
|
info!("loaded JWT token for authentication with safekeepers");
|
||||||
Some(SecretString::from(v))
|
Some(SecretString::from(v))
|
||||||
}
|
}
|
||||||
Err(VarError::NotPresent) => {
|
Err(VarError::NotPresent) => {
|
||||||
info!("no JWT token for authentication with safekeepers detected");
|
if let Some(auth_token_path) = args.auth_token_path.as_ref() {
|
||||||
None
|
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(_) => {
|
Err(_) => {
|
||||||
warn!("JWT token for authentication with safekeepers is not unicode");
|
warn!("JWT token for authentication with safekeepers is not unicode");
|
||||||
|
|||||||
Reference in New Issue
Block a user