From 5e11ed913388fa06a387c1907aa6ce44bcdfb2a5 Mon Sep 17 00:00:00 2001 From: TotaJ Date: Thu, 20 Jan 2022 17:57:37 +0800 Subject: [PATCH] Add auth for subscription. --- src/common/backend/utils/init/postinit.cpp | 4 ++-- src/gausskernel/process/postmaster/postmaster.cpp | 3 +++ .../storage/replication/subscription_walreceiver.cpp | 4 ++-- src/include/knl/knl_session.h | 1 + 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/common/backend/utils/init/postinit.cpp b/src/common/backend/utils/init/postinit.cpp index 33bb3cfd0..46fec2a3f 100644 --- a/src/common/backend/utils/init/postinit.cpp +++ b/src/common/backend/utils/init/postinit.cpp @@ -1812,8 +1812,8 @@ void PostgresInitializer::InitWAL() CheckAuthentication(); - /* Don't set superuser when connection is from gs_basebackup */ - if (u_sess->proc_cxt.clientIsGsBasebackup) { + /* Don't set superuser when connection is from gs_basebackup or subscription */ + if (u_sess->proc_cxt.clientIsGsBasebackup || u_sess->proc_cxt.clientIsSubscription) { InitUser(); } else { SetSuperUserStandalone(); diff --git a/src/gausskernel/process/postmaster/postmaster.cpp b/src/gausskernel/process/postmaster/postmaster.cpp index 901d891dd..f875e5a34 100644 --- a/src/gausskernel/process/postmaster/postmaster.cpp +++ b/src/gausskernel/process/postmaster/postmaster.cpp @@ -3750,6 +3750,9 @@ int ProcessStartupPacket(Port* port, bool SSLdone) } else if (strcmp(valptr, "autonomoustransaction") == 0) { clientIsAutonomousTransaction = true; ereport(DEBUG5, (errmsg("autonomoustransaction connected"))); + } else if (strcmp(valptr, "subscription") == 0) { + u_sess->proc_cxt.clientIsSubscription = true; + ereport(DEBUG5, (errmsg("subscription connected"))); } else { ereport(DEBUG5, (errmsg("application %s connected", valptr))); } diff --git a/src/gausskernel/storage/replication/subscription_walreceiver.cpp b/src/gausskernel/storage/replication/subscription_walreceiver.cpp index f7251a433..206be0447 100644 --- a/src/gausskernel/storage/replication/subscription_walreceiver.cpp +++ b/src/gausskernel/storage/replication/subscription_walreceiver.cpp @@ -28,7 +28,7 @@ bool sub_connect(char *conninfo, XLogRecPtr *startpoint, char *appname, int chan /* * We use the expand_dbname parameter to process the connection string (or * URI), and pass some extra options. The deliberately undocumented - * parameter "replication=true" makes it a replication connection. The + * parameter "replication=database" makes it a replication connection. The * database name is ignored by the server in replication mode. */ keys[i] = "dbname"; @@ -36,7 +36,7 @@ bool sub_connect(char *conninfo, XLogRecPtr *startpoint, char *appname, int chan keys[++i] = "replication"; vals[i] = "database"; keys[++i] = "fallback_application_name"; - vals[i] = appname; + vals[i] = "subscription"; keys[++i] = "client_encoding"; vals[i] = GetDatabaseEncodingName(); keys[++i] = NULL; diff --git a/src/include/knl/knl_session.h b/src/include/knl/knl_session.h index 85ed099e4..0605ace02 100644 --- a/src/include/knl/knl_session.h +++ b/src/include/knl/knl_session.h @@ -1134,6 +1134,7 @@ typedef struct knl_u_proc_context { bool clientIsGsBasebackup; /* gs_basebackup tool check flag */ bool clientIsGsroach; /* gs_roach tool check flag */ bool clientIsGsRestore; /* gs_restore tool check flag */ + bool clientIsSubscription; /* subscription client check flag */ bool IsBinaryUpgrade; bool IsWLMWhiteList; /* this proc will not be controled by WLM */ bool gsRewindAddCount;