Skip to content

[Bug]: DatabaseRole grants a new membership before applying the inherit attribute #11824

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?

When a single change to a DatabaseRole turns off its inherit attribute
and adds a role to inRoles, the operator grants the new membership before
running ALTER ROLE. From PostgreSQL 16, a membership granted without an
INHERIT option takes it from the inherit attribute the role has at that
moment, so the membership is granted with the old value.

Applying the DatabaseRole below, and then changing it to inherit: false
and inRoles: [pg_monitor] in one update, leaves app_role with
rolinherit set to false, as requested, but with a pg_monitor membership
whose inherit_option is true: the role inherits the privileges of
pg_monitor although it is NOINHERIT.

I expected the membership to take the inherit attribute of the updated
role, as it does when the two changes are applied one after the other.

Every release with DatabaseRole, introduced in 1.30.0 (#6155), is
affected on PostgreSQL 16 and later.

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
---
apiVersion: postgresql.cnpg.io/v1
kind: DatabaseRole
metadata:
  name: app-role
spec:
  cluster:
    name: cluster-example
  name: app_role
  login: true
  inherit: true

Relevant log output

# Reproduced in the e2e suite against main (role "update-attrs-6785"):
# after one patch setting `inherit: false` and `inRoles: [pg_monitor]`,
# once the DatabaseRole reports `applied: true`
expected query "SELECT am.inherit_option FROM pg_catalog.pg_auth_members AS am JOIN pg_catalog.pg_roles AS r ON r.oid = am.member WHERE am.roleid = 'pg_monitor'::regrole AND r.rolname = 'update-attrs-6785'" to return "f" (in database "postgres")
Expected
    <string>: t
to be equivalent to
    <string>: f

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 2, 2026
    090461d
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

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions