From: | Jacob Champion <jacob(dot)champion(at)enterprisedb(dot)com> |
---|---|
To: | Daniel Gustafsson <daniel(at)yesql(dot)se> |
Cc: | PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Shlok Kyal <shlok(dot)kyal(dot)oss(at)gmail(dot)com>, mahendrakar s <mahendrakarforpg(at)gmail(dot)com>, Andrey Chudnovsky <achudnovskij(at)gmail(dot)com>, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, "hlinnaka(at)iki(dot)fi" <hlinnaka(at)iki(dot)fi>, "michael(at)paquier(dot)xyz" <michael(at)paquier(dot)xyz>, "smilingsamay(at)gmail(dot)com" <smilingsamay(at)gmail(dot)com>, Stephen Frost <sfrost(at)snowman(dot)net> |
Subject: | Re: [PoC] Federated Authn/z with OAUTHBEARER |
Date: | 2024-03-01 00:04:05 |
Message-ID: | CAOYmi+my-TSnTmtcVkN=UY0sPtG_STgqm-gnYLwS0LayMMJzdA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Wed, Feb 28, 2024 at 9:40 AM Daniel Gustafsson <daniel(at)yesql(dot)se> wrote:
> +#define ALLOC(size) malloc(size)
> I wonder if we should use pg_malloc_extended(size, MCXT_ALLOC_NO_OOM) instead
> to self document the code. We clearly don't want feature-parity with server-
> side palloc here. I know we use malloc in similar ALLOC macros so it's not
> unique in that regard, but maybe?
I have a vague recollection that linking fe_memutils into libpq
tripped the exit() checks, but I can try again and see.
> +#ifdef FRONTEND
> + destroyPQExpBuffer(lex->errormsg);
> +#else
> + pfree(lex->errormsg->data);
> + pfree(lex->errormsg);
> +#endif
> Wouldn't it be nicer if we abstracted this into a destroyStrVal function to a)
> avoid the ifdefs and b) make it more like the rest of the new API? While it's
> only used in two places (close to each other) it's a shame to let the
> underlying API bleed through the abstraction.
Good idea. I'll fold this from your patch into the next set (and do
the same for the ones I've marked +1 below).
> + CURLM *curlm; /* top-level multi handle for cURL operations */
> Nitpick, but curl is not capitalized cURL anymore (for some value of "anymore"
> since it changed in 2016 [0]). I do wonder if we should consistently write
> "libcurl" as well since we don't use curl but libcurl.
Huh, I missed that memo. Thanks -- that makes it much easier to type!
> + PQExpBufferData work_data; /* scratch buffer for general use (remember
> + to clear out prior contents first!) */
> This seems like asking for subtle bugs due to uncleared buffers bleeding into
> another operation (especially since we are writing this data across the wire).
> How about having an array the size of OAuthStep of unallocated buffers where
> each step use it's own? Storing the content of each step could also be useful
> for debugging. Looking at the statemachine here it's not an obvious change but
> also not impossible.
I like that idea; I'll give it a look.
> + * TODO: This disables DNS resolution timeouts unless libcurl has been
> + * compiled against alternative resolution support. We should check that.
> curl_version_info() can be used to check for c-ares support.
+1
> + * so you don't have to write out the error handling every time. They assume
> + * that they're embedded in a function returning bool, however.
> It feels a bit iffy to encode the returntype in the macro, we can use the same
> trick that DISABLE_SIGPIPE employs where a failaction is passed in.
+1
> + if (!strcmp(name, field->name))
> Project style is to test for (strcmp(x,y) == 0) rather than (!strcmp()) to
> improve readability.
+1
> + libpq_append_conn_error(conn, "out of memory");
> While not introduced in this patch, it's not an ideal pattern to report "out of
> memory" errors via a function which may allocate memory.
Does trying (and failing) to allocate more memory cause any harm? Best
case, we still have enough room in the errorMessage to fit the whole
error; worst case, we mark the errorMessage broken and then
PQerrorMessage() can handle it correctly.
> + appendPQExpBufferStr(&conn->errorMessage,
> + libpq_gettext("server's error message contained an embedded NULL"));
> We should maybe add ", discarding" or something similar after this string to
> indicate that there was an actual error which has been thrown away, the error
> wasn't that the server passed an embedded NULL.
+1
> +#ifdef USE_OAUTH
> + else if (strcmp(mechanism_buf.data, OAUTHBEARER_NAME) == 0 &&
> + !selected_mechanism)
> I wonder if we instead should move the guards inside the statement and error
> out with "not built with OAuth support" or something similar like how we do
> with TLS and other optional components?
This one seems like a step backwards. IIUC, the client can currently
handle a situation where the server returns multiple mechanisms
(though the server doesn't support that yet), and I'd really like to
make use of that property without making users upgrade libpq.
That said, it'd be good to have a more specific error message in the
case where we don't have a match...
> + errdetail("Comma expected, but found character %s.",
> + sanitize_char(*p))));
> The %s formatter should be wrapped like '%s' to indicate that the message part
> is the character in question (and we can then reuse the translation since the
> error message already exist for SCRAM).
+1
> + temp = curl_slist_append(temp, "authorization_code");
> + if (!temp)
> + oom = true;
> +
> + temp = curl_slist_append(temp, "implicit");
> While not a bug per se, it reads a bit odd to call another operation that can
> allocate memory when the oom flag has been set. I think we can move some
> things around a little to make it clearer.
I'm not a huge fan of nested happy paths/pyramids of doom, but in this
case it's small enough that I'm not opposed. :D
> The attached diff contains some (most?) of the above as a patch on top of your
> v17, but as a .txt to keep the CFBot from munging on it.
Thanks very much! I plan to apply all but the USE_OAUTH guard change
(but let me know if you feel strongly about it).
--Jacob
From | Date | Subject | |
---|---|---|---|
Next Message | Greg Sabino Mullane | 2024-03-01 00:05:13 | Avoiding inadvertent debugging mode for pgbench |
Previous Message | Tomas Vondra | 2024-02-29 23:44:32 | Re: BitmapHeapScan streaming read user and prelim refactoring |