pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jeff Davis <pgsql@j-davis.com>
To: pgsql-bugs@postgresql.org
Subject: search_path not recomputed when role name changes
Date: Thu, 27 Jul 2023 11:21:25 -0700
Message-ID: <186761d32c0255debbdf50b6310b581b9c973e6c.camel@j-davis.com> (raw)


Session 1 as superuser:
  CREATE USER u1;
  CREATE SCHEMA u1 AUTHORIZATION u1;
  GRANT ALL PRIVILEGES ON SCHEMA public TO u1;

Session 2 as u1:
  SET search_path= "$user", public;
  CREATE TABLE u1.x(t) AS SELECT 'data in u1.x';  
  CREATE TABLE public.x(t) AS SELECT 'data in public.x';
  SELECT t FROM x; -- uses u1.x

Session 1 as superuser:
  ALTER ROLE u1 RENAME TO u2;

Session 2 as u1:
  SELECT CURRENT_USER; -- shows u2
  SHOW search_path; -- $user, public
  SELECT t FROM x; -- UNEXPECTED: uses u1.x still
  SET search_path = public;
  SET search_path TO default;
  SELECT t FROM x; -- uses public.x

The fix is simple, attached.


-- 
Jeff Davis
PostgreSQL Contributor Team - AWS

Attachments:

v1-0001-Recalculate-search_path-after-ALTER-ROLE.patch (text/x-patch, 1.2K) download From 4b541cf72cab68fe7f0f1a8afdac02fa3acaa23c Mon Sep 17 00:00:00 2001 From: Jeff Davis <jeff@j-davis.com> Date: Thu, 27 Jul 2023 10:55:26 -0700 Subject: [PATCH v1] Recalculate search_path after ALTER ROLE. Renaming a role can affect the meaning of the special string $user, so must cause search_path to be recalculated. --- src/backend/catalog/namespace.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/backend/catalog/namespace.c b/src/backend/catalog/namespace.c index 69ab1b8e4b..474970baf0 100644 --- a/src/backend/catalog/namespace.c +++ b/src/backend/catalog/namespace.c @@ -4396,11 +4396,15 @@ InitializeSearchPath(void) { /* * In normal mode, arrange for a callback on any syscache invalidation - * of pg_namespace rows. + * of pg_namespace or pg_authid rows. (Changing a role name may affect + * the meaning of the special string $user.) */ CacheRegisterSyscacheCallback(NAMESPACEOID, NamespaceCallback, (Datum) 0); + CacheRegisterSyscacheCallback(AUTHOID, + NamespaceCallback, + (Datum) 0); /* Force search path to be recomputed on next use */ baseSearchPathValid = false; } -- 2.34.1

view thread (6+ messages)  latest in thread

Message-ID: <186761d32c0255debbdf50b6310b581b9c973e6c.camel@j-davis.com>
Permalink:  ../186761d32c0255debbdf50b6310b581b9c973e6c.camel@j-davis.com/
Also on:    postgresql.org/message-id/186761d32c0255debbdf50b6310b581b9c973e6c.camel@j-davis.com

 ·  · 

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-bugs@postgresql.org
  Cc: pgsql@j-davis.com
  Subject: Re: search_path not recomputed when role name changes
  In-Reply-To: <186761d32c0255debbdf50b6310b581b9c973e6c.camel@j-davis.com>
  References: <186761d32c0255debbdf50b6310b581b9c973e6c.camel@j-davis.com>

* 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