Skip to content

Commit 4f1bc16

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 <[email protected]>
1 parent f911638 commit 4f1bc16

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

src/backend/replication/libpqwalreceiver/libpqwalreceiver.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ libpqrcv_connect(const char *conninfo, bool replication, bool logical,
150150
/* BEGIN_NEON */
151151
const char *keys[7];
152152
const char *vals[7];
153-
char * neon_auth_token = NULL;
154153
/* END_NEON */
155154
int i = 0;
156155

@@ -212,16 +211,14 @@ libpqrcv_connect(const char *conninfo, bool replication, bool logical,
212211
/* BEGIN_NEON */
213212
if (pg_strcasecmp(appname, "walreceiver") == 0)
214213
{
215-
neon_auth_token = getenv("NEON_AUTH_TOKEN");
216-
if (neon_auth_token != NULL)
214+
if (neon_storage_auth_token[0] != '\0')
217215
{
218-
elog(LOG, "Use NEON_AUTH_TOKEN to connect");
219216
keys[++i] = "password";
220-
vals[i] = neon_auth_token;
217+
vals[i] = neon_storage_auth_token;
221218
}
222219
else
223220
{
224-
elog(LOG, "NEON_AUTH_TOKEN is undefined in the environment");
221+
elog(LOG, "no storage authentication token set");
225222
}
226223
}
227224
/* END_NEON */

src/backend/replication/walreceiver.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
int wal_receiver_status_interval;
8989
int wal_receiver_timeout;
9090
bool hot_standby_feedback;
91+
char *neon_storage_auth_token;
9192

9293
/* libpqwalreceiver connection */
9394
static WalReceiverConn *wrconn = NULL;
@@ -1392,6 +1393,22 @@ WalRcvGetStateString(WalRcvState state)
13921393
return "UNKNOWN";
13931394
}
13941395

1396+
/*
1397+
* We currently grant the privileged role pg_monitor, which implies
1398+
* pg_read_all_settings. Until we fix that, let's just redact the content unless
1399+
* the user requesting the value is a superuser.
1400+
*
1401+
* See: https://databricks.atlassian.net/browse/LKB-7128
1402+
*/
1403+
const char *
1404+
show_neon_storage_auth_token(void)
1405+
{
1406+
if (superuser())
1407+
return neon_storage_auth_token;
1408+
1409+
return "**********";
1410+
}
1411+
13951412
/*
13961413
* Returns activity of WAL receiver, including pid, state and xlog locations
13971414
* received from the WAL sender of another server.

src/backend/utils/misc/guc_tables.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
#include "replication/slot.h"
7878
#include "replication/slotsync.h"
7979
#include "replication/syncrep.h"
80+
#include "replication/walreceiver.h"
8081
#include "storage/aio.h"
8182
#include "storage/bufmgr.h"
8283
#include "storage/bufpage.h"
@@ -5050,6 +5051,17 @@ struct config_string ConfigureNamesString[] =
50505051
check_log_connections, assign_log_connections, NULL
50515052
},
50525053

5054+
{
5055+
{"neon_storage_auth_token", PGC_SUSET, REPLICATION_STANDBY,
5056+
"Authentication token for Neon storage",
5057+
NULL,
5058+
GUC_NO_SHOW_ALL | GUC_NO_RESET | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_SUPERUSER_ONLY
5059+
},
5060+
&neon_storage_auth_token,
5061+
"",
5062+
NULL, NULL, show_neon_storage_auth_token,
5063+
},
5064+
50535065

50545066
/* End-of-list marker */
50555067
{

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_auth_token;
3132

3233
/*
3334
* MAXCONNINFO: maximum size of a connection string.
@@ -489,6 +490,8 @@ walrcv_clear_result(WalRcvExecResult *walres)
489490
pg_noreturn extern void WalReceiverMain(const void *startup_data, size_t startup_data_len);
490491
extern void WalRcvForceReply(void);
491492

493+
extern const char *show_neon_storage_auth_token(void);
494+
492495
/* prototypes for functions in walreceiverfuncs.c */
493496
extern Size WalRcvShmemSize(void);
494497
extern void WalRcvShmemInit(void);

0 commit comments

Comments
 (0)