Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qoGdK-000gmd-Oc for pgsql-hackers@arkaria.postgresql.org; Thu, 05 Oct 2023 05:10:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qoGdG-008qFq-QO for pgsql-hackers@arkaria.postgresql.org; Thu, 05 Oct 2023 05:10:43 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qoGdE-008qFf-Qq for pgsql-hackers@lists.postgresql.org; Thu, 05 Oct 2023 05:10:43 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qoGdA-0005rR-PE for pgsql-hackers@lists.postgresql.org; Thu, 05 Oct 2023 05:10:40 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 701D75C0375; Thu, 5 Oct 2023 01:10:35 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Thu, 05 Oct 2023 01:10:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm2; t=1696482635; x=1696569035; bh=Gb RcNxa1w8g0KgIA3zTm2kKzJV5viX5jVvjuzSQPZf4=; b=bLtVHgvH3vqKC9uKoJ 3j4RbUB8nEfpY9M7DkquMpDaRurRlXGNcXw37c7InjfPHjMP1WQYanMO2FZ6IBi7 bbUQoB28JkCer8L/Rw7GvzUVyTWS3c1bgKhUFbyT1RGxbK2IL829Ebv2mYOl5iwe 1BL3FgiqvBYecsAedVzrT32RMsrbBHDX4oJXh7DHeDsOOYhnY4S1A4Bg28tD1Rn7 TI+9EKqlKZ4C6aPN/fOVKm11jd/VO89sseeIJDLBL4+265TgigEB61GjmSy4nNRK ri+yMvFdlVMVL+lebWwNqcDuTBaDqMWdw8pMXfl8jxqojZF0F06Xr+YEgvnssXg8 OpJg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1696482635; x=1696569035; bh=GbRcNxa1w8g0K gIA3zTm2kKzJV5viX5jVvjuzSQPZf4=; b=mQ3qaRrVpJVec6NiKkc07cPduJ+Mb uZFCU4VaEVLuwsfv55KcP6gISY4hhTHyvJlOAcdxKrcynT8NxMc+RYG2r3q/W/3e QRlrgrPpm4PebI5f0BtD3IPr+rZarrmSboxsa3vSGrrXDTflm7LfmXhhMxi+fWHM Hh48uIj+P+JYakMng1TLegEPq5H99elPZGr5uW957TiJq+zru8bbsBZC6UcXC0JB Qs9A5VBA+KTfq8AHp0nSIRzBD3Vv2AJZdsWRNhFUsz1a3d5FdO1H47UIdTJVd+Lu GEaNFhpepL96Wi20402hTAqTc7k5HLFD/kpUEAf0kRzqC9/PWiPA5BVwQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrgeefgdelvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfg hrlhcuvffnffculdejtddmnecujfgurhepfffhvfevuffkfhggtggujgesghdtreertddt vdenucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrhcuoehmihgthhgrvghlsehprg hquhhivghrrdighiiiqeenucggtffrrghtthgvrhhnpeetleeifedufffhhfdtteelgeeg geffhfekueevteeigfduudevudetgfegiedvjeenucevlhhushhtvghrufhiiigvpedtne curfgrrhgrmhepmhgrihhlfhhrohhmpehmihgthhgrvghlsehprghquhhivghrrdighiii X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 5 Oct 2023 01:10:33 -0400 (EDT) Date: Thu, 5 Oct 2023 14:10:28 +0900 From: Michael Paquier To: "Drouvot, Bertrand" Cc: PostgreSQL Hackers Subject: Re: Add a new BGWORKER_BYPASS_ROLELOGINCHECK flag Message-ID: References: <566c1686-c80b-4d4a-b496-b00ac428a095@gmail.com> <83f72bb9-f3cf-4344-8d4d-45e128813d58@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="MI2NUVE1/ZGVoKI7" Content-Disposition: inline In-Reply-To: <83f72bb9-f3cf-4344-8d4d-45e128813d58@gmail.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --MI2NUVE1/ZGVoKI7 Content-Type: multipart/mixed; boundary="yZosu/sJ5BByIPik" Content-Disposition: inline --yZosu/sJ5BByIPik Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Oct 04, 2023 at 12:54:24PM +0200, Drouvot, Bertrand wrote: > Except the Nit that I mentioned in 0001, that looks all good to me (with = the > new wait in 001_worker_spi.pl). Thanks, I've applied the refactoring, including in it the stuff to be able to control the flags used when launching a dynamic worker. 0001 also needed some indenting. You'll notice that the diffs in worker_spi are minimal now. worker_spi_main is no more, as an effect of.. Cough.. c8e318b1b. +# An error message should be issued. +my $nb_errors =3D 0; +for (my $i =3D 0; $i < 10 * $PostgreSQL::Test::Utils::timeout_default; $i+= +) +{ + if ($node->log_contains( + "role \"nologrole\" is not permitted to log in", $log_start)) + { + $nb_errors =3D 1; + last; + } + usleep(100_000); +} This can be switched to use $node->wait_for_log, making the test simpler. No need for Time::HiRes, either. -extern void BackgroundWorkerInitializeConnection(const char *dbname, const char *username, uint32 flags); +extern void BackgroundWorkerInitializeConnection(const char *dbname, const char *username, bits32 flags); [...] -BackgroundWorkerInitializeConnectionByOid(Oid dboid, Oid useroid, uint32 flags)=20 +BackgroundWorkerInitializeConnectionByOid(Oid dboid, Oid useroid, bits32 flags) That's changing signatures just for the sake of breaking them. I would leave that alone, I guess.. @@ -719,6 +719,7 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username, Oid useroid, bool load_session_libraries, bool override_allow_connections, + bool bypass_login_check, char *out_dbname) I was not paying much attention here, but load_session_libraries gives a good argument in favor of switching all these booleans to a single bits32 argument as that would make three of them now, with a different set of flags than the bgworker ones. This can be refactored on its own. -#define BGWORKER_BYPASS_ALLOWCONN 1 +#define BGWORKER_BYPASS_ALLOWCONN 0x0001 Can be a change of its own as well. While looking at the refactoring at worker_spi. I've noticed that it would be simple and cheap to have some coverage for BYPASS_ALLOWCONN, something we've never done since this has been introduced. Let me suggest 0001 to add some coverage. 0002 is your own patch, with the tests simplified a bit. -- Michael --yZosu/sJ5BByIPik Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v5-0001-worker_spi-Add-tests-for-BGWORKER_BYPASS_ALLOWCON.patch" Content-Transfer-Encoding: quoted-printable =46rom fe8373992d2e2083d53e75ecd954ba2b71e454a1 Mon Sep 17 00:00:00 2001 =46rom: Michael Paquier Date: Thu, 5 Oct 2023 13:02:14 +0900 Subject: [PATCH v5 1/2] worker_spi: Add tests for BGWORKER_BYPASS_ALLOWCONN --- .../modules/worker_spi/t/001_worker_spi.pl | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/test/modules/worker_spi/t/001_worker_spi.pl b/src/test/mod= ules/worker_spi/t/001_worker_spi.pl index 4b46b1336b..7e5a4b1402 100644 --- a/src/test/modules/worker_spi/t/001_worker_spi.pl +++ b/src/test/modules/worker_spi/t/001_worker_spi.pl @@ -104,4 +104,29 @@ postgres|myrole|WorkerSpiMain]), 'dynamic bgworkers all launched' ) or die "Timed out while waiting for dynamic bgworkers to be launched"; =20 +# Check BGWORKER_BYPASS_ALLOWCONN. +$node->safe_psql('postgres', q(ALTER DATABASE mydb ALLOW_CONNECTIONS false= ;)); +my $log_offset =3D -s $node->logfile; + +# bgworker cannot be launched with connection restriction. +my $worker3_pid =3D $node->safe_psql('postgres', + qq[SELECT worker_spi_launch(12, $mydb_id, $myrole_id);]); +$node->wait_for_log( + qr/database "mydb" is not currently accepting connections/, $log_offset); + +$result =3D $node->safe_psql('postgres', + "SELECT count(*) FROM pg_stat_activity WHERE pid =3D $worker3_pid;"); +is($result, '0', 'dynamic bgworker without BYPASS_ALLOWCONN not started'); + +# bgworker bypasses the connection check, and can be launched. +my $worker4_pid =3D $node->safe_psql('postgres', + qq[SELECT worker_spi_launch(12, $mydb_id, $myrole_id, '{"ALLOWCONN"}');]); +ok( $node->poll_query_until( + 'postgres', + qq[SELECT datname, usename, wait_event FROM pg_stat_activity + WHERE backend_type =3D 'worker_spi dynamic' AND + pid IN ($worker4_pid) ORDER BY datname;], + qq[mydb|myrole|WorkerSpiMain]), + 'dynamic bgworker with BYPASS_ALLOWCONN started'); + done_testing(); --=20 2.42.0 --yZosu/sJ5BByIPik Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v5-0002-Allow-background-workers-to-bypass-login-check.patch" Content-Transfer-Encoding: quoted-printable =46rom 59b1e8827c20a3e801e64b3b089efb3d06d71f42 Mon Sep 17 00:00:00 2001 =46rom: Michael Paquier Date: Thu, 5 Oct 2023 14:06:37 +0900 Subject: [PATCH v5 2/2] Allow background workers to bypass login check This adds a new flag value (BGWORKER_BYPASS_ROLELOGINCHECK) to the flags being used in BackgroundWorkerInitializeConnection() and BackgroundWorkerInitializeConnectionByOid(). This flag allows the background workers to bypass the login check done in InitializeSessionUserId(). --- src/include/miscadmin.h | 4 +- src/include/postmaster/bgworker.h | 10 +++-- src/backend/bootstrap/bootstrap.c | 2 +- src/backend/postmaster/autovacuum.c | 5 +-- src/backend/postmaster/postmaster.c | 6 ++- src/backend/tcop/postgres.c | 1 + src/backend/utils/init/miscinit.c | 4 +- src/backend/utils/init/postinit.c | 5 ++- .../modules/worker_spi/t/001_worker_spi.pl | 37 +++++++++++++++++++ src/test/modules/worker_spi/worker_spi.c | 2 + doc/src/sgml/bgworker.sgml | 3 +- 11 files changed, 63 insertions(+), 16 deletions(-) diff --git a/src/include/miscadmin.h b/src/include/miscadmin.h index 14bd574fc2..f1d03f2df8 100644 --- a/src/include/miscadmin.h +++ b/src/include/miscadmin.h @@ -364,7 +364,8 @@ extern bool InSecurityRestrictedOperation(void); extern bool InNoForceRLSOperation(void); extern void GetUserIdAndContext(Oid *userid, bool *sec_def_context); extern void SetUserIdAndContext(Oid userid, bool sec_def_context); -extern void InitializeSessionUserId(const char *rolename, Oid roleid); +extern void InitializeSessionUserId(const char *rolename, Oid roleid, + bool bypass_login_check); extern void InitializeSessionUserIdStandalone(void); extern void SetSessionAuthorization(Oid userid, bool is_superuser); extern Oid GetCurrentRoleId(void); @@ -469,6 +470,7 @@ extern void InitPostgres(const char *in_dbname, Oid dbo= id, const char *username, Oid useroid, bool load_session_libraries, bool override_allow_connections, + bool bypass_login_check, char *out_dbname); extern void BaseInit(void); =20 diff --git a/src/include/postmaster/bgworker.h b/src/include/postmaster/bgw= orker.h index 7815507e3d..0fdbfaf431 100644 --- a/src/include/postmaster/bgworker.h +++ b/src/include/postmaster/bgworker.h @@ -141,18 +141,20 @@ extern PGDLLIMPORT BackgroundWorker *MyBgworkerEntry; * If dbname is NULL, connection is made to no specific database; * only shared catalogs can be accessed. */ -extern void BackgroundWorkerInitializeConnection(const char *dbname, const= char *username, uint32 flags); +extern void BackgroundWorkerInitializeConnection(const char *dbname, const= char *username, bits32 flags); =20 /* Just like the above, but specifying database and user by OID. */ -extern void BackgroundWorkerInitializeConnectionByOid(Oid dboid, Oid usero= id, uint32 flags); +extern void BackgroundWorkerInitializeConnectionByOid(Oid dboid, Oid usero= id, bits32 flags); =20 /* * Flags to BackgroundWorkerInitializeConnection et al * * - * Allow bypassing datallowconn restrictions when connecting to database + * Allow bypassing datallowconn restrictions and login check when connecti= ng + * to database */ -#define BGWORKER_BYPASS_ALLOWCONN 1 +#define BGWORKER_BYPASS_ALLOWCONN 0x0001 +#define BGWORKER_BYPASS_ROLELOGINCHECK 0x0002 =20 =20 /* Block/unblock signals in a background worker process */ diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/boot= strap.c index 5810f8825e..bdd005b66a 100644 --- a/src/backend/bootstrap/bootstrap.c +++ b/src/backend/bootstrap/bootstrap.c @@ -345,7 +345,7 @@ BootstrapModeMain(int argc, char *argv[], bool check_on= ly) if (pg_link_canary_is_frontend()) elog(ERROR, "backend is incorrectly linked to frontend functions"); =20 - InitPostgres(NULL, InvalidOid, NULL, InvalidOid, false, false, NULL); + InitPostgres(NULL, InvalidOid, NULL, InvalidOid, false, false, false, NUL= L); =20 /* Initialize stuff for bootstrap-file processing */ for (i =3D 0; i < MAXATTR; i++) diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/a= utovacuum.c index ae9be9b911..4686b81f68 100644 --- a/src/backend/postmaster/autovacuum.c +++ b/src/backend/postmaster/autovacuum.c @@ -488,7 +488,7 @@ AutoVacLauncherMain(int argc, char *argv[]) /* Early initialization */ BaseInit(); =20 - InitPostgres(NULL, InvalidOid, NULL, InvalidOid, false, false, NULL); + InitPostgres(NULL, InvalidOid, NULL, InvalidOid, false, false, false, NUL= L); =20 SetProcessingMode(NormalProcessing); =20 @@ -1706,8 +1706,7 @@ AutoVacWorkerMain(int argc, char *argv[]) * Note: if we have selected a just-deleted database (due to using * stale stats info), we'll fail and exit here. */ - InitPostgres(NULL, dbid, NULL, InvalidOid, false, false, - dbname); + InitPostgres(NULL, dbid, NULL, InvalidOid, false, false, false, dbname); SetProcessingMode(NormalProcessing); set_ps_display(dbname); ereport(DEBUG1, diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/p= ostmaster.c index 54e9bfb8c4..37f5b94469 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -5575,7 +5575,7 @@ MaxLivePostmasterChildren(void) * Connect background worker to a database. */ void -BackgroundWorkerInitializeConnection(const char *dbname, const char *usern= ame, uint32 flags) +BackgroundWorkerInitializeConnection(const char *dbname, const char *usern= ame, bits32 flags) { BackgroundWorker *worker =3D MyBgworkerEntry; =20 @@ -5589,6 +5589,7 @@ BackgroundWorkerInitializeConnection(const char *dbna= me, const char *username, u username, InvalidOid, /* role to connect as */ false, /* never honor session_preload_libraries */ (flags & BGWORKER_BYPASS_ALLOWCONN) !=3D 0, /* ignore datallowconn? */ + (flags & BGWORKER_BYPASS_ROLELOGINCHECK) !=3D 0, /* bypass login chec= k? */ NULL); /* no out_dbname */ =20 /* it had better not gotten out of "init" mode yet */ @@ -5602,7 +5603,7 @@ BackgroundWorkerInitializeConnection(const char *dbna= me, const char *username, u * Connect background worker to a database using OIDs. */ void -BackgroundWorkerInitializeConnectionByOid(Oid dboid, Oid useroid, uint32 f= lags) +BackgroundWorkerInitializeConnectionByOid(Oid dboid, Oid useroid, bits32 f= lags) { BackgroundWorker *worker =3D MyBgworkerEntry; =20 @@ -5616,6 +5617,7 @@ BackgroundWorkerInitializeConnectionByOid(Oid dboid, = Oid useroid, uint32 flags) NULL, useroid, /* role to connect as */ false, /* never honor session_preload_libraries */ (flags & BGWORKER_BYPASS_ALLOWCONN) !=3D 0, /* ignore datallowconn? */ + (flags & BGWORKER_BYPASS_ROLELOGINCHECK) !=3D 0, /* bypass login chec= k? */ NULL); /* no out_dbname */ =20 /* it had better not gotten out of "init" mode yet */ diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index 21b9763183..5c1e21b99d 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -4211,6 +4211,7 @@ PostgresMain(const char *dbname, const char *username) username, InvalidOid, /* role to connect as */ !am_walsender, /* honor session_preload_libraries? */ false, /* don't ignore datallowconn */ + false, /* don't bypass login check */ NULL); /* no out_dbname */ =20 /* diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/mis= cinit.c index 1e671c560c..182d666852 100644 --- a/src/backend/utils/init/miscinit.c +++ b/src/backend/utils/init/miscinit.c @@ -725,7 +725,7 @@ has_rolreplication(Oid roleid) * Initialize user identity during normal backend startup */ void -InitializeSessionUserId(const char *rolename, Oid roleid) +InitializeSessionUserId(const char *rolename, Oid roleid, bool bypass_logi= n_check) { HeapTuple roleTup; Form_pg_authid rform; @@ -789,7 +789,7 @@ InitializeSessionUserId(const char *rolename, Oid rolei= d) /* * Is role allowed to login at all? */ - if (!rform->rolcanlogin) + if (!bypass_login_check && !rform->rolcanlogin) ereport(FATAL, (errcode(ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION), errmsg("role \"%s\" is not permitted to log in", diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/pos= tinit.c index df4d15a50f..dcfeb30832 100644 --- a/src/backend/utils/init/postinit.c +++ b/src/backend/utils/init/postinit.c @@ -719,6 +719,7 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username, Oid useroid, bool load_session_libraries, bool override_allow_connections, + bool bypass_login_check, char *out_dbname) { bool bootstrap =3D IsBootstrapProcessingMode(); @@ -901,7 +902,7 @@ InitPostgres(const char *in_dbname, Oid dboid, } else { - InitializeSessionUserId(username, useroid); + InitializeSessionUserId(username, useroid, bypass_login_check); am_superuser =3D superuser(); } } @@ -910,7 +911,7 @@ InitPostgres(const char *in_dbname, Oid dboid, /* normal multiuser case */ Assert(MyProcPort !=3D NULL); PerformAuthentication(MyProcPort); - InitializeSessionUserId(username, useroid); + InitializeSessionUserId(username, useroid, false); /* ensure that auth_method is actually valid, aka authn_id is not NULL */ if (MyClientConnectionInfo.authn_id) InitializeSystemUser(MyClientConnectionInfo.authn_id, diff --git a/src/test/modules/worker_spi/t/001_worker_spi.pl b/src/test/mod= ules/worker_spi/t/001_worker_spi.pl index 7e5a4b1402..a8169c175b 100644 --- a/src/test/modules/worker_spi/t/001_worker_spi.pl +++ b/src/test/modules/worker_spi/t/001_worker_spi.pl @@ -128,5 +128,42 @@ ok( $node->poll_query_until( pid IN ($worker4_pid) ORDER BY datname;], qq[mydb|myrole|WorkerSpiMain]), 'dynamic bgworker with BYPASS_ALLOWCONN started'); +$node->safe_psql('postgres', q(ALTER DATABASE mydb ALLOW_CONNECTIONS true;= )); + +# Check BGWORKER_BYPASS_ROLELOGINCHECK. +# First create a role without login access. +$node->safe_psql( + 'postgres', qq[ + CREATE ROLE nologrole with nologin; + ALTER ROLE nologrole with superuser; +]); +my $nologrole_id =3D $node->safe_psql('mydb', + "SELECT oid FROM pg_roles where rolname =3D 'nologrole';"); +$log_offset =3D -s $node->logfile; + +# bgworker cannot be launched with login restriction. +my $worker5_pid =3D $node->safe_psql('postgres', + qq[SELECT worker_spi_launch(13, $mydb_id, $nologrole_id);]); +$node->wait_for_log(qr/role "nologrole" is not permitted to log in/, + $log_offset); + +$result =3D $node->safe_psql('postgres', + "SELECT count(*) FROM pg_stat_activity WHERE pid =3D $worker5_pid;"); +is($result, '0', + 'dynamic bgworker without BYPASS_ROLELOGINCHECK not started'); + +# bgworker bypasses the login restriction, and can be launched. +$log_offset =3D -s $node->logfile; +my $worker6_pid =3D $node->safe_psql('mydb', + qq(SELECT worker_spi_launch(13, $mydb_id, $nologrole_id, '{"ROLELOGINCHEC= K"}');) +); +ok( $node->poll_query_until( + 'mydb', + qq[SELECT datname, usename, wait_event FROM pg_stat_activity + WHERE backend_type =3D 'worker_spi dynamic' AND + pid =3D $worker6_pid;], + 'mydb|nologrole|WorkerSpiMain'), + 'dynamic bgworker with BYPASS_ROLELOGINCHECK launched' +) or die "Timed out while waiting for dynamic bgworkers to be launched"; =20 done_testing(); diff --git a/src/test/modules/worker_spi/worker_spi.c b/src/test/modules/wo= rker_spi/worker_spi.c index 5d81cf4563..af7256bd89 100644 --- a/src/test/modules/worker_spi/worker_spi.c +++ b/src/test/modules/worker_spi/worker_spi.c @@ -443,6 +443,8 @@ worker_spi_launch(PG_FUNCTION_ARGS) =20 if (strcmp(optname, "ALLOWCONN") =3D=3D 0) flags |=3D BGWORKER_BYPASS_ALLOWCONN; + else if (strcmp(optname, "ROLELOGINCHECK") =3D=3D 0) + flags |=3D BGWORKER_BYPASS_ROLELOGINCHECK; else ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), diff --git a/doc/src/sgml/bgworker.sgml b/doc/src/sgml/bgworker.sgml index 9ad1146ba0..7335c02ed8 100644 --- a/doc/src/sgml/bgworker.sgml +++ b/doc/src/sgml/bgworker.sgml @@ -200,7 +200,8 @@ typedef struct BackgroundWorker InvalidOid, the process will run as the superuser cr= eated during initdb. If BGWORKER_BYPASS_ALLOWCONN= is specified as flags it is possible to bypass the r= estriction - to connect to databases not allowing user connections. + to connect to databases not allowing user connections. If BGWO= RKER_BYPASS_ROLELOGINCHECK + is specified as flags it is possible to bypass the l= ogin check to connect to databases. A background worker can only call one of these two functions, and only once. It is not possible to switch databases. --=20 2.42.0 --yZosu/sJ5BByIPik-- --MI2NUVE1/ZGVoKI7 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmUeRUQACgkQnvQgOdby QH2wqA//YY2L0mikTxdu5NoAOpTB/T+SE1Ch1pdkZF6d/IlSCpSiKXUPK6cvE7FK B9hNgSu13FXEY+RF2XRjOLyf31xXaoruiQHRpov8zetGP13b/QGqazdtmsY4hwu2 fLjDbvu+AOa1oi763tevECN1KwrQ/V5haJ6ZPEF+WXT7L2gBA+ZaTOtuaLjq7Zc+ pkLxtQ/E3rumnBz4bVbKcL3H+PN/96K2SXLK4avjTu4S2Jqfdz3KxKQdAdPLZLmw v8FT8gxs+KO88TukX1T3HDgf+F4fSdAv3cKBvSML6vPYmgCl5TKcZfAdmwAct3XG JZMxkOKTDqmniW6fd1KcAUvKzkFR2YAO2GLHzDEd4NIv8sYduj69UkFIy33yEUla a3ByRIJXBeG7MQ9gCtzaIjCp5kKvMSHD8sHVwwmLGQ87UN91chCDoqK7UhcET5rL L9LIS/hbehve0CdOmBYguJfBhUHhorURV3GjLIF6qrrLO3meZjLrojYQhk5LHg10 c+xBgN5T/9af8y0I+VCX5EI8wCVv24z5M6nPaL0g3rJJAEJ+38ibE85dP8UsAagR n21mE1xSSMVqz86/EqQZ1xthWxOm4AJjLy3Q4YuDRIk7T2tII0/6CeRzE7JQmXd+ TKMWxvlxI0rFzaT1u2g226ZSs8mBFRFgJzfQ6zOTrcp7iwg0rUc= =WRxi -----END PGP SIGNATURE----- --MI2NUVE1/ZGVoKI7--