pg.ddx.io pgsql-bugs@postgresql.org mailing list archivehelp / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: Richard Guo <guofenglinux@gmail.com>
Cc: hysong0101@163.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #17909: CREATE SCHEMA AUTHORIZATION sch CREATE TABLE foo ( id INT ) will coredump
Date: Fri, 28 Apr 2023 08:05:22 +0900
Message-ID: <ZEr/shjg+8TClUm/@paquier.xyz> (raw)
In-Reply-To: <CAMbWs49CfOfrMp_AGPiBo7g7BusGf2gy1kGSatm-BYO5aeojvQ@mail.gmail.com>
References: <17909-f65c12dfc5f0451d@postgresql.org>
<ZEolfwBHm6+znydH@paquier.xyz>
<CAMbWs4-f5w+YCzqd90YAS-ogPxoahzfJ7C1QUUo8X+KE=0UC4w@mail.gmail.com>
<ZEpA1SgNzEqhgCvA@paquier.xyz>
<CAMbWs49CfOfrMp_AGPiBo7g7BusGf2gy1kGSatm-BYO5aeojvQ@mail.gmail.com>
On Thu, Apr 27, 2023 at 06:28:28PM +0800, Richard Guo wrote:
> I noticed that in CreateSchemaCommand there is logic that fills schema
> name with the role name if it is not specified. Do you think we can
> save the new-filled schema name into CreateSchemaStmt.schemaname there?
It's actually much trickier than that, on second look, as a RoleSpec
is embedded in this portion of a query because we need to support
CURRENT_ROLE, CURRENT_SESSION and SESSION_USER. For example, this
query assigns neither role name nor schema name we could rely on at
transformation for the objects:
create schema authorization current_role create table aa (a int);
Anyway, semantically, something could go very wrong if we decide to
enforce a schema name for the objects based on the RoleSpec at the
time of transformation, because we may finish by executing the CREATE
SCHEMA command under an entirely different context than what we could
assign. So, I think that we should do the following in the
transformation path if an object is schema-qualified:
- Fail immediately if there is no schema and no role name at hand,
just give up. This needs a new error message, say:
"CREATE specifies a schema (%object_schema) without providing a schema
name."
- If there is a role name, aka RoleSpec points to a ROLESPEC_CSTRING,
use it as a comparison with the objects schema-qualified. Note that
there is no case for public, because we would fail on
get_rolespec_oid() when the schema is created.
There is also a very fancy case, if "foo" matches to the role that
would be assigned by GetUserIdAndSecContext() when executing the
schema command:
create schema authorization session_role create table foo.aa (a int);
One could say that this should work, and my proposal would cause an
error to make the query more predictible at an earlier step. IMO, I
think that this is just saner. And this case crashes today like the
others.
Any thoughts or objections about doing that?
--
Michael
Attachments:
[application/pgp-signature] signature.asc (832B, ../ZEr%2Fshjg+8TClUm%2F@paquier.xyz/2-signature.asc)
download
view thread (14+ messages) latest in thread
Message-ID: <ZEr/shjg+8TClUm/@paquier.xyz> Permalink: ../ZEr%2Fshjg+8TClUm%2F@paquier.xyz/ Also on: postgresql.org/message-id/ZEr/shjg+8TClUm/@paquier.xyz ·
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 using the --to and --cc options: reply via email To: pgsql-bugs@postgresql.org Cc: michael@paquier.xyz, guofenglinux@gmail.com, hysong0101@163.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17909: CREATE SCHEMA AUTHORIZATION sch CREATE TABLE foo ( id INT ) will coredump In-Reply-To: <ZEr/shjg+8TClUm/@paquier.xyz> * 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