pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Preventing in-session 'set role' commands
4+ messages / 4 participants
[nested] [flat]

* Preventing in-session 'set role' commands
@ 2019-08-06 08:25 VO Ipfix <ipfix5101@gmail.com>
  2019-08-06 10:50 ` Re: Preventing in-session 'set role' commands Luca Ferrari <fluca1978@gmail.com>
  2019-08-06 11:04 ` RE: Preventing in-session 'set role' commands Steven Winfield <Steven.Winfield@cantabcapital.com>
  2019-08-06 13:47 ` Re: Preventing in-session 'set role' commands Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 3 replies; 4+ messages in thread

From: VO Ipfix @ 2019-08-06 08:25 UTC (permalink / raw)
  To: pgsql-general

Hello everyone! I am working on a multi-tenant (sigh) DB design using
schemas. I anticipate a bunch of junior developers coming in before we
fully mature our testing process, so SQLi is a concern. Basically, I want
to have a role for each tenant, and have a user/role that will est. a DB
session from a connection pool then perform a set role followed by a set
schema to the schema that the tenant role has grants to. So, my main
requirement is this: after these two (or more) commands are invoked, the
current role should not be able to do a set role to any other role (tenant)
other than itself. This is to prevent an attacker-controlled SQL query that
has set role as part of its payload.Is this something that can be
accomplished with PostgreSQL? Any suggestions thoughts are welcome, however
tangential

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

* Re: Preventing in-session 'set role' commands
  2019-08-06 08:25 Preventing in-session 'set role' commands VO Ipfix <ipfix5101@gmail.com>
@ 2019-08-06 10:50 ` Luca Ferrari <fluca1978@gmail.com>
  2 siblings, 0 replies; 4+ messages in thread

From: Luca Ferrari @ 2019-08-06 10:50 UTC (permalink / raw)
  To: VO Ipfix <ipfix5101@gmail.com>; +Cc: pgsql-general

On Tue, Aug 6, 2019 at 10:26 AM VO Ipfix <ipfix5101@gmail.com> wrote:
>
> Is this something that can be accomplished with PostgreSQL? Any suggestions thoughts are welcome, however tangential

Perhaps SET SESSION AUTHORIZATION?
<https://www.postgresql.org/docs/11/sql-set-session-authorization.html;

Luca





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

* RE: Preventing in-session 'set role' commands
  2019-08-06 08:25 Preventing in-session 'set role' commands VO Ipfix <ipfix5101@gmail.com>
@ 2019-08-06 11:04 ` Steven Winfield <Steven.Winfield@cantabcapital.com>
  2 siblings, 0 replies; 4+ messages in thread

From: Steven Winfield @ 2019-08-06 11:04 UTC (permalink / raw)
  To: VO Ipfix <ipfix5101@gmail.com>; pgsql-general

Maybe check out the set_user extension:
https://github.com/pgaudit/set_user

Steve.


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

* Re: Preventing in-session 'set role' commands
  2019-08-06 08:25 Preventing in-session 'set role' commands VO Ipfix <ipfix5101@gmail.com>
@ 2019-08-06 13:47 ` Tom Lane <tgl@sss.pgh.pa.us>
  2 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2019-08-06 13:47 UTC (permalink / raw)
  To: VO Ipfix <ipfix5101@gmail.com>; +Cc: pgsql-general

VO Ipfix <ipfix5101@gmail.com> writes:
> Hello everyone! I am working on a multi-tenant (sigh) DB design using
> schemas. I anticipate a bunch of junior developers coming in before we
> fully mature our testing process, so SQLi is a concern. Basically, I want
> to have a role for each tenant, and have a user/role that will est. a DB
> session from a connection pool then perform a set role followed by a set
> schema to the schema that the tenant role has grants to. So, my main
> requirement is this: after these two (or more) commands are invoked, the
> current role should not be able to do a set role to any other role (tenant)
> other than itself. This is to prevent an attacker-controlled SQL query that
> has set role as part of its payload.Is this something that can be
> accomplished with PostgreSQL?

There's nothing built-in for that, but probably an event trigger could
be written to implement such a restriction.

As noted by another respondent, SET SESSION AUTHORIZATION might be a
better fit to your goals than SET ROLE.  (I don't recall the exact
distinction between them -- ENOCAFFEINE -- but I think the former
gives up more privilege than the latter.)  You'd still need a trigger.

			regards, tom lane





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


end of thread, other threads:[~2019-08-06 13:47 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-08-06 08:25 Preventing in-session 'set role' commands VO Ipfix <ipfix5101@gmail.com>
2019-08-06 10:50 ` Luca Ferrari <fluca1978@gmail.com>
2019-08-06 11:04 ` Steven Winfield <Steven.Winfield@cantabcapital.com>
2019-08-06 13:47 ` Tom Lane <tgl@sss.pgh.pa.us>

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