Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/backend/replication/libpqwalreceiver/libpqwalreceiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ libpqrcv_connect(const char *conninfo, bool replication, bool logical,
/* BEGIN_NEON */
const char *keys[7];
const char *vals[7];
char * neon_auth_token = NULL;
/* END_NEON */
int i = 0;

Expand Down Expand Up @@ -212,16 +211,14 @@ libpqrcv_connect(const char *conninfo, bool replication, bool logical,
/* 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 */
Expand Down
17 changes: 17 additions & 0 deletions src/backend/replication/walreceiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,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;
Expand Down Expand Up @@ -1392,6 +1393,22 @@ WalRcvGetStateString(WalRcvState state)
return "UNKNOWN";
}

/*
* We currently grant the privileged role pg_monitor, which implies
* pg_read_all_settings. Until we fix that, let's just redact the content unless
* the user requesting the value is a superuser.
*
* See: https://databricks.atlassian.net/browse/LKB-7128
*/
const char *
show_neon_storage_auth_token(void)
{
if (superuser())
return neon_storage_auth_token;

return "**********";
}

/*
* Returns activity of WAL receiver, including pid, state and xlog locations
* received from the WAL sender of another server.
Expand Down
12 changes: 12 additions & 0 deletions src/backend/utils/misc/guc_tables.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
#include "replication/slot.h"
#include "replication/slotsync.h"
#include "replication/syncrep.h"
#include "replication/walreceiver.h"
#include "storage/aio.h"
#include "storage/bufmgr.h"
#include "storage/bufpage.h"
Expand Down Expand Up @@ -5050,6 +5051,17 @@ struct config_string ConfigureNamesString[] =
check_log_connections, assign_log_connections, NULL
},

{
{"neon_storage_auth_token", PGC_SUSET, REPLICATION_STANDBY,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't decide on PGC_SUSET or PGC_SU_BACKEND.

"Authentication token for Neon storage",
NULL,
GUC_NO_SHOW_ALL | GUC_NO_RESET | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_SUPERUSER_ONLY
},
&neon_storage_auth_token,
"",
NULL, NULL, show_neon_storage_auth_token,
},


/* End-of-list marker */
{
Expand Down
3 changes: 3 additions & 0 deletions src/include/replication/walreceiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -489,6 +490,8 @@ walrcv_clear_result(WalRcvExecResult *walres)
pg_noreturn extern void WalReceiverMain(const void *startup_data, size_t startup_data_len);
extern void WalRcvForceReply(void);

extern const char *show_neon_storage_auth_token(void);

/* prototypes for functions in walreceiverfuncs.c */
extern Size WalRcvShmemSize(void);
extern void WalRcvShmemInit(void);
Expand Down