Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lbQD6-00029y-3K for pgsql-general@arkaria.postgresql.org; Tue, 27 Apr 2021 16:05:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lbQD4-0005Xi-SV for pgsql-general@arkaria.postgresql.org; Tue, 27 Apr 2021 16:05:14 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lbQD4-0005Xb-LL for pgsql-general@lists.postgresql.org; Tue, 27 Apr 2021 16:05:14 +0000 Received: from tamriel.snowman.net ([2001:470:e38f::11]) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lbQCy-0005EG-Ay for pgsql-general@lists.postgresql.org; Tue, 27 Apr 2021 16:05:13 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id 949545F799; Tue, 27 Apr 2021 12:05:07 -0400 (EDT) Date: Tue, 27 Apr 2021 12:05:07 -0400 From: Stephen Frost To: Sanjay Minni Cc: pgsql-general@lists.postgresql.org Subject: Re: Approach to creating users in Database Message-ID: <20210427160507.GH20766@tamriel.snowman.net> References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="XHetxmNm4Wo4a9Eg" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --XHetxmNm4Wo4a9Eg Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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. >=20 > 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. >=20 > 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 --XHetxmNm4Wo4a9Eg Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJgiDYzAAoJEO1sijiDR2RVP1MP/07p/r68ufxzZua5Q+ktvbWy nIEGkJ8Z/zYOwpiwInCkzo3dWPJ9M/k7L4jTvFLItZdQe1nlRKduILqKpQMdlaKh V5yjzOjiq0SJKq6YXCrtenku/MJ6m8IyujkbGp/8tmOkPcDIJc92SiS9qY/V9/gR l/vxEA+TXM6A6+JseOt0fJ1x95vQVcqLSSu0WKYtRxk/fR6Uah905tn4Lxaq2tNU FNQOZxHzFPWvlskOO21F70Tw9yWjxbC/C/KuSiyRcncT8BuS7PcVaqFkrmWv9p+J ++884fnisR/wcWrJR/r5YjpvPXwptlDUJ5A0ReQJ5IJRlzuHHSj/7Y6BgsY1Klwb EAhaWU02aqVVpR1P+Yi1RITt61iaYNTf9Ey/gO9JEHXIavz/zzv2QeVSgKqYpb6A YPOtb7Jkmpm1u74anohh0d9D1ko1fzyUazLqUWcvRMY3HWa9x8insZ8nN1cBQSbd ubTNYcqExOuhG99HBCAzkex9yXs8A27EB1J5b6CyCif+dkfgVcrnm4m821PIdlH0 om2wjjpwV/oozM3evMvT/MDn//C8D1E+0v8xyqGfA1Ctf9cV39aBu7hkrPdBoCxq c+d7ek4tWWWWY+gEpTJsUyl04/rp0yFBBzkfoAa8ntFsnqIWXTb7EuxZKMiAmUfK JZjK7UAru6U465s3Ajyt =DZkG -----END PGP SIGNATURE----- --XHetxmNm4Wo4a9Eg--