You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Managed role stays pending-reconciliation when a membership has several grantor rows #11624
A managed role that holds a membership through two pg_auth_members rows (two different grantors) never leaves pending-reconciliation, although its inRoles match what is declared. The operator schedules UPDATE_MEMBERSHIPS on every reconcile; the computed diff is empty, so nothing is executed and no error is logged.
Cause
isInSameRolesAs compares the lengths of the two lists before comparing their contents (internal/management/controller/roles/contract.go). The list read from the database is built with:
SELECTpg_catalog.array_agg(pg_catalog.pg_get_userbyid(roleid)) AS inroles, member
FROMpg_catalog.pg_auth_membersGROUP BY member
(internal/management/controller/roles/postgres.go, in the role-list query and again in GetParentRoles.) Since PostgreSQL 16, pg_auth_members can hold several rows for the same (roleid, member) pair that differ in grantor, so a role appears once per grantor row.
Reproduction
Declare a managed role with createrole: true and inRoles: [grp].
Connected as that role: CREATE ROLE grp NOLOGIN; (PostgreSQL 16+ records an implicit membership of the creator in grp, granted by the bootstrap superuser), then GRANT grp TO CURRENT_USER; (a second row, with the role itself as grantor).
SELECT roleid::regrole, member::regrole, grantor::regrole FROM pg_auth_members WHERE roleid = 'grp'::regrole; returns two rows for the same pair.
Observed
status.managedRolesStatus lists the role under pending-reconciliation indefinitely.
The read list has 2 entries (grp, grp) against 1 declared, so isInSameRolesAs is false on every reconcile.
Expected
The role is reported as reconciled. Duplicate rows for the same granted role should not count twice.
Suggested fix
Collapse duplicates when reading, e.g. array_agg(DISTINCT pg_catalog.pg_get_userbyid(roleid)), or deduplicate the slice in isInSameRolesAs.
Environment
CloudNativePG 1.30.0 (the code above is unchanged on main), PostgreSQL 18.
Activity
MatheuslFavaretto commentedon Oct 17, 2026
Hi! I'd like to work on this, if that's okay.
ixcans commentedon Oct 17, 2026
Sounds good, go ahead!
fix(roles): ensure distinct user roles in aggregate queries