From 45b479a836ec5434933b5d57fdc2c215b7e11b61 Mon Sep 17 00:00:00 2001 From: Jeff Davis Date: Wed, 5 Aug 2026 13:19:10 -0700 Subject: [PATCH] Revert "Validate subscription conninfo on owner change" This reverts commit 1c9c35890421e96a91129b51f2c6446a6d95af95. Raising errors during OWNER TO can cause problems during restore. An upcoming commit will avoid other errors that can happen in this path. Reviewed-by: Amit Kapila Discussion: https://postgr.es/m/e103ae8daf74485e0c0ebde297fae735d38f54d1.camel@j-davis.com Backpatch-through: 19 --- doc/src/sgml/ref/alter_subscription.sgml | 7 ------- src/backend/commands/subscriptioncmds.c | 14 ++------------ src/test/regress/expected/subscription.out | 17 ----------------- src/test/regress/regress.c | 9 --------- src/test/regress/sql/subscription.sql | 15 --------------- 5 files changed, 2 insertions(+), 60 deletions(-) diff --git a/doc/src/sgml/ref/alter_subscription.sgml b/doc/src/sgml/ref/alter_subscription.sgml index 04388ebf82d..8632657e45a 100644 --- a/doc/src/sgml/ref/alter_subscription.sgml +++ b/doc/src/sgml/ref/alter_subscription.sgml @@ -53,13 +53,6 @@ ALTER SUBSCRIPTION name RENAME TO < to alter the owner, you must be able to SET ROLE to the new owning role. If the subscription has password_required=false, only superusers can modify it. - If the subscription uses a foreign server, the new owner must have - USAGE privilege on the foreign server, a user mapping - for the new owner or for PUBLIC must exist, and the - connection string generated for the new owner must be valid. If the new - owner is not a superuser and the subscription has - password_required=true, the generated connection string - must include a password. diff --git a/src/backend/commands/subscriptioncmds.c b/src/backend/commands/subscriptioncmds.c index 70d94016e2f..50a5e279252 100644 --- a/src/backend/commands/subscriptioncmds.c +++ b/src/backend/commands/subscriptioncmds.c @@ -2791,12 +2791,11 @@ AlterSubscriptionOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId) /* * If the subscription uses a server, check that the new owner has USAGE - * privileges on the server, that a user mapping exists, and that the - * resulting connection string is valid for the new owner. + * privileges on the server and that a user mapping exists. Note: does not + * re-check the resulting connection string. */ if (OidIsValid(form->subserver)) { - char *conninfo; ForeignServer *server = GetForeignServer(form->subserver); aclresult = object_aclcheck(ForeignServerRelationId, server->serverid, newOwnerId, ACL_USAGE); @@ -2809,15 +2808,6 @@ AlterSubscriptionOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId) /* make sure a user mapping exists */ GetUserMapping(newOwnerId, server->serverid); - - conninfo = ForeignServerConnectionString(newOwnerId, server); - - /* Load the library providing us libpq calls. */ - load_file("libpqwalreceiver", false); - /* Check the connection info string. */ - walrcv_check_conninfo(conninfo, - form->subpasswordrequired && - !superuser_arg(newOwnerId)); } form->subowner = newOwnerId; diff --git a/src/test/regress/expected/subscription.out b/src/test/regress/expected/subscription.out index b023e6fa563..c034b25f3d5 100644 --- a/src/test/regress/expected/subscription.out +++ b/src/test/regress/expected/subscription.out @@ -9,10 +9,6 @@ CREATE FUNCTION test_fdw_connection(oid, oid, internal) RETURNS text AS :'regresslib', 'test_fdw_connection' LANGUAGE C; -CREATE FUNCTION test_fdw_connection_no_password(oid, oid, internal) - RETURNS text - AS :'regresslib', 'test_fdw_connection_no_password' - LANGUAGE C; CREATE ROLE regress_subscription_user LOGIN SUPERUSER; CREATE ROLE regress_subscription_user2; CREATE ROLE regress_subscription_user3 IN ROLE pg_create_subscription; @@ -191,18 +187,6 @@ CREATE SUBSCRIPTION regress_testsub6 SERVER test_server WARNING: subscription was created, but is not connected HINT: To initiate replication, you must manually create the replication slot, enable the subscription, and alter the subscription to refresh publications. RESET SESSION AUTHORIZATION; -GRANT USAGE ON FOREIGN SERVER test_server TO regress_subscription_user2; -CREATE USER MAPPING FOR regress_subscription_user2 SERVER test_server OPTIONS(user 'foo'); -ALTER FOREIGN DATA WRAPPER test_fdw CONNECTION test_fdw_connection_no_password; -WARNING: changing the foreign-data wrapper connection function can cause the options for dependent objects to become invalid --- fail, new owner's generated conninfo must satisfy password_required -ALTER SUBSCRIPTION regress_testsub6 OWNER TO regress_subscription_user2; -ERROR: password is required -DETAIL: Non-superusers must provide a password in the connection string. -ALTER FOREIGN DATA WRAPPER test_fdw CONNECTION test_fdw_connection; -WARNING: changing the foreign-data wrapper connection function can cause the options for dependent objects to become invalid -DROP USER MAPPING FOR regress_subscription_user2 SERVER test_server; -REVOKE USAGE ON FOREIGN SERVER test_server FROM regress_subscription_user2; -- fail, subscription depends on the server and cannot be dropped by CASCADE DROP SERVER test_server CASCADE; ERROR: cannot drop server test_server because subscription regress_testsub6 depends on it @@ -260,7 +244,6 @@ HINT: Use DROP ... CASCADE to drop the dependent objects too. ALTER FOREIGN DATA WRAPPER test_fdw NO CONNECTION; WARNING: removing the foreign-data wrapper connection function will cause dependent subscriptions to fail DROP FUNCTION test_fdw_connection(oid, oid, internal); -DROP FUNCTION test_fdw_connection_no_password(oid, oid, internal); DROP FOREIGN DATA WRAPPER test_fdw; -- fail - invalid connection string during ALTER ALTER SUBSCRIPTION regress_testsub CONNECTION 'foobar'; diff --git a/src/test/regress/regress.c b/src/test/regress/regress.c index 3cc3756a81a..90bb2a7e881 100644 --- a/src/test/regress/regress.c +++ b/src/test/regress/regress.c @@ -742,15 +742,6 @@ test_fdw_connection(PG_FUNCTION_ARGS) PG_RETURN_TEXT_P(cstring_to_text("dbname=regress_doesnotexist user=doesnotexist password=secret")); } -PG_FUNCTION_INFO_V1(test_fdw_connection_no_password); -Datum -test_fdw_connection_no_password(PG_FUNCTION_ARGS) -{ - /* Ensure the test fails if no valid user mapping exists. */ - GetUserMapping(PG_GETARG_OID(0), PG_GETARG_OID(1)); - PG_RETURN_TEXT_P(cstring_to_text("dbname=regress_doesnotexist user=doesnotexist")); -} - PG_FUNCTION_INFO_V1(is_catalog_text_unique_index_oid); Datum is_catalog_text_unique_index_oid(PG_FUNCTION_ARGS) diff --git a/src/test/regress/sql/subscription.sql b/src/test/regress/sql/subscription.sql index c5a011fc4ef..cbdaaa9294d 100644 --- a/src/test/regress/sql/subscription.sql +++ b/src/test/regress/sql/subscription.sql @@ -12,10 +12,6 @@ CREATE FUNCTION test_fdw_connection(oid, oid, internal) RETURNS text AS :'regresslib', 'test_fdw_connection' LANGUAGE C; -CREATE FUNCTION test_fdw_connection_no_password(oid, oid, internal) - RETURNS text - AS :'regresslib', 'test_fdw_connection_no_password' - LANGUAGE C; CREATE ROLE regress_subscription_user LOGIN SUPERUSER; CREATE ROLE regress_subscription_user2; @@ -137,16 +133,6 @@ CREATE SUBSCRIPTION regress_testsub6 SERVER test_server PUBLICATION testpub WITH (slot_name = 'dummy', connect = false); RESET SESSION AUTHORIZATION; -GRANT USAGE ON FOREIGN SERVER test_server TO regress_subscription_user2; -CREATE USER MAPPING FOR regress_subscription_user2 SERVER test_server OPTIONS(user 'foo'); -ALTER FOREIGN DATA WRAPPER test_fdw CONNECTION test_fdw_connection_no_password; - --- fail, new owner's generated conninfo must satisfy password_required -ALTER SUBSCRIPTION regress_testsub6 OWNER TO regress_subscription_user2; - -ALTER FOREIGN DATA WRAPPER test_fdw CONNECTION test_fdw_connection; -DROP USER MAPPING FOR regress_subscription_user2 SERVER test_server; -REVOKE USAGE ON FOREIGN SERVER test_server FROM regress_subscription_user2; -- fail, subscription depends on the server and cannot be dropped by CASCADE DROP SERVER test_server CASCADE; @@ -208,7 +194,6 @@ DROP FUNCTION test_fdw_connection(oid, oid, internal); ALTER FOREIGN DATA WRAPPER test_fdw NO CONNECTION; DROP FUNCTION test_fdw_connection(oid, oid, internal); -DROP FUNCTION test_fdw_connection_no_password(oid, oid, internal); DROP FOREIGN DATA WRAPPER test_fdw;