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 1rKbKP-003TNx-4Y for pgsql-hackers@arkaria.postgresql.org; Tue, 02 Jan 2024 09:44:53 +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 1rKbKN-00Eoj9-MW for pgsql-hackers@arkaria.postgresql.org; Tue, 02 Jan 2024 09:44:51 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rKbKN-00Eoj1-Bd for pgsql-hackers@lists.postgresql.org; Tue, 02 Jan 2024 09:44:51 +0000 Received: from mail-lj1-x22d.google.com ([2a00:1450:4864:20::22d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rKbKL-00F89w-Id for pgsql-hackers@postgresql.org; Tue, 02 Jan 2024 09:44:50 +0000 Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2cd03f1b385so10402051fa.1 for ; Tue, 02 Jan 2024 01:44:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704188688; x=1704793488; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=HXQR5TWkpD3nfBZC0F/ParHDKeBbTVaGfgb7VhKc/Kc=; b=W1INonr8ygQPTz24+GG/0s/R9hm/I8Kisyq4RzqDMOpzMTQNl2CbmOPAbxOKjrsaJx Qr73bV0GkkAWMqcOK7I3paKKaGJOjlUEWQrAzLVoOg4rHmJBGqgExj7fTML5oxIWM7v4 M3wmbms5GKoJqxeuwo4LL4NHbDrACeZMg4S4DmzcgLDGkgxT8RWHU6DDdTAaWt1kwZoM z0zayFLi+mHQznn4MrmgdMdxmjQGenIcoFVg2c2p1W2NljIfcJqw1g3nPuFT85qwDMbI nvJPSdDoYwyhgAVhv1+t/atVQdN5uV6huUbK9bqtQiPkdJDfm0UHYURKiaF4/GfqONeb VCdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704188688; x=1704793488; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HXQR5TWkpD3nfBZC0F/ParHDKeBbTVaGfgb7VhKc/Kc=; b=oFslj7Dh17j/1g75bM0uu7Mryimab7G6L6DVlMoVJG7g/K47GZmEgzQ+6W+4RRG4j0 iNl3SlxxpaWgJkHEjHvb9IjMEvadRdJrrZsw9VzF9XI58TR3yDyo2RZ/tzhwiCMiccgC cDYW6mh67eWTkXIxJOxEalkiAGTE5hziLjKk69vWbLspGxq7JUKHg+LwpIUdFhre7mmK S0wJ3YTVVOladsccHeOx6WMetZycznKrlDsD1Qha00fCnYE53FJX2hkcZFwLN9zFj03C cU41JMwGTzrUop0X9QCa6iLqxvqU5h232NSfrym81ydHWYrAINHYYU5Cd6O8uR5p3VH5 cinQ== X-Gm-Message-State: AOJu0YxG8zsr5qsSwr0IE+wdg846ErvbbrxSZSZ4KL7aXoq/t7M9jhgm KWg56qATypfM15+zGAq3+HPaJccu0FTOrIcdT44= X-Google-Smtp-Source: AGHT+IH5FjeJTPQ5bcyKfjGuU8H08A5O8bxtRk+vkleW6rMX+ok5o+TbrC65AJtBUQX2NICRe+V7N/4g2Md2Wx9XPBw= X-Received: by 2002:a2e:a993:0:b0:2cc:defb:48a5 with SMTP id x19-20020a2ea993000000b002ccdefb48a5mr5344158ljq.20.1704188687982; Tue, 02 Jan 2024 01:44:47 -0800 (PST) MIME-Version: 1.0 References: <149ff9264db27cdf724b65709fbbaee4bf316835.camel@j-davis.com> <830a2bc6cbbb2e6e01c6c0d9f31f320822e10603.camel@j-davis.com> <433d0845248e86c0317d9d396926182cfe157340.camel@j-davis.com> <05ae37abb207cd6bf6b126780024692d91402b0b.camel@j-davis.com> <93392ffa941ab0d436e19e0ab5d04d0e42c02d3f.camel@j-davis.com> <26be917cb07b6aa3ef5dd15f6b59d1b375ece6e8.camel@j-davis.com> In-Reply-To: <26be917cb07b6aa3ef5dd15f6b59d1b375ece6e8.camel@j-davis.com> From: Bharath Rupireddy Date: Tue, 2 Jan 2024 15:14:36 +0530 Message-ID: Subject: Re: [17] CREATE SUBSCRIPTION ... SERVER To: Jeff Davis Cc: Ashutosh Bapat , Joe Conway , pgsql-hackers@postgresql.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Jan 1, 2024 at 12:29=E2=80=AFAM Jeff Davis wrot= e: > > On Fri, 2023-12-29 at 15:22 -0800, Jeff Davis wrote: > > On Tue, 2023-09-05 at 12:08 -0700, Jeff Davis wrote: > > > OK, so we could have a built-in FDW called pg_connection that would > > > do > > > the right kinds of validation; and then also allow other FDWs but > > > the > > > subscription would have to do its own validation. > > > > Attached a rough rebased version. > > Attached a slightly better version which fixes a pg_dump issue and > improves the documentation. Hi, I spent some time today reviewing the v4 patch and below are my comments. BTW, the patch needs a rebase due to commit 9a17be1e2. 1. + /* + * We don't want to allow unprivileged users to be able to trigger + * attempts to access arbitrary network destinations, so require the user + * to have been specifically authorized to create connections. + */ + if (!has_privs_of_role(owner, ROLE_PG_CREATE_CONNECTION)) Can the pg_create_connection predefined role related code be put into a separate 0001 patch? I think this can go in a separate commit. 2. Can one use {FDW, user_mapping, foreign_server} combo other than the built-in pg_connection_fdw? If yes, why to allow say oracle_fdw foreign server and user mapping with logical replication? Isn't this a security concern? 3. I'd like to understand how the permission model works with this feature amidst various users a) subscription owner b) table owner c) FDW owner d) user mapping owner e) foreign server owner f) superuser g) user with which logical replication bg workers (table sync, {parallel} apply workers) are started up and running. What if foreign server owner doesn't have permissions on the table being applied by logical replication bg workers? What if foreign server owner is changed with ALTER SERVER ... OWNER TO when logical replication is in-progress? What if the owner of {FDW, user_mapping, foreign_server} is different from a subscription owner with USAGE privilege granted? Can the subscription still use the foreign server? 4. How does the invalidation of {FDW, user_mapping, foreign_server} affect associated subscription and vice-versa? 5. What if the password is changed in user mapping with ALTER USER MAPPING? Will it refresh the subscription so that all the logical replication workers get restarted with new connection info? 6. How does this feature fit if a subscription is created with run_as_owner? Will it check if the table owner has permissions to use {FDW, user_mapping, foreign_server} comob? 7. + if (strcmp(d->defname, "user") =3D=3D 0 || + strcmp(d->defname, "password") =3D=3D 0 || + strcmp(d->defname, "sslpassword") =3D=3D 0 || + strcmp(d->defname, "password_required") =3D=3D 0) + ereport(ERROR, + (errmsg("invalid option \"%s\" for pg_connection_f= dw", + ereport(ERROR, + (errmsg("invalid user mapping option \"%s\" for pg_connection_fdw", + d->defname))); Can we emit an informative error message and hint using initClosestMatch, updateClosestMatch, getClosestMatch similar to other FDWs elsewhere in the code? 8. + errmsg("password is required"), + errdetail("Non-superusers must provide a password in the connection string."))); The error message and detail look generic, can it be improved to include something about pg_connection_fdw? 9. +{ oid =3D> '6015', oid_symbol =3D> 'PG_CONNECTION_FDW', + descr =3D> 'Pseudo FDW for connections to Postgres', + fdwname =3D> 'pg_connection_fdw', fdwowner =3D> 'POSTGRES', What if the database cluster is initialized with an owner different than 'POSTGRES' at the time of initdb? Will the fdwowner be correct in that case? 10. +# src/include/catalog/pg_foreign_data_wrapper.dat +{ oid =3D> '6015', oid_symbol =3D> 'PG_CONNECTION_FDW', Do we want to REVOKE USAGE ON FOREIGN DATA WRAPPER pg_connection_fdw FROM PUBLIC and REVOKE EXECUTE ON its handler functions? With this, the permissions are granted explicitly to the foreign server/user mapping creators. 11. How about splitting patches in the following manner for better manageability (all of which can go as separate commits) of this feature? 0001 for pg_create_connection predefined role per comment #1. 0002 for introducing in-built FDW pg_connection_fdw. 0003 utilizing in-built FDW for logical replication to provide CREATE SUBSCRIPTION ... SERVER. -- Bharath Rupireddy PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com