Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vp4Bv-0006ZL-G0 for pgsql-jdbc@arkaria.postgresql.org; Fri, 06 Dec 2013 22:48:11 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Vp4Bu-0000kv-Pp for pgsql-jdbc@arkaria.postgresql.org; Fri, 06 Dec 2013 22:48:10 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vp4Bu-0000ka-2S for pgsql-jdbc@postgresql.org; Fri, 06 Dec 2013 22:48:10 +0000 Received: from smtp2.stanford.edu ([171.67.219.82] helo=smtp.stanford.edu) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vp4Bp-0000VV-6z for pgsql-jdbc@postgresql.org; Fri, 06 Dec 2013 22:48:07 +0000 Received: from smtp.stanford.edu (localhost [127.0.0.1]) by localhost (Postfix) with SMTP id C3F9F340DD3 for ; Fri, 6 Dec 2013 14:48:03 -0800 (PST) Received: from sr13-cc613b7de2.stanford.edu (sr13-cc613b7de2.Stanford.EDU [171.64.19.137]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: pradtke) by smtp.stanford.edu (Postfix) with ESMTPSA id 5852C340AD7 for ; Fri, 6 Dec 2013 14:48:03 -0800 (PST) Message-ID: <52A25425.8040908@stanford.edu> Date: Fri, 06 Dec 2013 14:48:05 -0800 From: Patrick Radtke User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.1.1 MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org Subject: Service principal, GSSAPI and JDBC connection issue Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.5 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org Hi, I'm using PostgreSQL 9.1 and I have configured GSSAPI authentication for my client application. The client application has this principal: service/uaa-authz-uat01@stanford.edu and I have it mapped to the DB role/user uaa pg_ident.conf # MAPNAME SYSTEM-USERNAME PG-USERNAME krb5 service/uaa-authz-uat01 uaa Connecting works fine with psql. I use k5start to get the appropriate tickets and then connect k5start -qUf /etc/oauth/keytab -- psql -h authz-uat01 -U uaa However, when I try connecting with the JDBC driver I run into trouble. I've configured my JAAS config pgjdbc { com.sun.security.auth.module.Krb5LoginModule required principal="service/uaa-authz-uat01" useKeyTab=true keyTab="/etc/oauth/keytab" doNotPrompt=true useTicketCache=true storeKey=true debug=true renewTGT=true; }; and my JDBC connection with these properties database: driverClassName: org.postgresql.Driver url: jdbc:postgresql://authz-uat01.stanford.edu/uaa?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory username: uaa however when I go to connect I get the error "No valid credentials provided (Mechanism level: Failed to find any Kerberos tgt)" which is odd because in the JAAS debug output it seems to be able to create a tgt based on the keytab just fine. Reviewing the code in 'MakeGSS.java' I see the problem. GSSName clientName = manager.createName(user, GSSName.NT_USER_NAME); GSSCredential clientCreds = manager.createCredential(clientName, 8*3600, desiredMechs, GSSCredential.INITIATE_ONLY); The driver assumes that the client is a 'GSSName.NT_USER_NAME' which is "Name type to indicate a named user on a local system.". It passes in 'uaa' (the username) to createName(), and then the next call to createCredential() fails since the tgt is for 'service/uaa-authz-uat01' and its looking for one that matches 'uaa'. Setting the db username to 'service/uaa-authz-uat01' gets by the GSSAPI issues, but then fails because I don't have (nor wish to have) a postgres user with the same name. Deleting those two lines, and changing the manager.createContext() call to GSSContext secContext = manager.createContext(serverName, desiredMechs[0], null, GSSContext.DEFAULT_LIFETIME); e.g. using a null for the 3rd argument makes the driver work fine. The javadoc for manager.createContext() says "Use null to act as the default initiator principal.". So... does that mean the two lines related clientCreds/Name aren't needed at all? If they are needed for some scenarios, how can the code be modified to handle both use cases? thanks, Patrick -- Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc