pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephen Frost <sfrost@snowman.net>
To: Sanjay Minni <sanjay.minni@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Approach to creating users in Database
Date: Tue, 27 Apr 2021 12:05:07 -0400
Message-ID: <20210427160507.GH20766@tamriel.snowman.net> (raw)
In-Reply-To: <CAMpxBon7xmsd88rY0oQxheoD2zCOg0h9FmoEO6AWSL61UuQ-4Q@mail.gmail.com>
References: <CAMpxBon7xmsd88rY0oQxheoD2zCOg0h9FmoEO6AWSL61UuQ-4Q@mail.gmail.com>

Greetings,

* Sanjay Minni (sanjay.minni@gmail.com) wrote:
> what is the usual approach in creating users / role in a postgresql
> database serving as the data repository to a hosted multi-tenanted
> application with a large number of users.
> 
> the 2 approaches I can think of is
> A. The user stays and is controlled only in the application level, the
> application in turn connects with the postgresql database as a single user
> name. Any userid to be stored as part of the data is injected by the
> application
> B. Each user is also created in the postgresql database with grant or
> required rights to the tables.
> 
> what is the usual practice ?
> I am unable to see any benefit in (B) above - i.e. recreating each user in
> the postgres database

Both approaches are used pretty commonly.  The advantages of B include:

- The permissions can be managed using GRANT/REVOKE at the database
  level and you remove the risk, for the most part, of things like SQL
  injection attacks because the user you're connected to the database as
  has only the rights that they should have, unlike in approach A where
  the user connected to the database has rights to basically everything.

- Auditing is able to be done of who did what using the database rather
  than having to trust to application logs and auditing.

There's other up-sides and down-sides, of course.

Thanks,

Stephen

Attachments:

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

view thread (2+ messages)

Message-ID: <20210427160507.GH20766@tamriel.snowman.net>
Permalink:  ../20210427160507.GH20766@tamriel.snowman.net/
Also on:    postgresql.org/message-id/20210427160507.GH20766@tamriel.snowman.net

 · 

reply

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: sfrost@snowman.net, sanjay.minni@gmail.com
  Subject: Re: Approach to creating users in Database
  In-Reply-To: <20210427160507.GH20766@tamriel.snowman.net>
  References: <CAMpxBon7xmsd88rY0oQxheoD2zCOg0h9FmoEO6AWSL61UuQ-4Q@mail.gmail.com> <20210427160507.GH20766@tamriel.snowman.net>

* 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