pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Thoughts on row-level security for webapps?
5+ messages / 4 participants
[nested] [flat]

* Thoughts on row-level security for webapps?
@ 2018-12-31 16:57  Siegfried Bilstein <sbilstein@gmail.com>
  0 siblings, 3 replies; 5+ messages in thread

From: Siegfried Bilstein @ 2018-12-31 16:57 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

Hi all,

I'm evaluating using a tool called Postgraphile that generates a GraphSQL
server from a postgres setup. The recommended way of handling security is
to implement RLS within postgres and simply have the webserver take a
cookie or similar and define which user is querying data.

I've normally built webapps like this: pull out user id from a session
cookie -> the API endpoint verifies the user and whether or not it has
access to the given data -> app code mutates the data.

With Postgraphile the request specifies the mutation and the server
processes the request and relies on Postgres to determine if the user has
correct access rights.

It seems like I would need to create a ROLE for every single member that
signs up for my website which I'm a little concerned about. Is this a
common usage pattern for SQL security? Any gotchas relying on RLS?

-- 
Siggy Bilstein
CTO of Ayuda Care <https://www.ayudacare.com;
Book some time <https://calendly.com/siggy-cto; with me!

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Thoughts on row-level security for webapps?
@ 2019-01-01 18:49  Adrian Klaver <adrian.klaver@aklaver.com>
  parent: Siegfried Bilstein <sbilstein@gmail.com>
  2 siblings, 0 replies; 5+ messages in thread

From: Adrian Klaver @ 2019-01-01 18:49 UTC (permalink / raw)
  To: Siegfried Bilstein <sbilstein@gmail.com>; pgsql-general@lists.postgresql.org

On 12/31/18 8:57 AM, Siegfried Bilstein wrote:
> Hi all,
> 
> I'm evaluating using a tool called Postgraphile that generates a 
> GraphSQL server from a postgres setup. The recommended way of handling 
> security is to implement RLS within postgres and simply have the 
> webserver take a cookie or similar and define which user is querying data.
> 
> I've normally built webapps like this: pull out user id from a session 
> cookie -> the API endpoint verifies the user and whether or not it has 
> access to the given data -> app code mutates the data.
> 
> With Postgraphile the request specifies the mutation and the server 
> processes the request and relies on Postgres to determine if the user 
> has correct access rights.

So there is still user information being passed in, correct?

> 
> It seems like I would need to create a ROLE for every single member that 
> signs up for my website which I'm a little concerned about. Is this a 
> common usage pattern for SQL security? Any gotchas relying on RLS?

The ROLE will be determined by the user name used to make the 
connection. Is it possible to change the connection login depending on 
the website user privileges?


> 
> -- 
> Siggy Bilstein
> CTO ofAyuda Care <https://www.ayudacare.com;
> Book some time <https://calendly.com/siggy-cto; with me!


-- 
Adrian Klaver
adrian.klaver@aklaver.com




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Thoughts on row-level security for webapps?
@ 2019-01-02 10:31  Achilleas Mantzios <achill@matrix.gatewaynet.com>
  parent: Siegfried Bilstein <sbilstein@gmail.com>
  2 siblings, 0 replies; 5+ messages in thread

From: Achilleas Mantzios @ 2019-01-02 10:31 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

On 31/12/18 6:57 μ.μ., Siegfried Bilstein wrote:
> Hi all,
>
> I'm evaluating using a tool called Postgraphile that generates a GraphSQL server from a postgres setup. The recommended way of handling security is to implement RLS within postgres and simply have 
> the webserver take a cookie or similar and define which user is querying data.
>
> I've normally built webapps like this: pull out user id from a session cookie -> the API endpoint verifies the user and whether or not it has access to the given data -> app code mutates the data.
>
> With Postgraphile the request specifies the mutation and the server processes the request and relies on Postgres to determine if the user has correct access rights.
>
> It seems like I would need to create a ROLE for every single member that signs up for my website which I'm a little concerned about.

Why?

> Is this a common usage pattern for SQL security? Any gotchas relying on RLS?
>
> -- 
> Siggy Bilstein
> CTO ofAyuda Care <https://www.ayudacare.com;
> Book some time <https://calendly.com/siggy-cto; with me!


-- 
Achilleas Mantzios
IT DEV Lead
IT DEPT
Dynacom Tankers Mgmt

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Thoughts on row-level security for webapps?
@ 2019-01-03 20:49  Stephen Frost <sfrost@snowman.net>
  parent: Siegfried Bilstein <sbilstein@gmail.com>
  2 siblings, 1 reply; 5+ messages in thread

From: Stephen Frost @ 2019-01-03 20:49 UTC (permalink / raw)
  To: Siegfried Bilstein <sbilstein@gmail.com>; +Cc: pgsql-general@lists.postgresql.org

Greetings,

* Siegfried Bilstein (sbilstein@gmail.com) wrote:
> I'm evaluating using a tool called Postgraphile that generates a GraphSQL
> server from a postgres setup. The recommended way of handling security is
> to implement RLS within postgres and simply have the webserver take a
> cookie or similar and define which user is querying data.
> 
> I've normally built webapps like this: pull out user id from a session
> cookie -> the API endpoint verifies the user and whether or not it has
> access to the given data -> app code mutates the data.
> 
> With Postgraphile the request specifies the mutation and the server
> processes the request and relies on Postgres to determine if the user has
> correct access rights.
> 
> It seems like I would need to create a ROLE for every single member that
> signs up for my website which I'm a little concerned about. Is this a
> common usage pattern for SQL security? Any gotchas relying on RLS?

You don't have to create a role for every member, though depending on
your expectation you might want to.  You could just set a custom GUC
which is used in the policy, but you then have to trust the web
application code to always do that correctly and to always properly
validate the client (without bugs, of course).

RLS has been around for a while now and it works really rather well in
most cases.  There are some corner cases where you're doing some kind of
filtering that might be able to use an index but the functions aren't
leakproof and therefore can't be used, causing a performance regression,
but that's not too hard to test for and only an issue if the policy
itself isn't very selective.

Thanks!

Stephen

Attachments:

  signature.asc (application/pgp-signature, 818B) download

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Thoughts on row-level security for webapps?
@ 2019-01-03 21:04  Siegfried Bilstein <sbilstein@gmail.com>
  parent: Stephen Frost <sfrost@snowman.net>
  0 siblings, 0 replies; 5+ messages in thread

From: Siegfried Bilstein @ 2019-01-03 21:04 UTC (permalink / raw)
  To: Stephen Frost <sfrost@snowman.net>; +Cc: pgsql-general@lists.postgresql.org

Thank you for the responses.

I did some research and now understand that in my query I'll need to do
something like 'SET LOCAL user_id=5; SET ROLE app_user' and define a policy
that references a 'user_id' variable. I think I have enough info now to get
started.

On Thu, Jan 3, 2019 at 12:49 PM Stephen Frost <sfrost@snowman.net> wrote:

> Greetings,
>
> * Siegfried Bilstein (sbilstein@gmail.com) wrote:
> > I'm evaluating using a tool called Postgraphile that generates a GraphSQL
> > server from a postgres setup. The recommended way of handling security is
> > to implement RLS within postgres and simply have the webserver take a
> > cookie or similar and define which user is querying data.
> >
> > I've normally built webapps like this: pull out user id from a session
> > cookie -> the API endpoint verifies the user and whether or not it has
> > access to the given data -> app code mutates the data.
> >
> > With Postgraphile the request specifies the mutation and the server
> > processes the request and relies on Postgres to determine if the user has
> > correct access rights.
> >
> > It seems like I would need to create a ROLE for every single member that
> > signs up for my website which I'm a little concerned about. Is this a
> > common usage pattern for SQL security? Any gotchas relying on RLS?
>
> You don't have to create a role for every member, though depending on
> your expectation you might want to.  You could just set a custom GUC
> which is used in the policy, but you then have to trust the web
> application code to always do that correctly and to always properly
> validate the client (without bugs, of course).
>
> RLS has been around for a while now and it works really rather well in
> most cases.  There are some corner cases where you're doing some kind of
> filtering that might be able to use an index but the functions aren't
> leakproof and therefore can't be used, causing a performance regression,
> but that's not too hard to test for and only an issue if the policy
> itself isn't very selective.
>
> Thanks!
>
> Stephen
>


-- 
Siggy Bilstein
CTO of Ayuda Care <https://www.ayudacare.com;
Book some time <https://calendly.com/siggy-cto; with me!

^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2019-01-03 21:04 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-12-31 16:57 Thoughts on row-level security for webapps? Siegfried Bilstein <sbilstein@gmail.com>
2019-01-01 18:49 ` Adrian Klaver <adrian.klaver@aklaver.com>
2019-01-02 10:31 ` Achilleas Mantzios <achill@matrix.gatewaynet.com>
2019-01-03 20:49 ` Stephen Frost <sfrost@snowman.net>
2019-01-03 21:04   ` Siegfried Bilstein <sbilstein@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox