pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedsearch_path not recomputed when role name changes
6+ messages / 3 participants
[nested] [flat]
Commits from this thread:
2023-08-07 43ba5105a8 a86d402278 90cadfd499 00953f1e23 9f3343e40d 0d56c32c8e fa2e874946 Recalculate search_path after ALTER ROLE.
* search_path not recomputed when role name changes
@ 2023-07-27 18:21 Jeff Davis <pgsql@j-davis.com>
0 siblings, 1 reply; 6+ messages in thread
From: Jeff Davis @ 2023-07-27 18:21 UTC (permalink / raw)
To: pgsql-bugs
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
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: search_path not recomputed when role name changes
@ 2023-07-30 04:08 Nathan Bossart <nathandbossart@gmail.com>
parent: Jeff Davis <pgsql@j-davis.com>
0 siblings, 1 reply; 6+ messages in thread
From: Nathan Bossart @ 2023-07-30 04:08 UTC (permalink / raw)
To: Jeff Davis <pgsql@j-davis.com>; +Cc: pgsql-bugs
On Thu, Jul 27, 2023 at 11:21:25AM -0700, Jeff Davis wrote:
> The fix is simple, attached.
LGTM
--
Nathan Bossart
Amazon Web Services: https://aws.amazon.com
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: search_path not recomputed when role name changes
@ 2023-07-30 05:58 Michael Paquier <michael@paquier.xyz>
parent: Nathan Bossart <nathandbossart@gmail.com>
0 siblings, 1 reply; 6+ messages in thread
From: Michael Paquier @ 2023-07-30 05:58 UTC (permalink / raw)
To: Nathan Bossart <nathandbossart@gmail.com>; +Cc: Jeff Davis <pgsql@j-davis.com>; pgsql-bugs
On Sat, Jul 29, 2023 at 09:08:02PM -0700, Nathan Bossart wrote:
> On Thu, Jul 27, 2023 at 11:21:25AM -0700, Jeff Davis wrote:
>> The fix is simple, attached.
>
> LGTM
Is that something that should have an isolation test?
--
Michael
Attachments:
signature.asc (application/pgp-signature, 832B) download
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: search_path not recomputed when role name changes
@ 2023-08-02 19:09 Jeff Davis <pgsql@j-davis.com>
parent: Michael Paquier <michael@paquier.xyz>
0 siblings, 1 reply; 6+ messages in thread
From: Jeff Davis @ 2023-08-02 19:09 UTC (permalink / raw)
To: Michael Paquier <michael@paquier.xyz>; Nathan Bossart <nathandbossart@gmail.com>; +Cc: pgsql-bugs
On Sun, 2023-07-30 at 14:58 +0900, Michael Paquier wrote:
> Is that something that should have an isolation test?
Good idea, attached.
Is there any logical ordering or grouping in the isolation_schedule? I
just added it at the end.
Regards,
Jeff Davis
Attachments:
v2-0001-Recalculate-search_path-after-ALTER-ROLE.patch (text/x-patch, 5.6K) download
From 7c71f0a390d575710a2d2f458f0a333b5bad1399 Mon Sep 17 00:00:00 2001
From: Jeff Davis <jeff@j-davis.com>
Date: Wed, 2 Aug 2023 11:51:50 -0700
Subject: [PATCH v2] 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.
Discussion: https://postgr.es/m/186761d32c0255debbdf50b6310b581b9c973e6c.camel@j-davis.com
---
src/backend/catalog/namespace.c | 6 +-
.../isolation/expected/search-path-inval.out | 97 +++++++++++++++++++
src/test/isolation/isolation_schedule | 1 +
.../isolation/specs/search-path-inval.spec | 59 +++++++++++
4 files changed, 162 insertions(+), 1 deletion(-)
create mode 100644 src/test/isolation/expected/search-path-inval.out
create mode 100644 src/test/isolation/specs/search-path-inval.spec
diff --git a/src/backend/catalog/namespace.c b/src/backend/catalog/namespace.c
index 1f76b5d7f7..0c679fbf94 100644
--- a/src/backend/catalog/namespace.c
+++ b/src/backend/catalog/namespace.c
@@ -4175,11 +4175,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;
}
diff --git a/src/test/isolation/expected/search-path-inval.out b/src/test/isolation/expected/search-path-inval.out
new file mode 100644
index 0000000000..e0173afdb2
--- /dev/null
+++ b/src/test/isolation/expected/search-path-inval.out
@@ -0,0 +1,97 @@
+Parsed test spec with 3 sessions
+
+starting permutation: s1a s2a s1a s2b
+step s1a:
+ SELECT CURRENT_USER;
+ SHOW search_path;
+ SELECT t FROM x;
+
+current_user
+----------------
+regress_sp_user1
+(1 row)
+
+search_path
+--------------------------
+"$user", regress_sp_public
+(1 row)
+
+t
+--------------------------
+data in regress_sp_user1.x
+(1 row)
+
+step s2a:
+ ALTER ROLE regress_sp_user1 RENAME TO regress_sp_user2;
+
+step s1a:
+ SELECT CURRENT_USER;
+ SHOW search_path;
+ SELECT t FROM x;
+
+current_user
+----------------
+regress_sp_user2
+(1 row)
+
+search_path
+--------------------------
+"$user", regress_sp_public
+(1 row)
+
+t
+---------------------------
+data in regress_sp_public.x
+(1 row)
+
+step s2b:
+ ALTER ROLE regress_sp_user2 RENAME TO regress_sp_user1;
+
+
+starting permutation: s1a s3a s1a s3b
+step s1a:
+ SELECT CURRENT_USER;
+ SHOW search_path;
+ SELECT t FROM x;
+
+current_user
+----------------
+regress_sp_user1
+(1 row)
+
+search_path
+--------------------------
+"$user", regress_sp_public
+(1 row)
+
+t
+--------------------------
+data in regress_sp_user1.x
+(1 row)
+
+step s3a:
+ ALTER SCHEMA regress_sp_user1 RENAME TO regress_sp_user2;
+
+step s1a:
+ SELECT CURRENT_USER;
+ SHOW search_path;
+ SELECT t FROM x;
+
+current_user
+----------------
+regress_sp_user1
+(1 row)
+
+search_path
+--------------------------
+"$user", regress_sp_public
+(1 row)
+
+t
+---------------------------
+data in regress_sp_public.x
+(1 row)
+
+step s3b:
+ ALTER SCHEMA regress_sp_user2 RENAME TO regress_sp_user1;
+
diff --git a/src/test/isolation/isolation_schedule b/src/test/isolation/isolation_schedule
index 4fc56ae99c..eab9f2243e 100644
--- a/src/test/isolation/isolation_schedule
+++ b/src/test/isolation/isolation_schedule
@@ -110,3 +110,4 @@ test: serializable-parallel
test: serializable-parallel-2
test: serializable-parallel-3
test: matview-write-skew
+test: search-path-inval
\ No newline at end of file
diff --git a/src/test/isolation/specs/search-path-inval.spec b/src/test/isolation/specs/search-path-inval.spec
new file mode 100644
index 0000000000..08b1bba2fc
--- /dev/null
+++ b/src/test/isolation/specs/search-path-inval.spec
@@ -0,0 +1,59 @@
+# Test search_path invalidation.
+
+setup
+{
+ CREATE USER regress_sp_user1;
+ CREATE SCHEMA regress_sp_user1 AUTHORIZATION regress_sp_user1;
+ CREATE SCHEMA regress_sp_public;
+ GRANT ALL PRIVILEGES ON SCHEMA regress_sp_public TO regress_sp_user1;
+}
+
+teardown
+{
+ DROP SCHEMA regress_sp_public CASCADE;
+ DROP SCHEMA regress_sp_user1 CASCADE;
+ DROP USER regress_sp_user1;
+}
+
+session s1
+setup
+{
+ SET search_path = "$user", regress_sp_public;
+ SET SESSION AUTHORIZATION regress_sp_user1;
+ CREATE TABLE regress_sp_user1.x(t) AS SELECT 'data in regress_sp_user1.x';
+ CREATE TABLE regress_sp_public.x(t) AS SELECT 'data in regress_sp_public.x';
+}
+step s1a
+{
+ SELECT CURRENT_USER;
+ SHOW search_path;
+ SELECT t FROM x;
+}
+
+session s2
+step s2a
+{
+ ALTER ROLE regress_sp_user1 RENAME TO regress_sp_user2;
+}
+step s2b
+{
+ ALTER ROLE regress_sp_user2 RENAME TO regress_sp_user1;
+}
+
+session s3
+step s3a
+{
+ ALTER SCHEMA regress_sp_user1 RENAME TO regress_sp_user2;
+}
+step s3b
+{
+ ALTER SCHEMA regress_sp_user2 RENAME TO regress_sp_user1;
+}
+
+# s1's search_path is invalidated by role name change in s2a, and
+# falls back to regress_sp_public.x
+permutation s1a s2a s1a s2b
+
+# s1's search_path is invalidated by schema name change in s2b, and
+# falls back to regress_sp_public.x
+permutation s1a s3a s1a s3b
--
2.34.1
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: search_path not recomputed when role name changes
@ 2023-08-03 23:28 Nathan Bossart <nathandbossart@gmail.com>
parent: Jeff Davis <pgsql@j-davis.com>
0 siblings, 1 reply; 6+ messages in thread
From: Nathan Bossart @ 2023-08-03 23:28 UTC (permalink / raw)
To: Jeff Davis <pgsql@j-davis.com>; +Cc: Michael Paquier <michael@paquier.xyz>; pgsql-bugs
On Wed, Aug 02, 2023 at 12:09:58PM -0700, Jeff Davis wrote:
> Is there any logical ordering or grouping in the isolation_schedule? I
> just added it at the end.
It looks like folks try to group related tests, but I don't sense any
strict ordering. It's probably fine to add it to the end. Maybe we should
alphabetize the list someday (/me braces for collation jokes).
--
Nathan Bossart
Amazon Web Services: https://aws.amazon.com
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: search_path not recomputed when role name changes
@ 2023-08-07 23:20 Michael Paquier <michael@paquier.xyz>
parent: Nathan Bossart <nathandbossart@gmail.com>
0 siblings, 0 replies; 6+ messages in thread
From: Michael Paquier @ 2023-08-07 23:20 UTC (permalink / raw)
To: Nathan Bossart <nathandbossart@gmail.com>; +Cc: Jeff Davis <pgsql@j-davis.com>; pgsql-bugs
On Thu, Aug 03, 2023 at 04:28:41PM -0700, Nathan Bossart wrote:
> It looks like folks try to group related tests, but I don't sense any
> strict ordering. It's probably fine to add it to the end. Maybe we should
> alphabetize the list someday (/me braces for collation jokes).
Isolation tests have been added over the years in the order that a
committer and/or author saw fit at the point when it was added. There
has never been any kind of strict ordering, but there may be locations
where having a new test makes more sense than other locations.
--
Michael
Attachments:
signature.asc (application/pgp-signature, 832B) download
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2023-08-07 23:20 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-07-27 18:21 search_path not recomputed when role name changes Jeff Davis <pgsql@j-davis.com>
2023-07-30 04:08 ` Nathan Bossart <nathandbossart@gmail.com>
2023-07-30 05:58 ` Michael Paquier <michael@paquier.xyz>
2023-08-02 19:09 ` Jeff Davis <pgsql@j-davis.com>
2023-08-03 23:28 ` Nathan Bossart <nathandbossart@gmail.com>
2023-08-07 23:20 ` Michael Paquier <michael@paquier.xyz>
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