Cache invalidation after authentication (on-the-fly role creation) - Mailing list pgsql-hackers

From Thomas Munro
Subject Cache invalidation after authentication (on-the-fly role creation)
Date
Msg-id CAEepm=3_h0_cgmz5PMyab4xk_OFrg6G5VCN=nF4chFXM9iFOqA@mail.gmail.com
Whole thread Raw
Responses Re: Cache invalidation after authentication (on-the-fly rolecreation)  (Alvaro Herrera <alvherre@2ndquadrant.com>)
Re: Cache invalidation after authentication (on-the-fly role creation)  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Cache invalidation after authentication (on-the-fly rolecreation)  (Stephen Frost <sfrost@snowman.net>)
List pgsql-hackers
Hello hackers,

I'd like to do this to postinit.c:

                PerformAuthentication(MyProcPort);
+               AcceptInvalidationMessages();
                InitializeSessionUserId(username, useroid);

Any objections?  Motivation:

Many people use custom scripts, ldap2pg or other similar tools to
synchronise or manage their PostgreSQL roles from an LDAP server.
Doing that in a cron job works pretty well, but you have to wait for
the next cron job run after you make a change.  Based on several
requests from the field (basically, ex-SQL Server shops, where they
love Active Directory group-based authorisation), I started wondering
if it would be crazy to do incremental per-user synchronisation at at
the moment of authentication.  New hooks don't seem to be necessary,
since PAM is designed for things like that -- for example creating
your Unix home directory on demand.  But I ran into one small problem:
PostgreSQL doesn't see catalog changes that happened during
authentication because of caching.

For example, you might put this in pg_hba.conf:

host all all all pam pamservice=postgresql

... and then put this in /etc/pam.d/postgresql:

auth required pam_ldap.so config=/path/to/ldap.conf
auth required pam_exec.so /path/to/ldap2pg --sync-pam-user
account required pam_permit.so

That's a fictional ldap2pg option that would synchronise only the user
passed to it in $PAM_USER.  A high performance version could do
authentication and role synchronisation at the same time (perhaps
using the LDAP server's change notification/counter to skip having to
connect back to PostgreSQL to inspect catalogs in the common case that
nothing changed).

If you try things like that today, it works but any roles created
during authentication are (sometimes?) not visible to PostgreSQL until
your *next* attempt to log in.

-- 
Thomas Munro
http://www.enterprisedb.com


pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: AtEOXact_ApplyLauncher() and subtransactions
Next
From: Michael Paquier
Date:
Subject: Re: Non-reserved replication slots and slot advancing