Skip to content

Managed role stays pending-reconciliation when a membership has several grantor rows #11624

Open

Description

@ixcans

Summary

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:

SELECT pg_catalog.array_agg(pg_catalog.pg_get_userbyid(roleid)) AS inroles, member
FROM pg_catalog.pg_auth_members GROUP 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

  1. Declare a managed role with createrole: true and inRoles: [grp].
  2. 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).
  3. 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

  1. MatheuslFavaretto commented on Oct 17, 2026

    @MatheuslFavaretto

    Hi! I'd like to work on this, if that's okay.

  2. ixcans commented on Oct 17, 2026

    @ixcans
    Author
    1. Hi! I'd like to work on this, if that's okay.

    Sounds good, go ahead!

  3. added a commit that references this issue on Oct 17, 2026
    8079354
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions