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 1oeQqX-00034d-Es for pgsql-general@arkaria.postgresql.org; Sat, 01 Oct 2022 00:59:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oeQqU-0001Fi-FV for pgsql-general@arkaria.postgresql.org; Sat, 01 Oct 2022 00:59:10 +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 1oeQqT-0001FZ-Uk for pgsql-general@lists.postgresql.org; Sat, 01 Oct 2022 00:59:10 +0000 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oeQqP-00024Q-Q6 for pgsql-general@lists.postgresql.org; Sat, 01 Oct 2022 00:59:08 +0000 Received: by mail-pf1-x431.google.com with SMTP id v186so5602814pfv.11 for ; Fri, 30 Sep 2022 17:59:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yugabyte.com; s=google; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date; bh=aBFWjhkls1iZyP1F3wDUhsc5ieRFPfe80AI0DZ4+ISQ=; b=kXRt6ATtErheJGWo3Cyv2KSozcb4hCCS2YNFgUYhdXcWNJ1RlRAk84lxfmyEaxgdeM ETTJRcKoM5d/YAvR/3znFRzWkTtlnHkFeUGtWvPzc+CadufyMQaFeBxl+uHn43Nr8Z3i wkfMt9t5MbPsr6zsownZo2K2Ug72nAj/GFj8Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date; bh=aBFWjhkls1iZyP1F3wDUhsc5ieRFPfe80AI0DZ4+ISQ=; b=0919MNyQtkMOBsrQzhuEHJRsLBqH46Q6J0FpjoV4epvpPoGurGqrSOOmlxE/x8ZorI Iuem0vH9i2drkaX89UAm/E0FA4WF8UtrAHP9xNz3ESLnsX/XjDMfFeKXgWDu7vLKFh0K 6EpJWrm7oN+VaiQwpfj6GcI7JxY5ELWffQWX/UBGfe2ORbEoKSx1/ZHuec40O8xJv+LM 8iESoaK0e3XYRB23W9L8rkTwEGCEp1wW+SnmP5ZElZx1j6DwYNBsbbcPKjEKKZ7EjRLI Oo1eM8299BS78kj/algTaMUJH8FdHPmGuQ6qIPpHySv7JLLKpbABb4asIL7T6NkCQxxC KRTQ== X-Gm-Message-State: ACrzQf1ULjX14Z7xRFt1/zyUaLDZOlS7M5jZMMzdvi/5jwGu5q/WZF4S 0UfOhIzxJuGlPka8YE/XF54RFq7Xc6iDAg== X-Google-Smtp-Source: AMsMyM61po6Nu4t61ep2BohZ91Gx/ZaWhgEsucAS5leocoJ2n1CZCylv4Ke+1Yi76BRD1hVVb2zQ3g== X-Received: by 2002:a63:ed07:0:b0:442:87:3a38 with SMTP id d7-20020a63ed07000000b0044200873a38mr4747956pgi.216.1664585943707; Fri, 30 Sep 2022 17:59:03 -0700 (PDT) Received: from smtpclient.apple ([2601:646:101:7fda:5c09:2098:9baa:aacb]) by smtp.gmail.com with ESMTPSA id i62-20020a626d41000000b0053e468a78a8sm2464941pfc.158.2022.09.30.17.59.02 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Sep 2022 17:59:02 -0700 (PDT) From: Bryn Llewellyn Message-Id: <35254B0B-6501-4CF6-A13F-76D03756C2B2@yugabyte.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_9C03FFFB-27D1-4919-8A98-EEFD7668CC18" Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) Subject: Re: Limiting the operations that client-side code can perform upon its database backend's artifacts Date: Fri, 30 Sep 2022 17:59:01 -0700 In-Reply-To: <20220930184515.mw2avsox5daz6yok@hjp.at> Cc: pgsql-general list To: "Peter J. Holzer" References: <3D119733-6784-4E84-98E4-5124E69D43F9@yugabyte.com> <20220927065858.ibrmzrrbefjq5o4l@jrouhaud> <20220927222637.aolob6gk3kuyirfs@hjp.at> <87E125A5-A4B8-4BD6-9E9C-7ABF77650F3F@yugabyte.com> <20220928011353.zo7enlnig5vvpowe@jrouhaud> <5B23D9B8-56E8-458F-AD3D-B5F88AAB2844@yugabyte.com> <20220928025427.coznr3we5plyq5pp@jrouhaud> <3881881.1664337639@sss.pgh.pa.us> <20220930184515.mw2avsox5daz6yok@hjp.at> X-Mailer: Apple Mail (2.3654.120.0.1.13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_9C03FFFB-27D1-4919-8A98-EEFD7668CC18 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > hjp-pgsql@hjp.at wrote: >=20 >> bryn@yugabyte.com wrote: >>=20 >> Paraphrasing Peter, the design of the application's RDBMS backend has = to implement its own notions of roles and privileges as a new layer on = top of whatever the native RDBMS mechanisms provide. Some RDBMSs have = native primitives that help the implementation of this next, = application-specific, roles-and-privileges regime. >=20 > Can you provide a link to documentation (hopefully high-level and = concise) of such a system? I'm having a hard time imagining one which I = wouldn't either classify as "database roles by another name" or "just = data". I fear that we might be about to start another round of mutual = misunderstanding. I=E2=80=99m not confident that I understand the = question. I believe that you want x-refs to accounts of native RDBMS features that = let you implement application-level specific notions of security on top = of the basic roles and privileges features and that are oriented to the = case where a single RDBMS role, "client", must expose differentiated = functionality to different human end-users=E2=80=94where these = principals are identified by, and authorized by, system(s) outside of = the RDBMS in question. In such a world, the RDBMS gets a suitable ID for = the human (by all means suitably encrypted) and can use this to = advantage by consulting its own representation of the current human's = identity. If my guess about your question is wrong, then I'm wasting my time. But = I'll carry on anyway. This is the canonical example: =E2=80=94A manager must be able to see the salaries of all employees in = the reporting hierarchy under her/him=E2=80=94but not be able to see = salaries outside of that subtree. Imagine the usual "employees" table with the pig's ear "manager_id" FK. = But add an extra column for each employees external-to-the-database = unique ID (unless this is already used as the table's PK). PG has a native feature for this: row level security (hereinafter RLS). = You can Google for blog posts about this use case. Here's one by a = colleague of mine, Franck: = https://dev.to/yugabyte/hyper-scale-multi-tenant-for-saas-an-example-with-= pgbench-33a3 = It uses the multi-tenant use case rather than my "managers-and-salaries" = one. But the principles are what matter. Never mind the detail. The = critical table(s) are striped with "tenant_id". And this is passed from = the application tier to the PG tier with: set rls.tenant_id=3D42; Using the "hard shell" paradigm, "rls.tenant_id" could be a formal = argument to an API subprogram. And its within-database representation = could be a one column, one row temporary table with "on commit delete = rows". Franck's PG RLS policies are created like this: create policy... on ... for... = using(tenant_id=3Dcurrent_setting('rls.tenant_id')::int); The argument of "using()" is just an arbitrary SQL expression that = evaluates to a boolean. https://www.postgresql.org/docs/current/sql-createpolicy.html So in the "managers-and-salaries" use case, it could be "employee_id in = ()". I'm afraid that I don't know what you mean by =C2=AB classify as = "database roles by another name" or "just data" =C2=BB. For me, the RLS = scheme is simply the native PG feature that you use to get the result = that you want. But the context of these examples is very definitely a = connection pooling regime that uses the single role "client" on behalf = of (very) many different human users. Finally, in case your question sought an account of some real-world = scheme in this general use case space, a bit of Googling for =C2=AB = Salesforce multi-tenancy =C2=BB got me this: Platform Multitenant Architecture = https://architect.salesforce.com/fundamentals/platform-multitenant-archite= cture = It's public knowledge that they use Oracle Database (or at least did=E2=80= =94I haven't thought about them recently). But the general principles = have their equivalents in PG too. Salesforce engineers have also talked at Oracle User group conferences = about how they use PL/SQL. Their main multi-tenant implementation (at = least at the time of these talks) followed the "hard shell" paradigm.= --Apple-Mail=_9C03FFFB-27D1-4919-8A98-EEFD7668CC18 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8
hjp-pgsql@hjp.at = wrote:


Paraphrasing Peter, the design of the = application's RDBMS backend has to implement its own notions of = roles and privileges as a new layer on top of whatever the native = RDBMS mechanisms provide. Some RDBMSs have native primitives that = help the implementation of this next, = application-specific, roles-and-privileges regime.

Can = you provide a link to documentation (hopefully high-level and = concise) of such a system? I'm having a hard time imagining = one which I wouldn't either classify as "database roles by another = name" or "just data".

I fear that = we might be about to start another round of mutual misunderstanding. = I=E2=80=99m not confident that I understand the question.

I believe that you want = x-refs to accounts of native RDBMS features that let you implement = application-level specific notions of security on top of the basic roles = and privileges features and that are oriented to the case where a single = RDBMS role, "client", must expose differentiated functionality to = different human end-users=E2=80=94where these principals are identified = by, and authorized by, system(s) outside of the RDBMS in question. In = such a world, the RDBMS gets a suitable ID for the human (by all means = suitably encrypted) and can use this to advantage by consulting its own = representation of the current human's identity.

If my guess about your question is = wrong, then I'm wasting my time. But I'll carry on anyway.

This is the canonical = example:

=E2=80=94= A manager must be able to see the salaries of all employees in the = reporting hierarchy under her/him=E2=80=94but not be able to see = salaries outside of that subtree.

Imagine the usual "employees" table = with the pig's ear "manager_id" FK. But add an extra column for each = employees external-to-the-database unique ID (unless this is already = used as the table's PK).

PG has a native feature for this: row level security = (hereinafter RLS). You can Google for blog posts about this use case. = Here's one by a colleague of mine, Franck:


It uses the multi-tenant use case rather than my = "managers-and-salaries" one. But the principles are what matter. Never = mind the detail. The critical table(s) are striped with "tenant_id". And = this is passed from the application tier to the PG tier with:

set rls.tenant_id=3D42;

Using the "hard shell" paradigm, = "rls.tenant_id" could be a formal argument to an API subprogram. And its = within-database representation could be a one column, one row temporary = table with "on commit delete rows".

Franck's PG RLS  policies are = created like this:

create policy... on ... for... using(t= enant_id=3Dcurrent_setting('rls.tenant_id')::int);

The argument of = "using()" is just an arbitrary SQL expression that evaluates to a = boolean.






It's public knowledge that they use Oracle Database (or at = least did=E2=80=94I haven't thought about them recently). But the = general principles have their equivalents in PG too.

Salesforce engineers = have also talked at Oracle User group conferences about how they use = PL/SQL. Their main multi-tenant implementation (at least at the time of = these talks) followed the "hard shell" paradigm.
= --Apple-Mail=_9C03FFFB-27D1-4919-8A98-EEFD7668CC18--