Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1jC2rB-000446-7P for pgsql-general@arkaria.postgresql.org; Wed, 11 Mar 2020 15:01:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jC2r9-0000KA-8e for pgsql-general@arkaria.postgresql.org; Wed, 11 Mar 2020 15:01:11 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1jC2r8-0000K3-QX for pgsql-general@lists.postgresql.org; Wed, 11 Mar 2020 15:01:10 +0000 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jC2qy-0003Yb-9Q for pgsql-general@lists.postgresql.org; Wed, 11 Mar 2020 15:01:09 +0000 Received: by mail-wr1-x42f.google.com with SMTP id l18so3019112wru.11 for ; Wed, 11 Mar 2020 08:01:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=n26.com; s=google; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=Z0mKzAYfXU6gRNs/cP8dcvlWiOpUW782dCBYLJ1n5mU=; b=YLIVNlo/9Wez+Ry6DbNPbzdEkC4z3l6hKULznec4GhLbVM6iUe8b7+aouDuawVHi0s x2xSJqXif2I01EHR0lodXGnkkbkhym2cw8jhqvaHTmD1Sv5wmhsgnvlGJkdOcaGYVmfx Qf2DJqx+OQBi0sAvizqtytkFJbJXOBcE4FyiDIENeReAv4kcNuH4Lbh/Az/IETfndXco xa4Du8U0QxYbde14LqdEe25Xc73ebukk5KBkMznHJuqjxWpgR3eS2fB3FfeVGPgwDDgM FiyzX572ARIXVGuV/UA8TCdew2sNrIRt/Km3pZyy8XUkIT4iHeN2ftBzp3R9FWrvM1B/ sQIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=Z0mKzAYfXU6gRNs/cP8dcvlWiOpUW782dCBYLJ1n5mU=; b=Nnb9FQ7yVyDHDwP81fGfM+Y7kwHYJ3oZacE/tDreeMM1g3Z3BSLg4XOOJw6URg7KXE xIlg4SqNzHSBXh719+iXhp4OsGrrD1ZQpWw3JRuUYT8RPew98ZRm0aAnsKh4g8nBBygH s5GqKRJ60v+ZExnPBs382IBhATi27gOwpXLYIoGTq4mpRz/vlfTj0WXoOQcMl7wIq8VZ HmfKYCDWtsHoUkq+6Kem88dRtpWPkf+/8QSdhLm36bvygLOUsKtA8T2K0PW67WCNLzLZ M2ZGHJjm9dqvAqlfyUU1ckvfgpN6RrE491IGsrxD6ns4QivVTCoKgPDYjlkE+W5uVnZw M+2A== X-Gm-Message-State: ANhLgQ10XnVEMuCvQSkHUmOyP+h3OEPh9TENwg57jFnT2GXRjU2cg+W6 um1h0VhawzTG/GBuxVDOLpmzJA== X-Google-Smtp-Source: ADFU+vuNGO9OWT/L+/VPn97ySJ8doqPzvITvJXY43ZeQJ67r1HnpZcHnTdTNtBr2wHx71ENt2QlpbQ== X-Received: by 2002:a5d:4088:: with SMTP id o8mr5037641wrp.144.1583938858831; Wed, 11 Mar 2020 08:00:58 -0700 (PDT) Received: from [10.4.23.40] ([62.96.137.138]) by smtp.gmail.com with ESMTPSA id y200sm6441264wmc.20.2020.03.11.08.00.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Mar 2020 08:00:57 -0700 (PDT) From: Andrei Zhidenkov Message-Id: Content-Type: multipart/alternative; boundary="Apple-Mail=_D70ECEC8-139C-4148-B58C-72C8223853FD" Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3601.0.10\)) Subject: Re: Web users as database users? Date: Wed, 11 Mar 2020 16:00:57 +0100 In-Reply-To: Cc: Tom Lane , "pgsql-general@lists.postgresql.org" To: Michael Lewis , tgl@sss.pgh.pa.us References: <28CB89D3-194A-420F-868A-0AFC169EF7E5@gmail.com> <16391.1568989132@sss.pgh.pa.us> X-Mailer: Apple Mail (2.3601.0.10) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --Apple-Mail=_D70ECEC8-139C-4148-B58C-72C8223853FD Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii I used to use a different approach: 1. Create auth() pl/python procedure as follows: create or replace function auth(auser_id integer) returns void as $$ GD['user_id'] =3D auser_id $$ language plpythonu; This procedure is supposed to be called after a sucesseful authorisation = (in a database or on application side). 2. Create get_current_user() procedure: create or replace function get_current_user() returns integer as $$ return GD.get('user_id') $$ language plpythonu stable security definer; Now you can get current user id from every SQL query or stored = procedure. It works fast because Python shared array GD is always = present in memory. > On 11. Mar 2020, at 15:46, Michael Lewis wrote: >=20 > On Fri, Sep 20, 2019 at 8:19 AM Tom Lane > wrote: > There is a restriction on how many distinct GRANTs you can > issue against any one object --- performance will get bad if the ACL > list gets too large. >=20 >=20 > Any ballpark numbers here? Are we talking 50 or 8000? --Apple-Mail=_D70ECEC8-139C-4148-B58C-72C8223853FD Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii I = used to use a different approach:

1. Create auth() pl/python procedure as follows:

create = or replace
function auth(auser_id integer) returns = void as $$
    GD['user_id'] =3D = auser_id
$$ language plpythonu;

This procedure is = supposed to be called after a sucesseful authorisation (in a database or = on application side).

2. Create get_current_user() procedure:

create = or replace
function get_current_user() returns = integer as $$
    return = GD.get('user_id')
$$ language plpythonu stable = security definer;

Now you can get current user id from every SQL query or = stored procedure. It works fast because Python shared array GD is always = present in memory.

On 11. Mar 2020, at 15:46, Michael Lewis = <mlewis@entrata.com> wrote:

On Fri, Sep 20, 2019 at 8:19 AM = Tom Lane <tgl@sss.pgh.pa.us> wrote:
There is a restriction on how many = distinct GRANTs you can
issue against any one object --- performance will get bad if the ACL
list gets too large.


Any = ballpark numbers here? Are we talking 50 or 8000?

= --Apple-Mail=_D70ECEC8-139C-4148-B58C-72C8223853FD--