1
0
mirror of https://github.com/postgres/postgres.git synced 2026-10-23 13:29:09 +03:00

Fix REPACK (CONCURRENTLY) when the table owner lacks CONNECT.

REPACK (CONCURRENTLY) launches a background worker to decode changes
made while the table is being rewritten. The worker connects as the
table owner but bypassed the LOGIN check only, so CONNECT was still
checked against a role that need not have it, and the command could
fail with "permission denied for database".

Pass BGWORKER_BYPASS_ALLOWCONN as well, as we do for parallel
workers. That is safe because the leader already checked the invoking
user's privileges on the table before starting the worker.

Reported-by: Nathan Bossart <nathandbossart@gmail.com>
Author: Matheus Alcantara <mths.dev@pm.me>
Reviewed-by: Nathan Bossart <nathandbossart@gmail.com>
Reviewed-by: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Reviewed-by: Álvaro Herrera <alvherre@kurilemu.de>
Discussion: https://postgr.es/m/apBbzFd_EYAfHV45@nathan
Backpatch-through: 19
This commit is contained in:
Masahiko Sawada
2026-09-08 12:06:09 -07:00
parent fe7b607234
commit 9bf3a41456

View File

@@ -101,8 +101,14 @@ 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, skipping the connection authorization checks
* as parallel workers do. Note that we run as the owner of the table
* being repacked, who need not be able to log in or connect; the leader
* checked the invoking user's privileges before starting us.
*/
BackgroundWorkerInitializeConnectionByOid(shared->dbid, shared->roleid,
BGWORKER_BYPASS_ALLOWCONN |
BGWORKER_BYPASS_ROLELOGINCHECK);
/*