pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Matheus Alcantara <matheusssilv97@gmail.com>
To: Nathan Bossart <nathandbossart@gmail.com>
Cc: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Cc: pgsql-hackers@postgresql.org
Cc: alvherre@kurilemu.de
Subject: Re: REPACK (CONCURRENTLY) fails when table owner lacks CONNECT
Date: Thu, 27 Aug 2026 16:52:32 -0300
Message-ID: <9c2c4193-0de8-48a7-92be-fa468de6bd4f@gmail.com> (raw)
In-Reply-To: <apCNsqM7uGJwXUa5@nathan>
References: <apBbzFd_EYAfHV45@nathan>
	<3afc9eed-67eb-45a6-8e15-5972404635c3@gmail.com>
	<CALj2ACVioNbKZK1MuMsyUCbwb9Fvw0K=hZYfbwn5pLm7OXaODA@mail.gmail.com>
	<DKZYDQBK71EG.MRKXKB9IINVJ@gmail.com>
	<apCNsqM7uGJwXUa5@nathan>

On 27/08/26 16:19, Nathan Bossart wrote:
> The patch looks reasonable to me.
> 
> On Thu, Aug 27, 2026 at 03:55:11PM -0300, Matheus Alcantara wrote:
>> Added this new test case on attached.
> 
> I'm not sure the new tests are necessary.  It seems unlikely that we'll
> accidentally remove the flags down the road.
> 

Yeah, I also think that is unlikely that we'll remove, I just put the
test to be more conservative. I think that is good to have such tests
to ensure that these bugs are not re-introduced but given that this
seems a minor/oversight I'm not totally against not adding them.
Attached is v3 without the tests.

--
Matheus Alcantara
EDB: https://www.enterprisedb.com

Attachments:

v3-0001-Let-the-REPACK-decoding-worker-bypass-connection-.patch (text/plain, 2.2K) download From 7f5ec60686edbc3c0555bfa5c743719405321002 Mon Sep 17 00:00:00 2001 From: Matheus Alcantara <mths.dev@pm.me> Date: Thu, 27 Aug 2026 15:07:39 -0300 Subject: [PATCH v3] Let the REPACK decoding worker bypass connection privilege checks REPACK (CONCURRENTLY) launches a background worker to decode the changes made while the table is being rewritten. Since cluster_rel() switches the current user to the owner of the table being repacked, that is the role the worker connects as, and the worker asked for a bypass of the LOGIN check only. The CONNECT privilege on the database was therefore still checked against the table owner, who has no reason to have it, so the command could fail with ERROR: permission denied for database "d" DETAIL: User does not have CONNECT privilege. CONTEXT: REPACK decoding worker Pass BGWORKER_BYPASS_ALLOWCONN as well, as parallel.c already does for parallel workers: the backend that launched the worker is connected to the database already, and the worker only decodes changes on its behalf. Author: Matheus Alcantara <mths.dev@pm.me> Reported-by: Nathan Bossart <nathandbossart@gmail.com> Discussion: https://www.postgresql.org/message-id/apBbzFd_EYAfHV45@nathan --- src/backend/commands/repack_worker.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/backend/commands/repack_worker.c b/src/backend/commands/repack_worker.c index af7e2a94764..a49b681059f 100644 --- a/src/backend/commands/repack_worker.c +++ b/src/backend/commands/repack_worker.c @@ -101,8 +101,15 @@ RepackWorkerMain(Datum main_arg) pq_set_parallel_leader(shared->backend_pid, shared->backend_proc_number); - /* Connect to the database. LOGIN is not required. */ + /* + * Connect to the database. Like parallel workers do, we skip the + * connection authorization checks. The backend that launched us is + * already connected to this database, and the role we run as is the owner + * of the table being repacked, which needs neither the LOGIN attribute + * nor the CONNECT privilege for our purposes. + */ BackgroundWorkerInitializeConnectionByOid(shared->dbid, shared->roleid, + BGWORKER_BYPASS_ALLOWCONN | BGWORKER_BYPASS_ROLELOGINCHECK); /* -- 2.50.1 (Apple Git-155)

view thread (12+ messages)  latest in thread

Message-ID: <9c2c4193-0de8-48a7-92be-fa468de6bd4f@gmail.com>
Permalink:  ../9c2c4193-0de8-48a7-92be-fa468de6bd4f@gmail.com/
Also on:    postgresql.org/message-id/9c2c4193-0de8-48a7-92be-fa468de6bd4f@gmail.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: matheusssilv97@gmail.com, nathandbossart@gmail.com, bharath.rupireddyforpostgres@gmail.com, alvherre@kurilemu.de
  Subject: Re: REPACK (CONCURRENTLY) fails when table owner lacks CONNECT
  In-Reply-To: <9c2c4193-0de8-48a7-92be-fa468de6bd4f@gmail.com>
  References: <apBbzFd_EYAfHV45@nathan> <3afc9eed-67eb-45a6-8e15-5972404635c3@gmail.com> <CALj2ACVioNbKZK1MuMsyUCbwb9Fvw0K=hZYfbwn5pLm7OXaODA@mail.gmail.com> <DKZYDQBK71EG.MRKXKB9IINVJ@gmail.com> <apCNsqM7uGJwXUa5@nathan> <9c2c4193-0de8-48a7-92be-fa468de6bd4f@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox