Re: Not clear how to switch role without permitting switch back

From: "Alexander M(dot) Sauer-Budge" <ambudge(at)alum(dot)mit(dot)edu>
To: Guyren Howe <guyren(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Not clear how to switch role without permitting switch back
Date: 2017-01-10 11:40:52
Message-ID: 4434F95E-99D4-4434-A50A-C13A47498AA2@alum.mit.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


> On Jan 10, 2017, at 2:05 AM, Guyren Howe <guyren(at)gmail(dot)com <mailto:guyren(at)gmail(dot)com>> wrote:
>
> For my Love Your Database Project:
>
> https://medium.com/@gisborne/love-your-database-lydb-23c69f480a1d#.8g1ezwx6r <https://medium.com/@gisborne/love-your-database-lydb-23c69f480a1d#.8g1ezwx6r>
>
> I’m trying to see how a typical web developer might use Postgres’ roles and row-level security to implement their authorization.
>
> What I’m struggling with is that connection pooling seems to make straightforward use of the roles to enforce access impossible.
>
> If I’m using a connection pool, then I’m not re-connecting to Postgres with the user for the current transaction. But then my only option is to use SET ROLE. But that is not much security at all, because the current user can just do SET ROLE back to the (presumably privileged) default, or to any other user’s role.
>
> What am I missing here?

Tomas at 2nd Quadrant wrote a nice article about doing that:

http://blog.2ndquadrant.com/application-users-vs-row-level-security/ <http://blog.2ndquadrant.com/application-users-vs-row-level-security/>

You can also look at how projects like PostgREST (http://postgrest.com/ <http://postgrest.com/>) and PostGaphQL (https://github.com/calebmer/postgraphql <https://github.com/calebmer/postgraphql>) tackle the problem (although I don’t recall at the moment if they are as careful about avoiding the possibility of an unprotected SET ROLE as Tomas is in the above article).

Best,
Alex

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom DalPozzo 2017-01-10 13:35:16 Re: requested timeline doesn't contain minimum recovery point
Previous Message Alexander M. Sauer-Budge 2017-01-10 11:09:16 Re: Not clear how to switch role without permitting switch back