pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Drouvot, Bertrand <bertranddrouvot.pg@gmail.com>
To: Jacob Champion <jchampion@timescale.com>
To: Drouvot, Bertrand <bdrouvot@amazon.com>
To: Michael Paquier <michael@paquier.xyz>
Cc: Alvaro Herrera <alvherre@alvh.no-ip.org>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Joe Conway <mail@joeconway.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: SYSTEM_USER reserved word implementation
Date: Mon, 26 Sep 2022 15:09:40 +0200
Message-ID: <ea078f3a-29d9-9983-6bf8-35aea17d40bb@gmail.com> (raw)
In-Reply-To: <dc0e1444-9520-2841-5d9e-df054a1aae05@timescale.com>
References: <20220627173250.46lvecpvuunc7pf5@alvherre.pgsql>
	<c2727e30-a3d3-465f-f253-bfff81611a21@amazon.com>
	<24d638c7-16f6-afb9-c25c-6a29c169210e@amazon.com>
	<CAAWbhmiPwGCevz_FS3rRK5fWQ8RiLW2bPVABzJVDxVWCuMFdmg@mail.gmail.com>
	<8fe1752a-2e3d-4ee8-656c-0caf5d860b0e@amazon.com>
	<db5f852b-7e22-7b25-a0f3-5b4a67cd5be9@amazon.com>
	<YwWooBzPlfzncJea@paquier.xyz>
	<1da0e60c-bd85-9f2d-2039-103055338b00@amazon.com>
	<40b4e4d0-d034-ea19-3ec3-1557f498770f@amazon.com>
	<YwgboqQUV1+Y/k6z@paquier.xyz>
	<Yxha7/s9z8qk/R1e@paquier.xyz>
	<9dae37cb-abe0-a773-da74-3e2b62279d4c@amazon.com>
	<dc0e1444-9520-2841-5d9e-df054a1aae05@timescale.com>

Hi,

On 9/7/22 5:48 PM, Jacob Champion wrote:
> On 9/7/22 07:46, Drouvot, Bertrand wrote:
>> Except the Nit above, that looks all good to me.
> 
> A few additional comments:
> 
>> +        assigned a database role. It is represented as
>> +        <literal>auth_method:identity</literal> or
>> +        <literal>NULL</literal> if the user has not been authenticated (for
>> +        example if <xref linkend="auth-trust"/> has been used).
>> +       </para></entry>
> 
> This is rendered as
> 
>      ... (for example if Section 21.4 has been used).
> 
> which IMO isn't too helpful. Maybe a <link> would read better than an
> <xref>?

Thanks for looking at it!
Good catch, V4 coming soon will make use of <link> instead.

> 
> Also, this function's placement in the docs (with the System Catalog
> Information Functions) seems wrong to me. I think it should go up above
> in the Session Information Functions, with current_user et al.

Agree, will move it to the Session Information Functions in V4.

> 
>> +               /* Build system user as auth_method:authn_id */
>> +               char       *system_user;
>> +               Size            authname_len = strlen(auth_method);
>> +               Size            authn_id_len = strlen(authn_id);
>> +
>> +               system_user = palloc0(authname_len + authn_id_len + 2);
>> +               strcat(system_user, auth_method);
>> +               strcat(system_user, ":");
>> +               strcat(system_user, authn_id);
> 
> If we're palloc'ing anyway, can this be replaced with a single psprintf()?

Fair point, V4 will make use of psprintf().

> 
>> +       /* Initialize SystemUser now that MyClientConnectionInfo is restored. */
>> +       InitializeSystemUser(MyClientConnectionInfo.authn_id,
>> +                                                hba_authname(MyClientConnectionInfo.auth_method));
> 
> It makes me a little nervous to call hba_authname(auth_method) without
> checking to see that auth_method is actually valid (which is only true
> if authn_id is not NULL).

Will add additional check for safety in V4.


> 
> We could pass the bare auth_method index, or update the documentation
> for auth_method to state that it's guaranteed to be zero if authn_id is
> NULL (and then enforce that).
> 
>>          case SVFOP_CURRENT_USER:
>>          case SVFOP_USER:
>>          case SVFOP_SESSION_USER:
>> +       case SVFOP_SYSTEM_USER:
>>          case SVFOP_CURRENT_CATALOG:
>>          case SVFOP_CURRENT_SCHEMA:
>>              svf->type = NAMEOID;
> 
> Should this be moved to use TEXTOID instead?

Good catch, will do in V4.

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com





view thread (42+ messages)  latest in thread

Message-ID: <ea078f3a-29d9-9983-6bf8-35aea17d40bb@gmail.com>
Permalink:  ../ea078f3a-29d9-9983-6bf8-35aea17d40bb@gmail.com/
Also on:    postgresql.org/message-id/ea078f3a-29d9-9983-6bf8-35aea17d40bb@gmail.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-hackers@postgresql.org
  Cc: bertranddrouvot.pg@gmail.com, jchampion@timescale.com, bdrouvot@amazon.com, michael@paquier.xyz, alvherre@alvh.no-ip.org, tgl@sss.pgh.pa.us, mail@joeconway.com
  Subject: Re: SYSTEM_USER reserved word implementation
  In-Reply-To: <ea078f3a-29d9-9983-6bf8-35aea17d40bb@gmail.com>
  References: <20220627173250.46lvecpvuunc7pf5@alvherre.pgsql> <c2727e30-a3d3-465f-f253-bfff81611a21@amazon.com> <24d638c7-16f6-afb9-c25c-6a29c169210e@amazon.com> <CAAWbhmiPwGCevz_FS3rRK5fWQ8RiLW2bPVABzJVDxVWCuMFdmg@mail.gmail.com> <8fe1752a-2e3d-4ee8-656c-0caf5d860b0e@amazon.com> <db5f852b-7e22-7b25-a0f3-5b4a67cd5be9@amazon.com> <YwWooBzPlfzncJea@paquier.xyz> <1da0e60c-bd85-9f2d-2039-103055338b00@amazon.com> <40b4e4d0-d034-ea19-3ec3-1557f498770f@amazon.com> <YwgboqQUV1+Y/k6z@paquier.xyz> <Yxha7/s9z8qk/R1e@paquier.xyz> <9dae37cb-abe0-a773-da74-3e2b62279d4c@amazon.com> <dc0e1444-9520-2841-5d9e-df054a1aae05@timescale.com> <ea078f3a-29d9-9983-6bf8-35aea17d40bb@gmail.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