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 1oamWj-0001SO-AS for pgsql-hackers@arkaria.postgresql.org; Tue, 20 Sep 2022 23:19:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oamWh-0004JM-5i for pgsql-hackers@arkaria.postgresql.org; Tue, 20 Sep 2022 23:19:39 +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 1oamWg-0004JC-Qj for pgsql-hackers@lists.postgresql.org; Tue, 20 Sep 2022 23:19:38 +0000 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oamWd-0003lg-6L for pgsql-hackers@postgresql.org; Tue, 20 Sep 2022 23:19:37 +0000 Received: by mail-pf1-x42f.google.com with SMTP id a80so4181108pfa.4 for ; Tue, 20 Sep 2022 16:19:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=timescale.com; s=google; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:from:user-agent:mime-version:date:message-id:from:to :cc:subject:date; bh=I1duDxundAh3JGoLuQBp52IMzWe4gJaKe/QfJhszJO0=; b=ImESl34RvNH+ITTaC/R/IjI7cmGi5oZ3XJSla/74sHWhqEdyD3/cJxWueHhlflDCsx BOlwdXw8r94jsrZQGWmM4k8eS802zOXmmurqMQA8wZ8bvdZr0QqRzRYKQ+07wGBbLfzf 8b+GjzcrqfxJBJWJOEqQ/+l/h4waHy1rFi8CKOzThIl44LbRs0Z6EX9xSCoJiFeczxUD Mpx0Pn8IIeOLL2pUlUIfI4k872l8bnomkzwkgyJ/vFj/d1jRrNczjHx8CsPVSUs84oDr XUybyZtyY4jTxiJKHkOCCZ4ucUoKi0OIEPbKa0l3D875Ee+M2tzQKnHoMD1+PkmUm1Pw 5K0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:from:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date; bh=I1duDxundAh3JGoLuQBp52IMzWe4gJaKe/QfJhszJO0=; b=q7O8Q+2bi/VysgzfGgRyz5r3qLuqIwcJv7LE/V1/IyXycV7ZFOuPqKb2ZcrJzC1us1 hf9HnxjhI+SMK8taQDQxgXL8aMK7+Cb8Usni/Gx5On/F9EpORbv3Jq7LhZPSqKOOJywB BBz4NsGHTOKQMqu0cb1RLlytjVOykjNzOoQLQCbbj1EpmbX4KDRQWXHenQme0dWtCR1S jzlY9Cu3AOabia3wFAmfz/ab5NyzCT2WisgyYOmRLxjPzDxruSfoPO/WYUwhBEKVk4X8 NtHZqckjJDUaDqeiWmd/1br48dbEWRHkAAMgy3vqcIMqoAXV1YH1Z8IN8fXmfwPVODij TL0Q== X-Gm-Message-State: ACrzQf09QrVShUHrnpxt7cEhhbB7SRSPlCXcDvdPdEnAnt+WKnbUjVC1 ObxYijKhWA6/KOO2DM35G6a/dw== X-Google-Smtp-Source: AMsMyM5GbkxKYniFV9mAyxvQMgHUlq483squgivfARp394K7MifCJ0bmIiamcvukYbrRaTfScC8NOw== X-Received: by 2002:a63:1508:0:b0:438:eb90:52d1 with SMTP id v8-20020a631508000000b00438eb9052d1mr22762086pgl.252.1663715973615; Tue, 20 Sep 2022 16:19:33 -0700 (PDT) Received: from [192.168.1.21] ([50.39.205.221]) by smtp.gmail.com with ESMTPSA id y3-20020aa793c3000000b005383988ec0fsm458622pff.162.2022.09.20.16.19.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 20 Sep 2022 16:19:32 -0700 (PDT) Message-ID: Date: Tue, 20 Sep 2022 16:19:31 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 From: Jacob Champion Subject: Re: [PoC] Federated Authn/z with OAUTHBEARER To: mahendrakar s Cc: "pgsql-hackers@postgresql.org" , "smilingsamay@gmail.com" , "andres@anarazel.de" , anchudno@microsoft.com, mahendrakars@microsoft.com References: <2f06a4aef1d5defe4b7aaec01478572e5557d32a.camel@vmware.com> <8a5a35b31c3f25f6b047e77def0445a60399981d.camel@vmware.com> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Mahendrakar, thanks for your interest and for the patch! On Mon, Sep 19, 2022 at 10:03 PM mahendrakar s wrote: > The changes for each component are summarized below. > > 1. Provider-specific extension: > Each OAuth provider implements their own token validator as an > extension. Extension registers an OAuth provider hook which is matched > to a line in the HBA file. How easy is it to write a Bearer validator using C? My limited understanding was that most providers were publishing libraries in higher-level languages. Along those lines, sample validators will need to be provided, both to help in review and to get the pytest suite green again. (And coverage for the new code is important, too.) > 2. Add support to pass on the OAuth bearer token. In this > obtaining the bearer token is left to 3rd party application or user. > > ./psql -U -d 'dbname=postgres > oauth_client_id= oauth_bearer_token= This hurts, but I think people are definitely going to ask for it, given the frightening practice of copy-pasting these (incredibly sensitive secret) tokens all over the place... Ideally I'd like to implement sender constraints for the Bearer token, to *prevent* copy-pasting (or, you know, outright theft). But I'm not sure that sender constraints are well-implemented yet for the major providers. > 3. HBA: An additional param ‘provider’ is added for the oauth method. > Defining "oauth" as method + passing provider, issuer endpoint > and expected audience > > * * * * oauth provider= > issuer=.... scope=.... Naming aside (this conflicts with Samay's previous proposal, I think), I have concerns about the implementation. There's this code: > + if (oauth_provider && oauth_provider->name) > + { > + ereport(ERROR, > + (errmsg("OAuth provider \"%s\" is already loaded.", > + oauth_provider->name))); > + } which appears to prevent loading more than one global provider. But there's also code that deals with a provider list? (Again, it'd help to have test code covering the new stuff.) > b) libpq optionally compiled for the clients which > explicitly need libpq to orchestrate OAuth communication with the > issuer (it depends heavily on 3rd party library iddawc as Jacob > already pointed out. The library seems to be supporting all the OAuth > flows.) Speaking of iddawc, I don't think it's a dependency we should choose to rely on. For all the code that it has, it doesn't seem to provide compatibility with several real-world providers. Google, for one, chose not to follow the IETF spec it helped author, and iddawc doesn't support its flavor of Device Authorization. At another point, I think iddawc tried to decode Azure's Bearer tokens, which is incorrect... I haven't been able to check if those problems have been fixed in a recent version, but if we're going to tie ourselves to a huge dependency, I'd at least like to believe that said dependency is battle-tested and solid, and personally I don't feel like iddawc is. > - auth_method = I_TOKEN_AUTH_METHOD_NONE; > - if (conn->oauth_client_secret && *conn->oauth_client_secret) > - auth_method = I_TOKEN_AUTH_METHOD_SECRET_BASIC; This code got moved, but I'm not sure why? It doesn't appear to have made a change to the logic. > + if (conn->oauth_client_secret && *conn->oauth_client_secret) > + { > + session_response_type = I_RESPONSE_TYPE_CLIENT_CREDENTIALS; > + } Is this an Azure-specific requirement? Ideally a public client (which psql is) shouldn't have to provide a secret to begin with, if I understand that bit of the protocol correctly. I think Google also required provider-specific changes in this part of the code, and unfortunately I don't think they looked the same as yours. We'll have to figure all that out... Standards are great; everyone has one of their own. :) Thanks, --Jacob