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 1ra0LR-007cfU-Br for pgsql-hackers@arkaria.postgresql.org; Tue, 13 Feb 2024 21:29:37 +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 1ra0LQ-002ZtZ-25 for pgsql-hackers@arkaria.postgresql.org; Tue, 13 Feb 2024 21:29:36 +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 1ra0LP-002ZtQ-LZ for pgsql-hackers@lists.postgresql.org; Tue, 13 Feb 2024 21:29:35 +0000 Received: from mail-il1-x136.google.com ([2607:f8b0:4864:20::136]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1ra0LM-0072vu-Md for pgsql-hackers@postgresql.org; Tue, 13 Feb 2024 21:29:35 +0000 Received: by mail-il1-x136.google.com with SMTP id e9e14a558f8ab-36423ed3fdbso2194625ab.2 for ; Tue, 13 Feb 2024 13:29:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707859770; x=1708464570; darn=postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=4dMeySajRxa7xFL8594vTPuqvVQhV5G85Gt5KQZQWyA=; b=Z7/JKDK+NUkLtcwP3nAgQjMQCtYrYuwUz3OpHOc+8hy5BZEH8NlgkDe0hIMmBBUJtU SB42F7fOjSEl9tL5DKOO8aCdY5Equ3ss+CNSLuwCziDVPJ5HNg3ks8efzyqPHGzNhLPa SXddiVLoEq6Pzp2JzWYtQXH5wVMDkhliEx8PaHcid4f4WdIwmDVHGF7XkTvJqvaAcvbv eaLBCnU2JXxcsJgPYlgQWjcEWHv/ogbvcB4d5DUEAJCAEsTyC5gth/8O9/TevGGpy+cm n3hK0JhZdxdlFq6cY3qzsmBF83WKPgzTcrMoXr6u5N7+XZ0JOuNfngneXJkCkdm/4Z4R HX3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707859770; x=1708464570; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=4dMeySajRxa7xFL8594vTPuqvVQhV5G85Gt5KQZQWyA=; b=wK1oOgEj34PO7Nr2Vce0NnUIH+vczE3pGTP8C6aT77kvaqaNYUyXKixKVwcdUijYvN 8cMaxR6Y6v2oN6jnL+qN7Lm+M5JajIq7h3ZZXNgSpbUmdKIwYlm3laJhM0NDvvdnD83n dFoGBUMrcbDcXAHkOciGdJ8CbxZl+1Wwdena0WOHr345EgImhT8JSLkdTHiW3ts/mJGW mhSWdVNY3oN74ZnIrrgPrX/eooOpABVpU+hupNyHRfey2qfDYSlNqQmt+m/Czzx4ujZV qCqmBbf9x6c0/+J6IKXpIa2jz9g8PDr72AsJD8obJM7LxPOHmchRPhVvOk3xj08WrrjW IBEw== X-Gm-Message-State: AOJu0YwdHU+h+xTI767rVI3PWtUXbw0Pwn4p6++Tvmt6iE+e83ws5W/I SHiL6I/1+OUyEChdU9tAprmU6WqOVW33LEA1MYV3//McCLiMICDR X-Google-Smtp-Source: AGHT+IHIwY9SlGK2/ShadyeGGBkVq/smvyC1yQ4Pfte3RyE5AGHl8APQrY7AplCbV7xCNAzJ6GVVTg== X-Received: by 2002:a05:6e02:6cf:b0:363:e80e:a9a1 with SMTP id p15-20020a056e0206cf00b00363e80ea9a1mr981696ils.27.1707859770048; Tue, 13 Feb 2024 13:29:30 -0800 (PST) Received: from nathanxps13 (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id bp28-20020a056e02349c00b00363909191b8sm2703926ilb.39.2024.02.13.13.29.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 13:29:29 -0800 (PST) Date: Tue, 13 Feb 2024 15:29:28 -0600 From: Nathan Bossart To: Pavlo Golub Cc: pgsql-hackers Subject: Re: [PATCH] allow pg_current_logfile() execution under pg_monitor role Message-ID: <20240213212928.GA262402@nathanxps13> References: <20240209163657.GC663211@nathanxps13> <20240212154945.GA1645880@nathanxps13> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="NzB8fVQJ5HfG6fxh" Content-Disposition: inline In-Reply-To: <20240212154945.GA1645880@nathanxps13> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --NzB8fVQJ5HfG6fxh Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Feb 12, 2024 at 09:49:45AM -0600, Nathan Bossart wrote: > Okay. I'll plan on committing this in the next few days. Here is what I have staged for commit. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com --NzB8fVQJ5HfG6fxh Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0001-Allow-pg_monitor-to-execute-pg_current_logfile.patch" From bfe542c5d7b3c981e75ac6551abb34fbdf646eea Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Tue, 13 Feb 2024 15:12:36 -0600 Subject: [PATCH v2 1/1] Allow pg_monitor to execute pg_current_logfile(). We allow roles with privileges of pg_monitor to execute functions like pg_ls_logdir(), so it seems natural that such roles would also be able to execute this function. Bumps catversion. Co-authored-by: Pavlo Golub Discussion: https://postgr.es/m/CAK7ymcLmEYWyQkiCZ64WC-HCzXAB0omM%3DYpj9B3rXe8vUAFMqw%40mail.gmail.com --- doc/src/sgml/func.sgml | 5 +++++ src/backend/catalog/system_functions.sql | 4 ++++ src/include/catalog/catversion.h | 2 +- src/test/regress/expected/misc_functions.out | 20 ++++++++++++++++++++ src/test/regress/sql/misc_functions.sql | 11 +++++++++++ 5 files changed, 41 insertions(+), 1 deletion(-) diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 11d537b341..c4e5b4967e 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -23735,6 +23735,11 @@ SELECT * FROM pg_ls_dir('.') WITH ORDINALITY AS t(ls,n); . The result reflects the contents of the current_logfiles file. + + + This function is restricted to superusers and roles with privileges of + the pg_monitor role by default, but other users can + be granted EXECUTE to run the function. diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql index 346cfb98a0..fe2bb50f46 100644 --- a/src/backend/catalog/system_functions.sql +++ b/src/backend/catalog/system_functions.sql @@ -777,6 +777,10 @@ GRANT EXECUTE ON FUNCTION pg_ls_logicalmapdir() TO pg_monitor; GRANT EXECUTE ON FUNCTION pg_ls_replslotdir(text) TO pg_monitor; +GRANT EXECUTE ON FUNCTION pg_current_logfile() TO pg_monitor; + +GRANT EXECUTE ON FUNCTION pg_current_logfile(text) TO pg_monitor; + GRANT pg_read_all_settings TO pg_monitor; GRANT pg_read_all_stats TO pg_monitor; diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h index 9fc8ac9290..80a4c19565 100644 --- a/src/include/catalog/catversion.h +++ b/src/include/catalog/catversion.h @@ -57,6 +57,6 @@ */ /* yyyymmddN */ -#define CATALOG_VERSION_NO 202401301 +#define CATALOG_VERSION_NO 202402131 #endif diff --git a/src/test/regress/expected/misc_functions.out b/src/test/regress/expected/misc_functions.out index 7c15477104..d5f61dfad9 100644 --- a/src/test/regress/expected/misc_functions.out +++ b/src/test/regress/expected/misc_functions.out @@ -683,3 +683,23 @@ SELECT gist_stratnum_identity(18::smallint); 18 (1 row) +-- pg_current_logfile +CREATE ROLE regress_current_logfile; +-- not available by default +SELECT has_function_privilege('regress_current_logfile', + 'pg_current_logfile()', 'EXECUTE'); + has_function_privilege +------------------------ + f +(1 row) + +GRANT pg_monitor TO regress_current_logfile; +-- role has privileges of pg_monitor and can execute the function +SELECT has_function_privilege('regress_current_logfile', + 'pg_current_logfile()', 'EXECUTE'); + has_function_privilege +------------------------ + t +(1 row) + +DROP ROLE regress_current_logfile; diff --git a/src/test/regress/sql/misc_functions.sql b/src/test/regress/sql/misc_functions.sql index 851dad90f4..928b04db7f 100644 --- a/src/test/regress/sql/misc_functions.sql +++ b/src/test/regress/sql/misc_functions.sql @@ -254,3 +254,14 @@ FROM pg_walfile_name_offset('0/0'::pg_lsn + :segment_size - 1), -- test stratnum support functions SELECT gist_stratnum_identity(3::smallint); SELECT gist_stratnum_identity(18::smallint); + +-- pg_current_logfile +CREATE ROLE regress_current_logfile; +-- not available by default +SELECT has_function_privilege('regress_current_logfile', + 'pg_current_logfile()', 'EXECUTE'); +GRANT pg_monitor TO regress_current_logfile; +-- role has privileges of pg_monitor and can execute the function +SELECT has_function_privilege('regress_current_logfile', + 'pg_current_logfile()', 'EXECUTE'); +DROP ROLE regress_current_logfile; -- 2.25.1 --NzB8fVQJ5HfG6fxh--