Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mJ1Kr-0003Fe-9v for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Aug 2021 22:25:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mJ1Kp-0001y7-3K for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Aug 2021 22:25:27 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mJ1Ko-0001xz-Mb for pgsql-hackers@lists.postgresql.org; Wed, 25 Aug 2021 22:25:26 +0000 Received: from mail-lj1-x22f.google.com ([2a00:1450:4864:20::22f]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mJ1Kj-0002fU-Fc for pgsql-hackers@postgresql.org; Wed, 25 Aug 2021 22:25:25 +0000 Received: by mail-lj1-x22f.google.com with SMTP id y6so1355444lje.2 for ; Wed, 25 Aug 2021 15:25:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yugabyte.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ddj8cc1dIoRT7y3gh5/65IzKmkvvwDMBfBCv0hXz8VA=; b=NVfjWCSzw1EHgEpsdU+jnACzGRHjYP5u+O5mJnj091kjnGjLDCHhU/CE7UnsRa06PB Daej25NVAlazLBA2ieN0MU4fOiHJQh4rnnU90ZH3cWlumYFVq44moWh11yYsQPWzJgz1 c38y0ZUWLu8r7zBewR8T6+tqifFWRPyN3LQrM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ddj8cc1dIoRT7y3gh5/65IzKmkvvwDMBfBCv0hXz8VA=; b=ds9V+c3BFxT+cwDXrXbE+/NKGsCOfEAd0aNyxk7s7oUvWHNNRj5Z20oxpAQ1zvRUtt yD0CfVC2MVAkyZZibVJDwwYuYMHOwG5DG5b60LIucFNkVxyibrdtHDnZjRl1XCdIAe1e FY/OT11WnjzGfyDP/PfEW5ki4gGs8FUYraa9koL+AXB+vq0R2BMVninuvDE3c1MocZpr rT++GJFexLpkUvZlfAzNX2yjRZNTOTebeNKe/g6Bc7z9PIs1mgGsrfjRfhcgfUAGEolo /LYfBwW9zCcMIMt+BXIIZnVHFtmEBFjagEicUD4uaX9MaiMDPtq952haSLi7HGgQ247a ym1g== X-Gm-Message-State: AOAM531Rf5DyU1BrBaICX/Mqb2QJR2eAis0FswzMkooDg25JwMkziDqn nT/uhUatIghF3HTT0TZy9XHKWNJPk64xJAtqHSDXR7MXtAPmMw== X-Google-Smtp-Source: ABdhPJxcY1JQbhq/3tSZv6nKciAN0FEB8I8IFFM7Ajy0ASdBLT6nTcv9wC7gL/dtvDtUNs1x1aZ2tCjs4SicvcbQe2Y= X-Received: by 2002:a2e:b24f:: with SMTP id n15mr416652ljm.124.1629930319854; Wed, 25 Aug 2021 15:25:19 -0700 (PDT) MIME-Version: 1.0 References: <2f06a4aef1d5defe4b7aaec01478572e5557d32a.camel@vmware.com> <8a5a35b31c3f25f6b047e77def0445a60399981d.camel@vmware.com> In-Reply-To: <8a5a35b31c3f25f6b047e77def0445a60399981d.camel@vmware.com> From: Zhihong Yu Date: Wed, 25 Aug 2021 15:25:03 -0700 Message-ID: Subject: Re: [PoC] Federated Authn/z with OAUTHBEARER To: Jacob Champion Cc: "hlinnaka@iki.fi" , "pgsql-hackers@postgresql.org" , "michael@paquier.xyz" Content-Type: multipart/alternative; boundary="000000000000b9557f05ca69b950" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000b9557f05ca69b950 Content-Type: text/plain; charset="UTF-8" On Wed, Aug 25, 2021 at 11:42 AM Jacob Champion wrote: > On Tue, 2021-06-22 at 23:22 +0000, Jacob Champion wrote: > > On Fri, 2021-06-18 at 11:31 +0300, Heikki Linnakangas wrote: > > > > > > A few small things caught my eye in the backend oauth_exchange > function: > > > > > > > + /* Handle the client's initial message. */ > > > > + p = strdup(input); > > > > > > this strdup() should be pstrdup(). > > > > Thanks, I'll fix that in the next re-roll. > > > > > In the same function, there are a bunch of reports like this: > > > > > > > ereport(ERROR, > > > > + (errcode(ERRCODE_PROTOCOL_VIOLATION), > > > > + errmsg("malformed OAUTHBEARER message"), > > > > + errdetail("Comma expected, but found > character \"%s\".", > > > > + sanitize_char(*p)))); > > > > > > I don't think the double quotes are needed here, because sanitize_char > > > will return quotes if it's a single character. So it would end up > > > looking like this: ... found character "'x'". > > > > I'll fix this too. Thanks! > > v2, attached, incorporates Heikki's suggested fixes and also rebases on > top of latest HEAD, which had the SASL refactoring changes committed > last month. > > The biggest change from the last patchset is 0001, an attempt at > enabling jsonapi in the frontend without the use of palloc(), based on > suggestions by Michael and Tom from last commitfest. I've also made > some improvements to the pytest suite. No major changes to the OAuth > implementation yet. > > --Jacob > Hi, For v2-0001-common-jsonapi-support-FRONTEND-clients.patch : + /* Clean up. */ + termJsonLexContext(&lex); At the end of termJsonLexContext(), empty is copied to lex. For stack based JsonLexContext, the copy seems unnecessary. Maybe introduce a boolean parameter for termJsonLexContext() to signal that the copy can be omitted ? +#ifdef FRONTEND + /* make sure initialization succeeded */ + if (lex->strval == NULL) + return JSON_OUT_OF_MEMORY; Should PQExpBufferBroken(lex->strval) be used for the check ? Thanks --000000000000b9557f05ca69b950 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Wed, Aug 25, 2021 at 11:42 AM Jaco= b Champion <pchampion@vmware.com= > wrote:
= On Tue, 2021-06-22 at 23:22 +0000, Jacob Champion wrote:
> On Fri, 2021-06-18 at 11:31 +0300, Heikki Linnakangas wrote:
> >
> > A few small things caught my eye in the backend oauth_exchange fu= nction:
> >
> > > +=C2=A0 =C2=A0 =C2=A0 =C2=A0/* Handle the client's initi= al message. */
> > > +=C2=A0 =C2=A0 =C2=A0 =C2=A0p =3D strdup(input);
> >
> > this strdup() should be pstrdup().
>
> Thanks, I'll fix that in the next re-roll.
>
> > In the same function, there are a bunch of reports like this:
> >
> > >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 ereport(ERROR,
> > > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (errcode(ERRCODE_PROTOCOL_VIOLATION),
> > > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0errmsg("malformed OAUTHBEARER me= ssage"),
> > > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0errdetail("Comma expected, but f= ound character \"%s\".",
> > > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0sa= nitize_char(*p))));
> >
> > I don't think the double quotes are needed here, because sani= tize_char
> > will return quotes if it's a single character. So it would en= d up
> > looking like this: ... found character "'x'". >
> I'll fix this too. Thanks!

v2, attached, incorporates Heikki's suggested fixes and also rebases on=
top of latest HEAD, which had the SASL refactoring changes committed
last month.

The biggest change from the last patchset is 0001, an attempt at
enabling jsonapi in the frontend without the use of palloc(), based on
suggestions by Michael and Tom from last commitfest. I've also made
some improvements to the pytest suite. No major changes to the OAuth
implementation yet.

--Jacob
Hi,
For=C2=A0v2-0001-common-jsonapi-= support-FRONTEND-clients.patch :

+ =C2=A0 /* Clean up. = */
+ =C2=A0 termJsonLexContext(&lex);=C2=A0

At the end of=C2=A0termJsonLexContext(), empty is copied to lex. For = stack based=C2=A0JsonLexContext, the copy seems unnecessary.
Mayb= e introduce a boolean parameter for=C2=A0termJsonLexContext() to signal tha= t the copy can be omitted ?

+#ifdef FRONTEND
+ = =C2=A0 =C2=A0 =C2=A0 /* make sure initialization succeeded */
+ =C2=A0 = =C2=A0 =C2=A0 if (lex->strval =3D=3D NULL)
+ =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 return JSON_OUT_OF_MEMORY;

Should= =C2=A0PQExpBufferBroken(lex->strval) be used for the check ?
<= br>
Thanks
--000000000000b9557f05ca69b950--