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 1p3RSD-00009b-Sb for pgsql-hackers@arkaria.postgresql.org; Fri, 09 Dec 2022 00:41:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p3RSC-0001GQ-FY for pgsql-hackers@arkaria.postgresql.org; Fri, 09 Dec 2022 00:41:28 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p3RSC-0001GH-3X for pgsql-hackers@lists.postgresql.org; Fri, 09 Dec 2022 00:41:28 +0000 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1p3RS9-0007KE-Fy for pgsql-hackers@postgresql.org; Fri, 09 Dec 2022 00:41:27 +0000 Received: by mail-pg1-x533.google.com with SMTP id q1so2486191pgl.11 for ; Thu, 08 Dec 2022 16:41:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=timescale.com; s=google; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=gu3TOOhrc0f45n4zoqlBPnB8jrPMNJKPkTxPwCKLgJU=; b=lv8iAVPGg0hN4IWKJqfxUMldxfs2Kc6dc0p2cURlAlGvxFHlr/tJ7BMQAdc2LMIUug F7be/NA/n6rtheLqkEEW5d9mIBY1XWbUhk01gVll+BM5D9ikbKXaT6sAy+RnZKpxiyCb 5XWqGVBAe8vxxkkU3K4mfMwZI9wDROPENcN7cbYlYNHUCnbMoSZdvK3z3XISYfaCCdka vokQb1cXd//7tLqOs8W5XcIkD8oFrqHwptEna2xQtM7IWpzPkqVz7sTlswW5HVKgigf6 RtLdgXZoVNFbgHYd9f75FooIt7pxj7imFYmNhBr01dY5VSe97kwMcGucmcl0cFboboGr 1fAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=gu3TOOhrc0f45n4zoqlBPnB8jrPMNJKPkTxPwCKLgJU=; b=JfLYlC6nruD0g7H5APpNhEK58bYIu8sl8MhH5qdJOdIz5OpR1WrqU56H8o0c6H8VyR 64YYL95nWxiVx8XJ8D+1zz5ENbLQWWV+fxtsklPJ9nrDC9w6yPAyaMvYxqNZXPdBU4Ii UBZdAYx0ceNAZG3HVocaWn66jqH9FbWYwfsnEpTHZsOu8WC/39uqueDQKsVsucBjMgaK aV56fxP3ZrKxQ/NneuAC8XBNgNYAasMIyB069aj2gB3Qu9ZQCpifiArQjVJM1bsMaKYo 9bXnX5sKr2r9Fie49JrYaGt7+pSXCC+o43kqr4emAhUWst6dbo6lFQek3XR1ynxN3q0V Cz8Q== X-Gm-Message-State: ANoB5pk2YZkMq7rkcaK28bO5I/MD//Ih2YOPVU0V4Wqh675PUZYfsNSK A58l5gQCFEtrnAxIjlSlqp4x+Q== X-Google-Smtp-Source: AA0mqf63eJII3MR0gpjcXffxg9oaFLIz9NO5I05c7NEGVtv4pgqPQgD/EsCNFo4SqIHNVVHI5vDyLw== X-Received: by 2002:aa7:83d7:0:b0:56c:cde:1a44 with SMTP id j23-20020aa783d7000000b0056c0cde1a44mr3134538pfn.11.1670546483098; Thu, 08 Dec 2022 16:41:23 -0800 (PST) Received: from [192.168.1.21] ([50.53.8.205]) by smtp.gmail.com with ESMTPSA id y5-20020aa793c5000000b005765a5ff1fasm73463pff.213.2022.12.08.16.41.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 08 Dec 2022 16:41:22 -0800 (PST) Message-ID: <705e7eb8-29ee-a707-5a67-d2acfb2f3fad@timescale.com> Date: Thu, 8 Dec 2022 16:41:21 -0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PoC] Federated Authn/z with OAUTHBEARER Content-Language: en-US To: Andrey Chudnovsky Cc: mahendrakar s , "hlinnaka@iki.fi" , "michael@paquier.xyz" , "pgsql-hackers@postgresql.org" , "smilingsamay@gmail.com" References: From: Jacob Champion In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Dec 7, 2022 at 3:22 PM Andrey Chudnovsky wrote: > >> I think it's okay to have the extension and HBA collaborate to >> provide discovery information. Your proposal goes further than >> that, though, and makes the server aware of the chosen client flow. >> That appears to be an architectural violation: why does an OAuth >> resource server need to know the client flow at all? > > Ok. It may have left there from intermediate iterations. We did > consider making extension drive the flow for specific grant_type, > but decided against that idea. For the same reason you point to. Is > it correct that your main concern about use of grant_type was that > it's propagated to the server? Then yes, we will remove sending it > to the server. Okay. Yes, that was my primary concern. >> Ideally, yes, but that only works if all identity providers >> implement the same flows in compatible ways. We're already seeing >> instances where that's not the case and we'll necessarily have to >> deal with that up front. > > Yes, based on our analysis OIDC spec is detailed enough, that > providers implementing that one, can be supported with generic code > in libpq / client. Github specifically won't fit there though. > Microsoft Azure AD, Google, Okta (including Auth0) will. > Theoretically discovery documents can be returned from the extension > (server-side) which is provider specific. Though we didn't plan to > prioritize that. As another example, Google's device authorization grant is incompatible with the spec (which they co-authored). I want to say I had problems with Azure AD not following that spec either, but I don't remember exactly what they were. I wouldn't be surprised to find more tiny departures once we get deeper into implementation. >> That seems to be restating the goal of OAuth and OIDC. Can you >> explain how the incompatible change allows you to accomplish this >> better than standard implementations? > > Do you refer to passing grant_type to the server? Which we will get > rid of in the next iteration. Or other incompatible changes as well? Just the grant type, yeah. >> Why? I claim that standard OAUTHBEARER can handle all of that. >> What does your proposed architecture (the third diagram) enable >> that my proposed hook (the second diagram) doesn't? > > The hook proposed on the 2nd diagram effectively delegates all Oauth > flows implementations to the client. We propose libpq takes care of > pulling OpenId discovery and coordination. Which is effectively > Diagram 1 + more flows + server hook providing root url/audience. > > Created the diagrams with all components for 3 flows: [snip] (I'll skip ahead to your later mail on this.) >> (For a future conversation: they need to set up authorization, >> too, with custom scopes or some other magic. It's not enough to >> check who the token belongs to; even if Postgres is just using the >> verified email from OpenID as an authenticator, you have to also >> know that the user authorized the token -- and therefore the client >> -- to access Postgres on their behalf.) > > My understanding is that metadata in the tokens is provider > specific, so server side hook would be the right place to handle > that. Plus I can envision for some providers it can make sense to > make a remote call to pull some information. The server hook is the right place to check the scopes, yes, but I think the DBA should be able to specify what those scopes are to begin with. The provider of the extension shouldn't be expected by the architecture to hardcode those decisions, even if Azure AD chooses to short-circuit that choice and provide magic instead. On 12/7/22 20:25, Andrey Chudnovsky wrote: > That being said, the Diagram 2 would look like this with our proposal: > [snip] > > With the application taking care of all Token acquisition logic. While > the server-side hook is participating in the pre-authentication reply. > > That is definitely a required scenario for the long term and the > easiest to implement in the client core.> And if we can do at least that flow in PG16 it will be a strong > foundation to provide more support for specific grants in libpq going > forward. Agreed. > Does the diagram above look good to you? We can then start cleaning up > the patch to get that in first. I maintain that the hook doesn't need to hand back artifacts to the client for a second PQconnect call. It can just use those artifacts to obtain the access token and hand that right back to libpq. (I think any requirement that clients be rewritten to call PQconnect twice will probably be a sticking point for adoption of an OAuth patch.) That said, now that your proposal is also compatible with OAUTHBEARER, I can pony up some code to hopefully prove my point. (I don't know if I'll be able to do that by the holidays though.) Thanks! --Jacob