Repository navigation
Description
Is there an existing issue already for your request/idea?
- I have searched for an existing issue, and could not find anything. I believe this is a new documentation enhancement to be evaluated.
What problem in the existing documentation this issue aims to solve?
Setting login: false on a DatabaseRole applies NOLOGIN, so new connections are refused. Sessions that were already open keep working, and the documentation does not mention this.
We hit it while writing an internal runbook for revoking access: we assumed disabling a user cuts off access, and it does not. An application that is already connected keeps reading and writing until it reconnects on its own.
Reproduced on 1.30.0 with PostgreSQL 18:
- Create a
DatabaseRolewithlogin: true, connect as that role and keep the session open, for exampleSELECT pg_sleep(180);. - Set
login: falseand wait forstatus.applied: true(about 10 seconds for us). - The open session still runs queries and returns data. New logins are refused with
FATAL: role "myapp" is not permitted to log in.
For comparison, deleting the DatabaseRole with databaseRoleReclaimPolicy: delete does affect open sessions: the backend stays alive, but the next query fails with ERROR: invalid role OID: 16536. The two operations behave differently, and neither behaviour is documented.
Working around this from the outside is awkward. The database owner cannot call pg_terminate_backend on another role's backend without pg_signal_backend, and in a managed setup tenants have no superuser and no shell access to the pods.
Describe what additions need to be done to the documentation
A short note in declarative role management stating that disabling a role blocks new connections only, and that existing sessions survive until they reconnect. A sentence on what happens to open sessions when a role is dropped would help too.
It would also be useful to know your view on whether terminating sessions belongs in the operator at all. An opt-in field on DatabaseRole would make login: false usable for incident response. If you consider it out of scope, that is a fine answer, and worth stating in the docs so people do not build runbooks on the wrong assumption.
Activity
ehtishammubarik commentedon Aug 30, 2026
Confirmed on the code path, and I ran your two comparisons against a stock PostgreSQL 18.6 so the docs note can say exactly what happens. Line numbers below are from
main(8179beb).roles/postgres.go,api/v1/databaserole_types.goand the docs page are byte-identical onrelease-1.30(2c518dc), which is what you are running; where a file has shifted between the two I give both.login: falsecannot affect open sessions, by constructionDatabaseRolereconciliation ends inroles.Update, which builds oneALTER ROLEstatement fromappendRoleOptions— the only placeloginis translated, and it writesNOLOGIN(internal/management/controller/roles/postgres.go:366). Nothing in the role path terminates backends: the only twopg_terminate_backendcall sites in the tree aredropStaleReplicationConnections(internal/management/controller/instance_controller.go:1554,:1551on 1.30 — replication connections only) andInstance.DropConnections(pkg/management/postgres/instance.go:1560), whose single caller is the promotion path atinstance_controller.go:1270. So this is plain PostgreSQLNOLOGINsemantics, and a docs note is the right fix.Replaying the exact statement the operator issues:
A new connection is refused with
FATAL: role "myapp" is not permitted to log in, while the session opened beforehand keeps answering (still alive | myapp | 415). Same as your report.The workaround does not need superuser —
inRolesalready covers itDatabaseRoleSpecembedsRoleConfigurationinline (api/v1/databaserole_types.go:69), soinRoles(api/v1/cluster_types.go:2757,:2698on 1.30) is aDatabaseRolefield, and it is in the generated CRD atconfig/crd/bases/postgresql.cnpg.io_databaseroles.yaml:138. Membership changes are applied to existing roles too, viaroles.UpdateMembership, which emitsGRANT "<role>" TO "<name>"(postgres.go:266) on the reconciler's superuser connection (internal/management/controller/databaserole_controller.go:522) — so the tenant never needs one of their own:Measured with a plain non-superuser role, terminating the still-open
myappbackend:ERROR: permission denied to terminate process— with PostgreSQL's ownDETAILpointing atpg_signal_backendGRANT "pg_signal_backend" TO "runbook":pg_terminate_backendreturnst, andpg_stat_activitydrops to 0myappclient backendsThat makes
login: falseplus onepg_terminate_backenda complete revoke, with no superuser and no pod shell. The page already usespg_monitorin theDatabaseRoleexample (docs/src/declarative_role_management.md:113) andpg_signal_backendin the inline-roles example (:359), but never connects either to cutting off access.The drop comparison is weaker than it looks
Dropping does not close the session either. After
DROP ROLE, the backend stays connected and only statements that resolve the role OID fail:The session survives the error and keeps running. What actually stopped data access in my run was the
REVOKEthat had to happen before the drop, not the drop itself —roles.Deleteissues a bareDROP ROLE IF EXISTS(postgres.go:191), so a role holding a live table grant fails to drop at all:And a
REVOKEon its own, with the role kept and stillLOGIN, hits the open session immediately: the nextSELECTreturnspermission denied for table revdata.So the rule worth writing down is that privilege changes take effect on live sessions at the next statement, while
login: falseand dropping the role do not. AdatabaseRoleReclaimPolicy: deleteon a role that actually holds privileges is also worth a caveat, since it will not drop cleanly.On whether termination belongs in the operator: with
inRoles: [pg_signal_backend]there is already a supported path that needs no new API, so it may be enough to document that instead — your call. Happy to send a docs PR for the note if you want it.melancholictheory commentedon Aug 30, 2026
Thanks for digging into this. The
NOLOGINtrace matches what we see, andinRoles: [pg_signal_backend]is a good find. I hadn't considered that theGRANTgoes over the reconciler's own superuser connection, so the tenant never needs one.It doesn't reach our tenants as things stand. Our platform API wraps
DatabaseRoleand exposes anaccess: ro|rwenum that maps topg_read_all_data/pg_write_all_data, soinRolesisn't user-settable. That's our limitation, not the operator's.One correction on the drop comparison, though. Whether the drop cuts off data access depends on where the privileges come from.
Our roles hold no direct grants. All access is membership in
pg_read_all_data/pg_write_all_data, and in that model the drop does end data access, at the next statement. Same setup as yours, with a session opened before the change and a table owned by another role:SELECT count(*) FROM pg_classdoesn't show this, becausepg_classis readable byPUBLICand keeps answering for a dropped role too. A table the role could only reach through membership stops being readable as soon as the membership goes with the role.The
DROP ROLEcaveat splits along the same line. A role that owns nothing and holds no direct grants drops cleanly, sodatabaseRoleReclaimPolicy: deleteis fine in the membership model: the bareDROP ROLE IF EXISTSwent through in our run with noREVOKEbefore it. The dependency error you hit needs a direct grant to exist in the first place.So if you write the note, the line worth drawing is direct grants versus membership:
login: falsenever touches an open session, in either model.REVOKEthat lands on the live session.Yes to the docs PR, please. Happy to review it.
github-actions commentedon Nov 22, 2026
This issue is stale because it has been open for 60 days with no activity.
seshikanthguduri commentedon Nov 24, 2026
Hi, I'd like to work on this documentation update.
From the issue and the verification above, the note for the declarative role management page would state that setting
login: falseappliesNOLOGIN: new connections are refused, but sessions that are already open keep working until they disconnect, so disabling a role does not by itself revoke access for connected clients.If that matches what the maintainers have in mind, I'm happy to prepare a PR with the change. Please let me know if you'd prefer the note placed or worded differently.
Assisted with Muse