Skip to content

Commit fb2e404

Browse files
committed
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 <tristan.partin@databricks.com>
1 parent b7509d4 commit fb2e404

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

src/backend/replication/libpqwalreceiver/libpqwalreceiver.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ libpqrcv_connect(const char *conninfo, bool logical, const char *appname,
131131
/* BEGIN_NEON */
132132
const char *keys[7];
133133
const char *vals[7];
134-
char * neon_auth_token = NULL;
135134
/* END_NEON */
136135
int i = 0;
137136

@@ -143,18 +142,21 @@ libpqrcv_connect(const char *conninfo, bool logical, const char *appname,
143142
vals[i] = conninfo;
144143

145144
/* BEGIN_NEON */
145+
/*
146+
* We use neon_storage_token for the password because conninfo strings are
147+
* limited to MAXCONNINFO in length. Our tokens encode Unity Catalog
148+
* permissions, so they can be quite lengthy.
149+
*/
146150
if (pg_strcasecmp(appname, "walreceiver") == 0)
147151
{
148-
neon_auth_token = getenv("NEON_AUTH_TOKEN");
149-
if (neon_auth_token != NULL)
152+
if (neon_storage_token[0] != '\0')
150153
{
151-
elog(LOG, "Use NEON_AUTH_TOKEN to connect");
152154
keys[++i] = "password";
153-
vals[i] = neon_auth_token;
155+
vals[i] = neon_storage_token;
154156
}
155157
else
156158
{
157-
elog(LOG, "NEON_AUTH_TOKEN is undefined in the environment");
159+
elog(LOG, "no storage token set");
158160
}
159161
}
160162
/* END_NEON */

src/backend/replication/walreceiver.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
int wal_receiver_status_interval;
9191
int wal_receiver_timeout;
9292
bool hot_standby_feedback;
93+
char *neon_storage_token;
9394

9495
/* libpqwalreceiver connection */
9596
static WalReceiverConn *wrconn = NULL;
@@ -1339,6 +1340,22 @@ WalRcvGetStateString(WalRcvState state)
13391340
return "UNKNOWN";
13401341
}
13411342

1343+
/*
1344+
* We currently grant the privileged role pg_monitor, which implies
1345+
* pg_read_all_settings. Until we fix that, let's just redact the content unless
1346+
* the user requesting the value is a superuser.
1347+
*
1348+
* See: https://databricks.atlassian.net/browse/LKB-7128
1349+
*/
1350+
const char *
1351+
show_neon_storage_token(void)
1352+
{
1353+
if (superuser())
1354+
return neon_storage_token;
1355+
1356+
return "**********";
1357+
}
1358+
13421359
/*
13431360
* Returns activity of WAL receiver, including pid, state and xlog locations
13441361
* received from the WAL sender of another server.

src/backend/utils/misc/guc.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4801,6 +4801,17 @@ static struct config_string ConfigureNamesString[] =
48014801
check_restrict_nonsystem_relation_kind, assign_restrict_nonsystem_relation_kind, NULL
48024802
},
48034803

4804+
{
4805+
{"neon_storage_token", PGC_POSTMASTER, REPLICATION_STANDBY,
4806+
"Authentication token for Neon storage",
4807+
NULL,
4808+
GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_SUPERUSER_ONLY
4809+
},
4810+
&neon_storage_token,
4811+
"",
4812+
NULL, NULL, show_neon_storage_token
4813+
},
4814+
48044815
/* End-of-list marker */
48054816
{
48064817
{NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL, NULL

src/include/replication/walreceiver.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
extern PGDLLIMPORT int wal_receiver_status_interval;
2929
extern PGDLLIMPORT int wal_receiver_timeout;
3030
extern PGDLLIMPORT bool hot_standby_feedback;
31+
extern PGDLLIMPORT char *neon_storage_token;
3132

3233
/*
3334
* MAXCONNINFO: maximum size of a connection string.
@@ -454,6 +455,8 @@ walrcv_clear_result(WalRcvExecResult *walres)
454455
extern void WalReceiverMain(void) pg_attribute_noreturn();
455456
extern void ProcessWalRcvInterrupts(void);
456457

458+
extern const char *show_neon_storage_token(void);
459+
457460
/* prototypes for functions in walreceiverfuncs.c */
458461
extern Size WalRcvShmemSize(void);
459462
extern void WalRcvShmemInit(void);

0 commit comments

Comments
 (0)