Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sMSEN-002Ujq-Se for pgsql-general@arkaria.postgresql.org; Wed, 26 Jun 2024 12:58:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sMSEL-004KiD-MW for pgsql-general@arkaria.postgresql.org; Wed, 26 Jun 2024 12:58:34 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sMSEL-004Ki5-AM for pgsql-general@lists.postgresql.org; Wed, 26 Jun 2024 12:58:33 +0000 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sMSEI-003E2N-Hp for pgsql-general@lists.postgresql.org; Wed, 26 Jun 2024 12:58:32 +0000 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-70670fb3860so3110092b3a.1 for ; Wed, 26 Jun 2024 05:58:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719406709; x=1720011509; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=XyY6fOniDPeDyu/midxIJrrjY9DbaqeGhol+m9ptEn4=; b=IcJEIAf5ybG3PNWZ/Wuu3Bfho4ufFEmr9S2O78Cuj6phIh6vclQcKNVPpkerT459Wt 7z2WXoo+ORnZIY80t03ZbbdF8pAI9mhcexzxnZ7OwIJS5snmJ5B2V4w/FmbcglUXMdyi mghgBKrNLHL1o5WZf868vdQn34QL/RM+QQk852rGPWXjcKzAArpv9/tv7uxXScZIalKW Evh+M6Hratwkr59Czeo2zOWIJgxXH3alU02SeUXYyyfw1auonPaeWrj3PS9fdDGRYhAt OFyoHCf7CWE1c+U4ibP6nOVyhH8L1Ze9uOMA4PvqniMPs4usArX1FWgGppgwXuNwqM6i csfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719406709; x=1720011509; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=XyY6fOniDPeDyu/midxIJrrjY9DbaqeGhol+m9ptEn4=; b=I6n4yK6rrBkQQ5lvfVzsRLzMos/8fbfsQk8rhbtA8NdflsRfunzWF8g6bbAQGc3aao QXVYaO5MX7K2J1PYQ0m+ZychsX8exw3OtfepVPDMyxr0FccjINZAwcZ+IC4ddJW1e03/ VNPp+ppMlW1lclnNcmr2F8PVGLpkS0NqcLRqyFvUB4RT3wqH/8VQQe3+Z0na181BEo45 YdXtGbBkjMtqTkAZw7igeShynX0ka+1B6srVApcZjsrrwHBV9zYMxxJviFNQK7BMrI2n QoTdfLhsLKQnfftkm9yqEyu2OL//8sg/5pxRT5gNcydbU1VabrIzhycbqSHOFNaUltVA kXQA== X-Forwarded-Encrypted: i=1; AJvYcCXB1odlcKauO3N2DxDM3Us167Hh80Ag7DB78OOOIWwMNnBo2G08FrVFa6kljO1I0pwB2+Nn08Zu/VlwR6Ov5zlkcpc1ZIZwB6WKK5oie2PYl2Op X-Gm-Message-State: AOJu0YwRNeQH1iQeGkc3CgOqC5SpAoFk3PvZKqdVSnfL8dRraUdv4ysx 1CLRUQQHhWZwVtuwECY9ifJNL7C0kn6/s8oSvh+I9kt4kN76xTYvFHtMw1eKmgdx06bJVlEMBry H7/oUth6bltBlpDWcVWAlKNLx840= X-Google-Smtp-Source: AGHT+IHRmDId77P1lo/fy+oQDJAKt0iDSFpjIsRM9Agzmr3XpXOiTvPLIbr0xowi8uIWPUmuv1BlwhzzxqdNf5iIiCE= X-Received: by 2002:a05:6a20:baa7:b0:1bd:858e:a8be with SMTP id adf61e73a8af0-1bd858eaad4mr1569836637.59.1719406709565; Wed, 26 Jun 2024 05:58:29 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Isaac Morland Date: Wed, 26 Jun 2024 08:58:17 -0400 Message-ID: Subject: Re: current_role of caller of a DEFINER function To: "David G. Johnston" Cc: Dominique Devienne , "pgsql-general@lists.postgresql.org" Content-Type: multipart/alternative; boundary="00000000000025f40f061bca9293" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000025f40f061bca9293 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, 26 Jun 2024 at 08:42, David G. Johnston wrote: > On Wednesday, June 26, 2024, Dominique Devienne > wrote: > >> Only session_user >> is representative of the caller, and reliable (modulo SUPERUSER and >> SET AUTHORIZATION, but that's a different story and kinda normal) >> > > Why can you not use session_user then? > Speaking only for myself, if I am writing a security definer and I go to check the calling role, I want to know the role which was used in the privilege check as to whether the function would even be permitted to be called. What I would be looking for is to behave differently depending on who called me. The original role which connected to the database is totally irrelevant, and could even be a security problem: if superuser does a set role, I shouldn't then be doing security checks which report back that the current role is superuser. Imagine code like this: select objects from table where owner =3D [calling role] =E2=80=A6 I think this ties into the related discussions on questions like what search_path should be in effect during trigger execution and during REFRESH MATERIALIZED VIEW and other maintenance commands. It also relates into the question of what role executes triggers and performs calculations during REFRESH MATERIALIZED VIEW and other maintenance commands. Essentially the current behaviour is quirky and built up over time by a series of individual decisions, and does not appear to have any systematic theory of operation which would answer all these questions all at once. --00000000000025f40f061bca9293 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Wed, 26 Jun 2024 at 08:42, David G. Jo= hnston <david.g.johnston@g= mail.com> wrote:
On Wednesday, June 26, 2024, Dominique Devienne <ddevienne@gmail.com> wrote:
<= blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-l= eft-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);pa= dding-left:1ex">Only session_user
is representative of the caller, and reliable (modulo SUPERUSER and
SET AUTHORIZATION, but that's a different story and kinda normal)

Why can you not use session_user then?

Speaking only for myself, if I am writin= g a security definer and I go to check the calling role, I want to know the= role which was used in the privilege check as to whether the function woul= d even be permitted to be called. What I would be looking for is to behave = differently depending on who called me. The original role which connected t= o the database is totally irrelevant, and could even be a security problem:= if superuser does a set role, I shouldn't then be doing security check= s which report back that the current role is superuser.

Imagine code like this:

select objects from = table where owner =3D [calling role] =E2=80=A6

I t= hink this ties into the related discussions on questions like what search_p= ath should be in effect during trigger execution and during REFRESH MATERIA= LIZED VIEW and other maintenance commands. It also relates into the questio= n of what role executes triggers=C2=A0and performs calculations during REFR= ESH MATERIALIZED VIEW and other maintenance commands.

<= div>Essentially the current behaviour is quirky and built up over time by a= series of individual decisions, and does not appear to have any systematic= theory of operation which would answer all these questions all at once.
--00000000000025f40f061bca9293--