Skip to content

[Bug]: a membership granted by another role is not revoked when missing from inRoles #11825

Open

Description

@armru

Is there an existing issue already for this bug?

  • I have searched for an existing issue, and could not find anything. I believe this is a new bug.

I have read the troubleshooting guide

  • I have read the troubleshooting guide and I think this is a new bug.

I am running a supported version of CloudNativePG

  • I have read the troubleshooting guide and I think this is a new bug.

Contact Details

No response

Version

trunk (main)

What version of Kubernetes are you using?

1.37

What is your Kubernetes environment?

Self-managed: kind (evaluation)

How did you install the operator?

YAML manifest

What happened?

From PostgreSQL 16 a membership can be granted once per grantor: a role
holding the ADMIN option on a role can grant it again, next to the grant
made by the operator, and pg_auth_members keeps one row per grantor. The
operator revokes a membership that is not in inRoles with
REVOKE <role> FROM <member>, which acts only on the grant of the bootstrap
superuser, so a membership granted by another role survives, and PostgreSQL
only logs a warning.

With the Cluster below, another role grants pg_monitor to app_role:

CREATE ROLE grantor;
GRANT pg_monitor TO grantor WITH ADMIN OPTION;
SET ROLE grantor;
GRANT pg_monitor TO app_role;
RESET ROLE;

On the next reconciliation the operator finds a membership app_role does
not list in inRoles and runs REVOKE "pg_monitor" FROM "app_role", which
PostgreSQL answers with a warning, and app_role stays a member of
pg_monitor. In the same way, when both the operator and another role
granted a membership, removing it from inRoles revokes only the grant of
the operator.

I expected the operator to revoke every grant of a membership the role does
not list.

The revocation goes through the same code for a DatabaseRole, which is
affected in the same way. Every release is affected on PostgreSQL 16 and
later. The same rows also make the managed roles status count a membership
once per grant, which is #11624.

Cluster resource

apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
  name: cluster-example
spec:
  instances: 1
  imageName: ghcr.io/cloudnative-pg/postgresql:18.6-system-trixie
  storage:
    size: 1Gi
  managed:
    roles:
      - name: app_role
        ensure: present
        login: true

Relevant log output

# Reproduced in the e2e suite against main, with the role "new_role".
# The instance logs the REVOKE of a membership granted by another role:
{"level":"info","ts":"2026-11-02T14:29:50.661627011Z","logger":"postgres","msg":"record","logging_pod":"cluster-example-with-roles-1","record":{"log_time":"2026-11-02 14:29:50.661 UTC","user_name":"postgres","database_name":"postgres","process_id":"740","connection_from":"[local]","session_id":"6ae89e5e.2e4","session_line_num":"1","command_tag":"REVOKE ROLE","session_start_time":"2026-11-02 14:29:50 UTC","virtual_transaction_id":"5/15","transaction_id":"0","error_severity":"WARNING","sql_state_code":"01000","message":"role \"new_role\" has not been granted membership in role \"pg_monitor\" by role \"postgres\"","application_name":"cnpg-instance-manager","backend_type":"client backend","query_id":"0"}}

# and 30 seconds later the role is still a member of pg_monitor, while its
# inRoles lists only dante:
Expected
    <[]string | len:2, cap:2>: ["dante", "pg_monitor"]
to be equivalent to
    <[]string | len:1, cap:1>: ["dante"]

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. added
    bug 🐛
    triage
    on Nov 2, 2026
  2. added a commit that references this issue on Nov 10, 2026
    20cc41e
  3. gbartolini commented on Nov 10, 2026

    @gbartolini
    Contributor

    I think we need to reflect more on the use case. Let's queue this for 1.32.

  4. added this to the 1.32.0 milestone on Nov 10, 2026
  5. added a commit that references this issue on Nov 10, 2026
    9dbb695
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

    bug 🐛triage

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions