Skip to content
Merged
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
14 changes: 8 additions & 6 deletions src/backend/replication/libpqwalreceiver/libpqwalreceiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ libpqrcv_connect(const char *conninfo, bool logical, bool must_use_password,
/* BEGIN_NEON */
const char *keys[7];
const char *vals[7];
char * neon_auth_token = NULL;
/* END_NEON */
int i = 0;

Expand All @@ -157,18 +156,21 @@ libpqrcv_connect(const char *conninfo, bool logical, bool must_use_password,
vals[i] = conninfo;

/* BEGIN_NEON */
/*
* We use neon_storage_token for the password because conninfo strings are
* limited to MAXCONNINFO in length. Our tokens encode Unity Catalog
* permissions, so they can be quite lengthy.
*/
if (pg_strcasecmp(appname, "walreceiver") == 0)
{
neon_auth_token = getenv("NEON_AUTH_TOKEN");
if (neon_auth_token != NULL)
if (neon_storage_token[0] != '\0')
{
elog(LOG, "Use NEON_AUTH_TOKEN to connect");
keys[++i] = "password";
vals[i] = neon_auth_token;
vals[i] = neon_storage_token;
}
else
{
elog(LOG, "NEON_AUTH_TOKEN is undefined in the environment");
elog(LOG, "no storage 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 @@ -90,6 +90,7 @@
int wal_receiver_status_interval;
int wal_receiver_timeout;
bool hot_standby_feedback;
char *neon_storage_token;

/* libpqwalreceiver connection */
static WalReceiverConn *wrconn = NULL;
Expand Down Expand Up @@ -1395,6 +1396,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_token(void)
{
if (superuser())
return neon_storage_token;

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

/*
* Returns activity of WAL receiver, including pid, state and xlog locations
* received from the WAL sender of another server.
Expand Down
13 changes: 13 additions & 0 deletions src/backend/utils/misc/guc_tables.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
#include "replication/logicallauncher.h"
#include "replication/slot.h"
#include "replication/syncrep.h"
#include "replication/walreceiver.h"
#include "storage/bufmgr.h"
#include "storage/large_object.h"
#include "storage/pg_shmem.h"
Expand Down Expand Up @@ -4639,6 +4640,18 @@ struct config_string ConfigureNamesString[] =
check_restrict_nonsystem_relation_kind, assign_restrict_nonsystem_relation_kind, NULL
},


{
{"neon_storage_token", PGC_POSTMASTER, REPLICATION_STANDBY,
"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_token,
"",
NULL, NULL, show_neon_storage_token
},

/* End-of-list marker */
{
{NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL, NULL
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 @@ -30,6 +30,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_token;

/*
* MAXCONNINFO: maximum size of a connection string.
Expand Down Expand Up @@ -461,6 +462,8 @@ extern void WalReceiverMain(void) pg_attribute_noreturn();
extern void ProcessWalRcvInterrupts(void);
extern void WalRcvForceReply(void);

extern const char *show_neon_storage_token(void);

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