diff --git a/control_plane/src/compute.rs b/control_plane/src/compute.rs index 547aa14d39..8731cf2583 100644 --- a/control_plane/src/compute.rs +++ b/control_plane/src/compute.rs @@ -201,7 +201,7 @@ impl PostgresNode { .stderr(Stdio::piped()); if let Some(token) = auth_token { - cmd.env("ZENITH_AUTH_TOKEN", token); + cmd.env("NEON_AUTH_TOKEN", token); } let sync_handle = cmd @@ -304,17 +304,17 @@ impl PostgresNode { // Set up authentication // - // $ZENITH_AUTH_TOKEN will be replaced with value from environment + // $NEON_AUTH_TOKEN will be replaced with value from environment // variable during compute pg startup. It is done this way because // otherwise user will be able to retrieve the value using SHOW // command or pg_settings let password = if let AuthType::NeonJWT = auth_type { - "$ZENITH_AUTH_TOKEN" + "$NEON_AUTH_TOKEN" } else { "" }; // NOTE avoiding spaces in connection string, because it is less error prone if we forward it somewhere. - // Also note that not all parameters are supported here. Because in compute we substitute $ZENITH_AUTH_TOKEN + // Also note that not all parameters are supported here. Because in compute we substitute $NEON_AUTH_TOKEN // We parse this string and build it back with token from env var, and for simplicity rebuild // uses only needed variables namely host, port, user, password. format!("postgresql://no_user:{password}@{host}:{port}") @@ -323,7 +323,7 @@ impl PostgresNode { conf.append_line(""); conf.append("neon.pageserver_connstring", &pageserver_connstr); if let AuthType::NeonJWT = auth_type { - conf.append("neon.safekeeper_token_env", "$ZENITH_AUTH_TOKEN"); + conf.append("neon.safekeeper_token_env", "$NEON_AUTH_TOKEN"); } conf.append("neon.tenant_id", &self.tenant_id.to_string()); conf.append("neon.timeline_id", &self.timeline_id.to_string()); @@ -448,7 +448,7 @@ impl PostgresNode { self.env.pg_lib_dir(self.pg_version)?.to_str().unwrap(), ); if let Some(token) = auth_token { - cmd.env("ZENITH_AUTH_TOKEN", token); + cmd.env("NEON_AUTH_TOKEN", token); } let pg_ctl = cmd.output().context("pg_ctl failed")?; diff --git a/control_plane/src/pageserver.rs b/control_plane/src/pageserver.rs index 0c2415965a..68e94b2fdc 100644 --- a/control_plane/src/pageserver.rs +++ b/control_plane/src/pageserver.rs @@ -320,7 +320,7 @@ impl PageServerNode { let token = self .env .generate_auth_token(&Claims::new(None, Scope::SafekeeperData))?; - vec![("ZENITH_AUTH_TOKEN".to_owned(), token)] + vec![("NEON_AUTH_TOKEN".to_owned(), token)] } else { Vec::new() }) diff --git a/docs/authentication.md b/docs/authentication.md index 0752fae19f..e22d7b700f 100644 --- a/docs/authentication.md +++ b/docs/authentication.md @@ -65,7 +65,7 @@ There is no administrative API except those provided by PostgreSQL. #### Outgoing connections Compute connects to Pageserver for getting pages. -The connection string is configured by the `neon.pageserver_connstring` PostgreSQL GUC, e.g. `postgresql://no_user:$ZENITH_AUTH_TOKEN@localhost:15028`. +The connection string is configured by the `neon.pageserver_connstring` PostgreSQL GUC, e.g. `postgresql://no_user:$NEON_AUTH_TOKEN@localhost:15028`. The environment variable inside the connection string is substituted with the JWT token. @@ -77,7 +77,7 @@ If the GUC is unset, no token is passed. Note that both tokens can be (and typically are) the same; the scope is the tenant and the token is usually passed through the -`$ZENITH_AUTH_TOKEN` environment variable. +`$NEON_AUTH_TOKEN` environment variable. ### Pageserver #### Overview @@ -114,7 +114,7 @@ either of three values: Pageserver makes a connection to a Safekeeper for each active timeline. As Pageserver may want to access any timeline it has on the disk, it is given a blanket JWT token to access any data on any Safekeeper. -This token is passed through an environment variable called `ZENITH_AUTH_TOKEN` +This token is passed through an environment variable called `NEON_AUTH_TOKEN` (non-configurable as of writing this text). A better way _may be_ to store JWT token for each timeline next to it, diff --git a/pageserver/src/bin/pageserver.rs b/pageserver/src/bin/pageserver.rs index 2b4dcc68f0..5246541375 100644 --- a/pageserver/src/bin/pageserver.rs +++ b/pageserver/src/bin/pageserver.rs @@ -264,19 +264,35 @@ fn start_pageserver(conf: &'static PageServerConf) -> anyhow::Result<()> { }; info!("Using auth: {:#?}", conf.auth_type); - match var("ZENITH_AUTH_TOKEN") { - Ok(v) => { + // TODO: remove ZENITH_AUTH_TOKEN once it's not used anywhere in development/staging/prod configuration. + match (var("ZENITH_AUTH_TOKEN"), var("NEON_AUTH_TOKEN")) { + (old, Ok(v)) => { info!("Loaded JWT token for authentication with Safekeeper"); + if let Ok(v_old) = old { + warn!( + "JWT token for Safekeeper is specified twice, ZENITH_AUTH_TOKEN is deprecated" + ); + if v_old != v { + warn!("JWT token for Safekeeper has two different values, choosing NEON_AUTH_TOKEN"); + } + } pageserver::config::SAFEKEEPER_AUTH_TOKEN .set(Arc::new(v)) .map_err(|_| anyhow!("Could not initialize SAFEKEEPER_AUTH_TOKEN"))?; } - Err(VarError::NotPresent) => { + (Ok(v), _) => { + info!("Loaded JWT token for authentication with Safekeeper"); + warn!("Please update pageserver configuration: the JWT token should be NEON_AUTH_TOKEN, not ZENITH_AUTH_TOKEN"); + pageserver::config::SAFEKEEPER_AUTH_TOKEN + .set(Arc::new(v)) + .map_err(|_| anyhow!("Could not initialize SAFEKEEPER_AUTH_TOKEN"))?; + } + (_, Err(VarError::NotPresent)) => { info!("No JWT token for authentication with Safekeeper detected"); } - Err(e) => { + (_, Err(e)) => { return Err(e).with_context(|| { - "Failed to either load to detect non-present ZENITH_AUTH_TOKEN environment variable" + "Failed to either load to detect non-present NEON_AUTH_TOKEN environment variable" }) } }; diff --git a/pgxn/neon/libpagestore.c b/pgxn/neon/libpagestore.c index 5f134e3924..c6199dddc0 100644 --- a/pgxn/neon/libpagestore.c +++ b/pgxn/neon/libpagestore.c @@ -420,7 +420,7 @@ pg_init_libpagestore(void) NULL, NULL, NULL); DefineCustomStringVariable("neon.safekeeper_token_env", - "the environment variable containing JWT token for authentication with Safekeepers, the convention is to either unset or set to $ZENITH_AUTH_TOKEN", + "the environment variable containing JWT token for authentication with Safekeepers, the convention is to either unset or set to $NEON_AUTH_TOKEN", NULL, &safekeeper_token_env, NULL,