From: Tom Lane <tgl@sss.pgh.pa.us>
To: VO Ipfix <ipfix5101@gmail.com>
Cc: pgsql-general@postgresql.org
Subject: Re: Preventing in-session 'set role' commands
Date: Tue, 06 Aug 2019 09:47:54 -0400
Message-ID: <19556.1565099274@sss.pgh.pa.us> (raw)
In-Reply-To: <CAMNi=_QtdrrfB4i+SvjeZuAjcyQnkbK9U3gaiK379vNkMyD+wQ@mail.gmail.com>
References: <CAMNi=_QtdrrfB4i+SvjeZuAjcyQnkbK9U3gaiK379vNkMyD+wQ@mail.gmail.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, ipfix5101@gmail.com
Subject: Re: Preventing in-session 'set role' commands
In-Reply-To: <19556.1565099274@sss.pgh.pa.us>
References: <CAMNi=_QtdrrfB4i+SvjeZuAjcyQnkbK9U3gaiK379vNkMyD+wQ@mail.gmail.com> <19556.1565099274@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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