Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t6T02-00DAqo-5t for pgsql-hackers@arkaria.postgresql.org; Thu, 31 Oct 2024 11:05:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1t6Szz-000JJV-Iy for pgsql-hackers@arkaria.postgresql.org; Thu, 31 Oct 2024 11:05:55 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t6Szz-000JJN-61 for pgsql-hackers@lists.postgresql.org; Thu, 31 Oct 2024 11:05:55 +0000 Received: from mail-lf1-x141.google.com ([2a00:1450:4864:20::141]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1t6Szs-003zR7-VB for pgsql-hackers@postgresql.org; Thu, 31 Oct 2024 11:05:54 +0000 Received: by mail-lf1-x141.google.com with SMTP id 2adb3069b0e04-539fb49c64aso1224607e87.0 for ; Thu, 31 Oct 2024 04:05:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=cybertec.at; t=1730372748; x=1730977548; darn=postgresql.org; h=message-id:date:content-transfer-encoding:mime-version:comments :references:in-reply-to:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=w5fI+wR+QNtTlzyOy56kkRZIb1b+t2ChizkiHvAl9co=; b=G9rJc9WI/sZ/AqDxvzwraiuVLyLYSNoH9PjKuh/xHNMpLx3+GqLq8fg3ouIbMjSaI/ /TQMUoOettw8y9FDZfsxn14tng07TDxEybHduKrvgLnF3ja0+VOH2VIIDNC3ICqxTnFn rMZq9yVbrDrgtwXwn6HOjtUUfklqH8JEdv0VU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730372748; x=1730977548; h=message-id:date:content-transfer-encoding:mime-version:comments :references:in-reply-to:subject:cc:to:from:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=w5fI+wR+QNtTlzyOy56kkRZIb1b+t2ChizkiHvAl9co=; b=b+8xfmk8d3XxFvEYO6LjFP8W7HKwb7MXvTEf+zRl/1an1ZEO3E8PVcyr207mt4hPvG c80oCqKrVXxwEaXjR1ePYVnXchFT276k65X/rDTdrb0FUNJJcOu+1C9Gzmx0LGLWYBe/ XcwSVBKpPkBNxLnDzImAV5C9zStHXb96xSdWfuOVkBwrI3KRXKPuXqFDNFjjdP0HBATy 4tMlS4HIR7SBBXrJ68qy3uNrC8Z4+i5I5PfJHL5vSNVf5i3I+Xxo2Z5s081WVvx8siuo WUMp0yTfROtUUvuoV1sVXUUJX/+AX8IFVnm1OJpfLxSHrPzlfvJrUrt4dgN9BJQswRWY PX3g== X-Forwarded-Encrypted: i=1; AJvYcCVhXE5SeVLDPD5fPNHsrli3lX0qhzawA/PKTF0rjpicA/GBshStfWSNKiqvlu90M5qVFRP7pSdCMpGLmmjr@postgresql.org X-Gm-Message-State: AOJu0YxCYVXSlE7SBM99ZWnnOEse2qQZM5fKZyAuCIXp3JO5MYpsP9bj 3fYUHyK39zQDtL6VySipIfGNP676nqMg+JZBC28z0tMZ9f4SsKvu9fMDhAeVTMk= X-Google-Smtp-Source: AGHT+IFHu9qarVyJv5aHZnr1J94TP5bFoB4mjtVGgiWcolzwAQTMtswGKMbh3MAp1YiadKZGMlmoyA== X-Received: by 2002:a05:6512:31c3:b0:539:936c:9845 with SMTP id 2adb3069b0e04-53b3491e265mr15765204e87.37.1730372747966; Thu, 31 Oct 2024 04:05:47 -0700 (PDT) Received: from antos (109-81-174-36.rct.o2.cz. [109.81.174.36]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9e564c55ffsm55174666b.59.2024.10.31.04.05.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2024 04:05:47 -0700 (PDT) From: Antonin Houska To: Jacob Champion cc: Daniel Gustafsson , Peter Eisentraut , PostgreSQL Hackers Subject: Re: [PoC] Federated Authn/z with OAUTHBEARER In-reply-to: References: <3603e9bb-9a69-4761-869b-f5b1f204b840@eisentraut.org> <390f9699-6275-4e1e-a600-11452bee0576@eisentraut.org> <67b7e52e-0d6e-4eb5-9318-fdcfa4e7ea51@eisentraut.org> <20A6A78C-D5B1-4BA3-8CD0-99AF18A04B48@yesql.se> <4812.1727459899@antos> <4503.1727703521@antos> <63648.1728384409@antos> <2453.1729230681@antos> Comments: In-reply-to Jacob Champion message dated "Wed, 23 Oct 2024 15:40:57 -0700." X-Mailer: MH-E 8.6+git; nmh 1.8; GNU Emacs 28.3 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 31 Oct 2024 12:05:46 +0100 Message-ID: <4136.1730372746@antos> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Jacob Champion wrote: > On Thu, Oct 17, 2024 at 10:51=E2=80=AFPM Antonin Houska = wrote: > > * oauth_validator_library is defined as PGC_SIGHUP - is that intentiona= l? >=20 > Yes, I think it's going to be important to let DBAs migrate their > authentication modules without a full restart. That probably deserves > more explicit testing, now that you mention it. Is there a specific > concern that you have with that? No concern. I was just trying to imagine when the module needs to be change= d. > > And regardless, the library appears to be loaded by every backend dur= ing > > authentication. Why isn't it loaded by postmaster like libraries list= ed in > > shared_preload_libraries? fork() would then ensure that the backends = do have > > the library in their address space. >=20 > It _can_ be, if you want -- there's nothing that I know of preventing > the validator from also being preloaded with its own _PG_init(), is > there? But I don't think it's a good idea to force that, for the same > reason we want to allow SIGHUP. Loading the library by postmaster does not prevent the backends from reload= ing it on SIGHUP later. I was simply concerned about performance. (I proposed loading the library at another stage of backend initialization rather than adding _PG_init() to it.) > > * pg_fe_run_oauth_flow() > > > > When first time here > > case OAUTH_STEP_TOKEN_REQUEST: > > if (!handle_token_response(actx, &state= ->token)) > > goto error_return; > > > > the user hasn't been prompted yet so ISTM that the first token reques= t must > > always fail. It seems more logical if the prompt is set to the user b= efore > > sending the token request to the server. (Although the user probably = won't > > be that fast to make the first request succeed, so consider this just= a > > hint.) >=20 > That's also intentional -- if the first token response fails for a > reason _other_ than "we're waiting for the user", then we want to > immediately fail hard instead of making them dig out their phone and > go on a two-minute trip, because they're going to come back and find > that it was all for nothing. >=20 > There's a comment immediately below the part you quoted that mentions > this briefly; maybe I should move it up a bit? That's fine, I understand now. > > * As long as I understand, the following comment would make sense: > > > > diff --git a/src/interfaces/libpq/fe-auth-oauth.c b/src/interfaces/libp= q/fe-auth-oauth.c > > index f943a31cc08..97259fb5654 100644 > > --- a/src/interfaces/libpq/fe-auth-oauth.c > > +++ b/src/interfaces/libpq/fe-auth-oauth.c > > @@ -518,6 +518,7 @@ oauth_exchange(void *opaq, bool final, > > switch (state->state) > > { > > case FE_OAUTH_INIT: > > + /* Initial Client Response */ > > Assert(inputlen =3D=3D -1); > > > > if (!derive_discovery_uri(conn)) >=20 > There are multiple "initial client response" cases, though. What > questions are you hoping to clarify with the comment? Maybe we can > find a more direct answer. Easiness of reading is the only "question" here :-) It's might not always be obvious why a variable should have some particular value. In general, the Assert() statements are almost always preceded with a comment in the PG source. > > Or, doesn't the FE_OAUTH_INIT branch of the switch statement actually= fit > > better into oauth_init()? >=20 > oauth_init() is the mechanism initialization for the SASL framework > itself, which is shared with SCRAM. In the current architecture, the > init callback doesn't take the initial client response into > consideration at all. Sure. The FE_OAUTH_INIT branch in oauth_exchange() (FE) also does not gener= ate the initial client response. Based on reading the SCRAM implementation, I concluded that the init() callback can do authentication method specific things, but unlike exchange() it does not generate any output. > Generating the client response is up to the exchange callback -- and > even if we moved the SASL_ASYNC processing elsewhere, I don't think we > can get rid of its added complexity. Something has to signal upwards > that it's time to transfer control to an async engine. And we can't > make the asynchronicity a static attribute of the mechanism itself, > because we can skip the flow if something gives us a cached token. I didn't want to skip the flow. I thought that the init() callback could be made responsible for getting the token, but forgot that it still needs some way to signal to the caller that the async flow is needed. Anyway, are you sure that pg_SASL_continue() can also receive the SASL_ASYNC value from oauth_exchange()? My understanding is that pg_SASL_init() receiv= es it if there is no token, but after that, oauth_exchange() is not called util the token is available, and thus it should not return SASL_ASYNC anymore. --=20 Antonin Houska Web: https://www.cybertec-postgresql.com