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.96) (envelope-from ) id 1vvIVF-00CXLH-20 for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Feb 2026 17:16:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vvIVE-007ka8-1t for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Feb 2026 17:16:48 +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.96) (envelope-from ) id 1vvIVE-007ka0-0h for pgsql-hackers@lists.postgresql.org; Wed, 25 Feb 2026 17:16:48 +0000 Received: from mail-yw1-x1135.google.com ([2607:f8b0:4864:20::1135]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vvIVA-00000001Fjz-1z0A for pgsql-hackers@postgresql.org; Wed, 25 Feb 2026 17:16:47 +0000 Received: by mail-yw1-x1135.google.com with SMTP id 00721157ae682-79801df3e21so69452337b3.2 for ; Wed, 25 Feb 2026 09:16:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1772039803; cv=none; d=google.com; s=arc-20240605; b=QKD680sI7MKqCFN6LpFp/TBK4wAKr4BWOrpJRefdFflLaoNdY5+sR6Au2c8mKw89KF Y/r3253djbB6sVrkFDcgcD4/9eYnMfPU1aDYc+6wYOOwbSvSpXur/XR5KGjM1bkhbZiw 6mqNfeBFEQKsNLgt5bkAdpIlbadeaolcWUPcA7yZnGmUGvsQ57BIGYZSpqPWldg5zACo SabQM33sL6UpkAKZcZj5RZUKRb4ZsiB4iJKyaxC5kZ58VZwfbHmR47DdqZXzuxgum2ta e/q/DdgJLdrZdz9XLkopfWoHnwdj2/mq3UzZtPtSDs283z3cb3tX9yKjPE8cLtw5Y/DV LNcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=7WLKc/pUwRB4WnYTDb/LslQhBynpfV+RichvDaYRca4=; fh=Nw64H9N69w52pCIo08CfTLELAn0SlP65TqydhNJLFIo=; b=HdiFI27mrHRhtaNBaTiaTgia/TCd2hfE3ZSFV4+JOR7c5zGXkP9GCnRGZjDrYXnNEu GYcA2ifNPp0TOSicKyFqFS085yCleRsg0JZQ6RtYJtRetQoMbXgoRCsKUJarE6MN+at7 at1PfvFJCYPixkQ+6J08yDIayPdPh9tc6QbhANlpaT/FnEe9hRXwkTEweYvrnV/dyGLQ GV7QilYzkP6P41VxbO2vTrurAW8q+BVNCFXHHEgJBXNjw4HOqg5jstWWbe/kVn/kGgdj 2Q+iwb8shfNP07RLUygg2QWlVBagi71oCbaWkKTw0tgqNVQ6ygYZEjJkhl1qTfRTcDgx TmYg==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=percona.com; s=google; t=1772039803; x=1772644603; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=7WLKc/pUwRB4WnYTDb/LslQhBynpfV+RichvDaYRca4=; b=WlkHCCTWeApaqFGmV9TWtJsWn9oG0JMI+ajfHdt0U/XoAeWeztEi33dr1Wb3PLYfJT hIcXKh1hYidNnvi2MoP9oBYBUbz7mWMgOkmVFOQIWSMRRNnPxpeYbWmsmhUw6CFmmUNs nsKRIeawqIKoGoj6NHLPLrA4VaYT6bP/H6rV8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772039803; x=1772644603; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=7WLKc/pUwRB4WnYTDb/LslQhBynpfV+RichvDaYRca4=; b=OUtV/BzLp7jEw83n3d/OGiYtNKkRDgHDT8fAzjoXUlVUrrkg2XiFkhZTpzM4L5XYf5 6dnaZNoch2BzwZHhJabUTOw8mzcE3tWaslJy3Pk5zXbWSmnf+teDaonRLQzm2PjEeouB lxigz4sSJqpTxPCYv7DOjG7KEg1AeP4Yg+aOuEnGWRp4gof0nczCYKJ6WrNTCvC7nOwu OkJcdUSDFrlncZV8pHzull8jkKkpgoxfOuFxiARmMm3UvYKNYYRlFUHn4PNXSv0fdnBW kRX0tP0bkVYlvceOKspwsYeOwFufuwgt0h7j5K2dY0ySBpchPAWPAOIKakpmFBHj+xBU WrJA== X-Gm-Message-State: AOJu0YxtJmZu4NN2fcpfdX/bW6ZgsYBT2Zxi0VifMR3V4Z6JB6lJ0p1y rmsN98oC9tMVq3YttK5kC+OJNR6xlJmgZtNRB130BwvCIBsaaP0c2WkQrnKfjfIwD9kD2Aj3FyF KelcmsAsig9Tj5Z02za0+UdAMTMgrYg52WuDDreG8aLBXN8ctBYSOd12ImjT28bamde8fSbC/uH X8q4IKeLiz95IFy41CUa0NsX3ZJFdMHiFdtLqm+AMmxy4WmOZcf8ubKYAx2COTDp/ElO1cC1TxT BWIGn2Xm9ZMKI+yM3jdarCet8CkyZkyZWucEzM/3zchjBnqhcs= X-Gm-Gg: ATEYQzwBfGvS2PrqG3qZ2jBzh46lXNJUnEaqkHHPvodKFJCiFWc3IZcmuA0ipR37wzE ruj71wuUnHgfRjl6aDOkplCd2sMhDltpKiLXJ3tRFaDJ8YmwLDkcfnOfnjcg6itfx0ZdjK7mzp0 h1RDuUuBDaYpLgPoH6EDG80+jypj+68DFn1EwXGEoMSBGqmGe7dZrjW0dNO2FZzE61xgEbL+Q0Q n5RQVx8CN9YjcSPPQBtmDH59KtBgDRdsG606DfyF26ZRjBhC9S2VWrIrRDLlvd1efEfAae8hSOA ppIfMSuin7ZmvBZduf9aHyLqoMuv6+F9ftECQ4ahwm+q5l1bmM1YlbYQxGt97ZCGYl/v X-Received: by 2002:a05:690c:385:b0:796:2dfb:4af0 with SMTP id 00721157ae682-7986fc4af2dmr11416787b3.10.1772039802762; Wed, 25 Feb 2026 09:16:42 -0800 (PST) MIME-Version: 1.0 References: <3720B2E1-0B96-4063-8D63-B5AE6AFEA159@gmail.com> In-Reply-To: From: Zsolt Parragi Date: Wed, 25 Feb 2026 17:16:33 +0000 X-Gm-Features: AaiRm51RmrjGMoTA4a9ZcRprZzP2aSEYCKp9B5XPBOykWfwR8qgkBKPlSmTiYK8 Message-ID: Subject: Re: [oauth] Stabilize the libpq-oauth ABI (and allow alternative implementations?) To: Jacob Champion Cc: PostgreSQL Hackers , Chao Li Content-Type: text/plain; charset="UTF-8" X-CLOUD-SEC-AV-Sent: true X-CLOUD-SEC-AV-Info: percona,google_mail,monitor X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk + * TODO: have to think about _all_ the security ramifications of this. What + * existing protections in LD_LIBRARY_PATH (and/or SIP) are we potentially + * bypassing? Should we check the permissions of the file somehow...? + * TODO: maybe disallow anything not underneath LIBDIR? or PKGLIBDIR? + * Should it have a naming convention? + */ + const char *env = getenv("PGOAUTHMODULE"); and > That's exactly the use case. (Also, library clients of postgres that > should not install application hooks, other monolithic utilities that > link against libpq, etc.) Who wants to recompile their clients just to > switch how they get a token? How would this work with library clients exactly (and even multiple library clients)? * Language bindings: there's already ongoing work on adding support for the hooks into these libraries, so that's not really a use case (and: 1. there's no recompilation cost for many of them 2. even if there is, you can't easily use the same language for these plugins, which is again a downside). And some bindings don't use libpq at all. * postgres CLI tools: That's one use case, but it could work without generic user-facing plugin support, limited to these tools. * postgres_fwd/dblink and similar: I'm not sure how that would work, what if different extensions require different plugins? This already seems like a tricky question with the hooks And from a configuration/security risk point: * Restricting to system paths could work, but it limits who and how can add these plugins, and removes the possibility of modifying a specific application without system permissions. I can't just download a binary application, and a separate oauth plugin, and use them together, I need admin permission - that seems strange to me. (Unless I compile libpq myself in a different prefix?) * On the other hand requiring applications to specify allowed paths or plugins directly, without environment variables goes back to the previous configuration question > What existing protections in LD_LIBRARY_PATH (and/or SIP) are we potentially bypassing? From the ld.so.8 manpage: > In secure-execution mode, preload pathnames containing slashes are ignored. Furthermore, shared objects are preloaded only from the standard search directories and only if they have set-user-ID mode bit enabled (which is not typical). An easy solution could be using secure_getenv instead of getenv, which would at least improve the situation? And a few specific comments about the patches: +oom: + request->error = libpq_gettext("out of memory"); + return -1; Shouldn't this also free conninfo if it is allocated? +/* Features added in PostgreSQL v19: */ +/* Indicates presence of PQgetThreadLock */ +#define LIBPQ_HAS_GET_THREAD_LOCK Should this be defined to 1? + /* + * We need to inject necessary function pointers into the module. This + * only needs to be done once -- even if the pointers are constant, + * assigning them while another thread is executing the flows feels + * like tempting fate. + */ + if ((lockerr = pthread_mutex_lock(&init_mutex)) != 0) + { + /* Should not happen... but don't continue if it does. */ + Assert(false); - libpq_append_conn_error(conn, "failed to lock mutex (%d)", lockerr); - return 0; - } + libpq_append_conn_error(conn, "failed to lock mutex (%d)", lockerr); + return 0; + } Shouldn't this path return -1, and also dlclose the library? + + dlclose(state->flow_module); + Shouldn't dlcloses also reset state->flow_module after? -free_async_ctx(PGconn *conn, struct async_ctx *actx) +free_async_ctx(PGoauthBearerRequestV2 *req, struct async_ctx *actx) req (or conn) doesn't seem to be used in this function, does it need that parameter? + env = strchr(env, '\x01'); + *env++ = '\0'; Isn't mutating environment variables UB?