Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1X4i12-0000pL-2a for pgsql-odbc@arkaria.postgresql.org; Wed, 09 Jul 2014 02:53:52 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1X4i10-0003lb-Mb for pgsql-odbc@arkaria.postgresql.org; Wed, 09 Jul 2014 02:53:50 +0000 Received: from makus.postgresql.org ([174.143.35.229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1X4i10-0003lL-3j for pgsql-odbc@postgresql.org; Wed, 09 Jul 2014 02:53:50 +0000 Received: from mout.kundenserver.de ([212.227.17.10]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1X4i0w-00027x-Nw for pgsql-odbc@postgresql.org; Wed, 09 Jul 2014 02:53:48 +0000 Received: from ayaki.localdomain (58-7-82-8.dyn.iinet.net.au [58.7.82.8]) by mrelayeu.kundenserver.de (node=mreue101) with ESMTP (Nemesis) id 0LfAVs-1WFwqc3YHg-00onLr; Wed, 09 Jul 2014 04:53:44 +0200 Message-ID: <53BCAEB0.8070500@2ndquadrant.com> Date: Wed, 09 Jul 2014 10:53:36 +0800 From: Craig Ringer Organization: 2nd Quadrant User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 To: "pgsql-odbc@postgresql.org" Subject: Impossible to use MSDTC/XA with SSPI X-Enigmail-Version: 1.6 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:JkkBTi7HjgZ9oKdq0m3+rs/IW9xpvgPpHttzZSE4X4/ bRKGvha0OylNmt1Hxe8spSTEfXR55DEs8eOt6j7vXEqKAj3qTv k4/RH7I8i3LlVFHdhEsH5Owx8OpIi6te34cX26M+pS8MCiJIyG /jVIXkBNe1YSnTJ+lYaauCOj05H5vg7vE6H4KE3qv5KjBmL7jb QGU8ZZy9vNUi+0q3A6VkjjbSbG+7qpFdp36y/CGMMeJEXQCke2 2PVc+xsF5Gm/Rr4a1M9KF4Q9j4TNUgQYHUl/1eUWbNeZ1f88v2 HgtC0oJQUB7Qyajy9JkB9IBXjjpIfd3YpRwwxgFT83seMUVl6U mGFX27dMPdj2v0zuttHJiU9CpZfgVE19Sl+F9dV4i X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-odbc Precedence: bulk Sender: pgsql-odbc-owner@postgresql.org (Sent from the wrong account earlier, please disregard if you see another copy) Hi all It doesn't seem to be possible to use MSDTC XA transactions alongside SSPI authentication. psqlODBC's MSDTC support assumes that the DSN supplied by the user is also valid for a connection from MSDTC.exe via pgxalib.dll for XA recovery. We've already seen one case where that's not a valid assumption - where the 32-bit and 64-bit driver names differ when using 32-bit psqlODBC under SysWow64 on 64-bit Windows. This is another case. SSPI for TCP is like "peer" for unix socket connections on UNIX, except that it uses an in-band handshake protocol rather than out-of-band syscalls. It verifies that the connecting user is running as same operating system user as the PostgreSQL username they've requested (or is allowed to connect as that Pg user by the user mappings). So what happens is: - psqlODBC connects as the user - User starts distributed tx manager, binds connection(s) to MSDTC - User starts distributed tx; psqlODBC starts tx's on each session and saves the user's DSN in the DTC transaction context. - User does work on each session - User asks DTC to commit tx; psqlODBC does a PREPARE TRANSACTION on each session - DTC tells user tx has committed successfully - DTC asks psqlODBC to COMMIT PREPARED on each tx If the app exits after MSDTC tells it the tx committed (which it might - MSDTC doesn't offer synchronous 2-phase commit, it can only wait for the first phase to complete) or the server crashes, etc, there are left-over prepared transactions. pgxalib.dll's job is to recover those. To do that it has to connect to PostgreSQL. It's loaded within MSDTC.exe, where it establishes a psqlODBC connection using the DSN it saved in the distributed transaction context earlier. This works only if the DSN is valid. The 32-bit to 64-bit mismatch was one case of this being a problem earlier. SSPI is another - when MSDTC.exe tries to connect to PostgreSQL it does so under Windows user NETWORKSERVICE, which won't match the username the original user connected to PostgreSQL as. So PostgreSQL will reject the connection. I'm not sure how to solve this. "Use libpq" isn't an answer here, it still wouldn't give us any way to acquire creds that'd permit connecting safely. Stashing creds in the Registry or a file would work, but would require a .pgpass-like setup with matching for hostname/port/etc, since MSDTC might be co-ordinating transactions for multiple Pg servers on multiple machines. It'd also mean that MSDTC XA support for Pg would require configuration, which it never has before. Anything else running as NETWORKSERVICE could then steal these creds. Because you can only COMMIT PREPARED a tx that you created unless you're superuser, they'd have to be superuser creds too. Trusting NETWORKSERVICE to SSPI-authenticate as anybody seems pretty horrible - if Pg even has wildcard user mapping for SSPI that'll work for this, I haven't checked yet. Anything could be running as NETWORKSERVICE. The only thing I can think of that seems secure in the face of other things running as NETWORKSERVICE is to have a special cookie stored in the DTC transaction context that PostgreSQL accepts as a one-time password for a connection that can *only* commit or rollback that particular prepared transaction. That'd require some pretty significant changes to Pg core, so it's hardly a lightweight option. Ideas? -- Craig Ringer http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services -- Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-odbc