information_schema.applicable_roles reports a role with no usable membership option
Thread notes
1 note#bug
hackorum-bot#bug
@global #bug
information_schema.applicable_roles reports a role when both membership options are disabled
Description
PostgreSQL 19.0 lists a directly granted role in information_schema.applicable_roles even when the membership has both INHERIT and SET disabled. In that configuration, the member cannot use the target role's privileges through automatic inheritance or SET ROLE.
The applicable_roles documentation (https://www.postgresql.org/docs/19/infoschema-applicable-roles.html) defines the view as roles whose privileges the current user can use. The role membership documentation (https://www.postgresql.org/docs/19/role-membership.html) explains that inherited privileges require INHERIT, and SET ROLE requires the SET option.
Reproduction
Run the following in psql -X as a superuser in a clean test cluster; the script creates cluster-wide role names and uses SET SESSION AUTHORIZATION. If these role names already exist, rename the ar_* roles consistently before running it. The transaction rolls back the created roles.
BEGIN;
CREATE ROLE ar_applicant NOLOGIN;
CREATE ROLE ar_unusable NOLOGIN;
CREATE ROLE ar_set_only NOLOGIN;
CREATE ROLE ar_inherit_only NOLOGIN;
GRANT ar_unusable TO ar_applicant WITH INHERIT FALSE, SET FALSE;
GRANT ar_set_only TO ar_applicant WITH INHERIT FALSE, SET TRUE;
GRANT ar_inherit_only TO ar_applicant WITH INHERIT TRUE, SET FALSE;
SET SESSION AUTHORIZATION ar_applicant;
SELECT expected.role_name,
pg_has_role(session_user, expected.role_name, 'USAGE') AS privileges_immediately_usable,
pg_has_role(session_user, expected.role_name, 'SET') AS set_role_allowed,
EXISTS (
SELECT 1
FROM information_schema.applicable_roles ar
WHERE ar.grantee = session_user
AND ar.role_name = expected.role_name
) AS reported_as_applicable
FROM (VALUES ('ar_unusable'::name),
('ar_set_only'::name),
('ar_inherit_only'::name)) AS expected(role_name)
ORDER BY expected.role_name;
SET ROLE ar_set_only;
SELECT current_user;
RESET ROLE;
RESET SESSION AUTHORIZATION;
ROLLBACK;
On PostgreSQL 19.0, the query returns:
role_name | privileges_immediately_usable | set_role_allowed | reported_as_applicable
-----------------+-------------------------------+------------------+------------------------
ar_inherit_only | t | f | t
ar_set_only | f | t | t
ar_unusable | f | f | t
SET ROLE ar_set_only succeeds. For ar_unusable, both capability checks are false, yet the view reports it as applicable. The INHERIT-only and SET-only controls are listed as expected.
Expected behavior
The ar_unusable row should not appear in information_schema.applicable_roles, because the current user has no way to use that role's privileges. The two control memberships should remain listed.
Source observation
The PostgreSQL 19.0 applicable_roles view definition (https://github.com/postgres/postgres/blob/5c839a2a08b9b87a349be97371fac6c5a2873b10/src/backend/catalog/information_schema.sql#L243-L257) selects member, roleid, and admin_option from pg_auth_members, then filters on pg_has_role(grantee, 'USAGE'). It does not consider the membership's inherit_option or set_option when producing the row.
This is a metadata error; the reproduction does not show SQL privileges being bypassed.
Related report
The 2023 discussion of multiple membership grants (/messages/by-id/f78ca3f1-1bd8-05a7-957a-54f0074120a7@postgrespro.ru) concerns duplicate or missing rows when a role has multiple grants from different grantors. This reproduction uses one direct grant and concerns a role that has neither the INHERIT nor SET option.
Tested environment
- PostgreSQL 19.0 server and psql client (REL_19_0, commit 5c839a2a08b9b87a349be97371fac6c5a2873b10); PostgreSQL 18.7 also reproduced the same output.
- Ubuntu 24.04, Linux kernel 7.0.0-38-generic, x86-64, GCC 13.3.0. Build options: --without-readline --without-zlib --without-icu --without-llvm.
- A fresh cluster was initialized with initdb --no-locale -E UTF8 --auth-local=trust --auth-host=reject and listened on a local socket only. Startup settings were listen_addresses='', port=55491, max_connections=20, and shared_buffers=32MB; the socket directory was local to the test environment. No other configuration was changed.