From 39691301709fd5e1f253d1dcf479b478f864c581 Mon Sep 17 00:00:00 2001 From: Tristan Partin Date: Wed, 26 Nov 2025 10:23:34 -0600 Subject: [PATCH] Move NEON_AUTH_TOKEN to a builtin GUC This environment variable is used as the password to connect to another postgres instance as the walreceiver. The purpose of moving to a GUC is so that we can reload the storage auth token periodically. Signed-off-by: Tristan Partin --- .../replication/libpqwalreceiver/libpqwalreceiver.c | 9 +++------ src/backend/replication/walreceiver.c | 1 + src/backend/utils/misc/guc.c | 11 +++++++++++ src/include/replication/walreceiver.h | 1 + 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c b/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c index d64a95ded97..07a0cd468fa 100644 --- a/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c +++ b/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c @@ -131,7 +131,6 @@ libpqrcv_connect(const char *conninfo, bool logical, const char *appname, /* BEGIN_NEON */ const char *keys[7]; const char *vals[7]; - char * neon_auth_token = NULL; /* END_NEON */ int i = 0; @@ -145,16 +144,14 @@ libpqrcv_connect(const char *conninfo, bool logical, const char *appname, /* BEGIN_NEON */ if (pg_strcasecmp(appname, "walreceiver") == 0) { - neon_auth_token = getenv("NEON_AUTH_TOKEN"); - if (neon_auth_token != NULL) + if (neon_storage_auth_token[0] != '\0') { - elog(LOG, "Use NEON_AUTH_TOKEN to connect"); keys[++i] = "password"; - vals[i] = neon_auth_token; + vals[i] = neon_storage_auth_token; } else { - elog(LOG, "NEON_AUTH_TOKEN is undefined in the environment"); + elog(LOG, "no storage authentication token set"); } } /* END_NEON */ diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c index 5c53a3c1086..94cebe817ec 100644 --- a/src/backend/replication/walreceiver.c +++ b/src/backend/replication/walreceiver.c @@ -90,6 +90,7 @@ int wal_receiver_status_interval; int wal_receiver_timeout; bool hot_standby_feedback; +char *neon_storage_auth_token; /* libpqwalreceiver connection */ static WalReceiverConn *wrconn = NULL; diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index c6ee811ba26..20bc2bdab12 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -4801,6 +4801,17 @@ static struct config_string ConfigureNamesString[] = check_restrict_nonsystem_relation_kind, assign_restrict_nonsystem_relation_kind, NULL }, + { + {"neon_storage_auth_token", PGC_SUSET, REPLICATION_STANDBY, + "Authentication token for Neon storage", + NULL, + GUC_SUPERUSER_ONLY + }, + &neon_storage_auth_token, + "", + NULL, NULL, NULL + }, + /* End-of-list marker */ { {NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL, NULL diff --git a/src/include/replication/walreceiver.h b/src/include/replication/walreceiver.h index 81184aa92f3..75d174be2c2 100644 --- a/src/include/replication/walreceiver.h +++ b/src/include/replication/walreceiver.h @@ -28,6 +28,7 @@ extern PGDLLIMPORT int wal_receiver_status_interval; extern PGDLLIMPORT int wal_receiver_timeout; extern PGDLLIMPORT bool hot_standby_feedback; +extern PGDLLIMPORT char *neon_storage_auth_token; /* * MAXCONNINFO: maximum size of a connection string.