Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gzpH9-0000nP-04 for pgsql-general@arkaria.postgresql.org; Fri, 01 Mar 2019 21:00:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gzpH6-0005uS-Mz for pgsql-general@arkaria.postgresql.org; Fri, 01 Mar 2019 21:00:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gzpH6-0005rt-BZ for pgsql-general@lists.postgresql.org; Fri, 01 Mar 2019 21:00:56 +0000 Received: from tamriel.snowman.net ([2001:470:e38f::11]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gzpH2-000766-PF for pgsql-general@lists.postgresql.org; Fri, 01 Mar 2019 21:00:55 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id B187E5F7A0; Fri, 1 Mar 2019 16:00:50 -0500 (EST) Date: Fri, 1 Mar 2019 16:00:50 -0500 From: Stephen Frost To: Jean-Philippe Chenel Cc: Andre Piwoni , "pgsql-general@lists.postgresql.org" Subject: Re: PostgreSQL (linux) configuration with GSSAPI to a Windows domain Message-ID: <20190301210050.GJ6197@tamriel.snowman.net> References: <4182C0C4-7555-415A-992D-3141AAA9176D@LIVE.CA> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="QQOJ7tcb1Icu6LtL" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --QQOJ7tcb1Icu6LtL Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Greetings, * Jean-Philippe Chenel (jp.chenel@live.ca) wrote: > Thank you very much for your help. > I think I was missing an important command in the equation. >=20 > sudo realm --verbose join ad.corp.com --user=3DAdministrateur --user-pr= incipal=3Dpostgres/UBUNTU.ad.corp.com@AD.CORP.COM >=20 > The Linux server as joint the AD and now, psql connection work very well = =66rom the clients! Great! Glad to hear you got that working. > It makes a lot of things that I'm not accustomed too, but was very intere= sting. I'll also look forward to the other authentication method that you'v= e talked (PAM). I'm not sure what the discussion around PAM was getting to, though it seemed like it was talking about using PAM at the Linux OS level to allow access, which could be fine. I will say that using PAM in PostgreSQL for authentication would be worse from a security standpoint than using GSS since with PAM a password would be sent from the client to the PG server and would be visible to the PG server. Thanks! Stephen > ________________________________ > De : Andre Piwoni > Envoy=E9 : 1 mars 2019 11:44 > =C0 : Jean-Philippe Chenel > Cc : pgsql-general@lists.postgresql.org > Objet : Re: PostgreSQL (linux) configuration with GSSAPI to a Windows dom= ain >=20 > Hi Philippe, >=20 > I would increase logging level to debug since it is hard to tell from log= what is happening. > Have you verified kinit for the user on the server? Sounds like you did s= ince you are running client on the server > Also, my username in postgres database is lowercase without realm info. >=20 > At the high level, here's the setup I had: >=20 > 1. Create AD user account for PostgreSQL UNIX service. > 2. Set up identity mapping for Service Principal Name (SPN) to postgre= s user account. > Note: Multiple service instances cannot map to the same user account, so = user account may be created as postgres_shortHostName > 3. Generate keytab for postgres service principal. > 4. Ensure Kerberos configuration file has been created on PostgreSQL s= erver after joining server to AD domain using SSSD and realmd utility. > 5. Configure PostgreSQL to use generated keytab file. > 6. Configure PostgreSQL host-base authentication to use GSSAPI. >=20 > My setup for PAM is using SSSD PAM module and is configured for AD: >=20 > cat /etc/pam.d/postgresql > #%PAM-1.0 > auth required pam_sss.so > account required pam_sss.so >=20 > By joining domain using realm sssd you should have krb5.conf and sssd.con= f generated for you automatically. You should remove existing krb5.conf bef= ore joining domain. >=20 >=20 > cat /etc/sssd/sssd.conf > [sssd] > domains =3D ad.corp.com > config_file_version =3D 2 > services =3D nss, pam >=20 > [domain/ ad.corp.com] > ad_domain =3D ad.corp.com > krb5_realm =3D AD.CORP.COM > realmd_tags =3D manages-system joined-with-samba > cache_credentials =3D True > id_provider =3D ad > krb5_store_password_if_offline =3D True > default_shell =3D /bin/bash > ldap_id_mapping =3D True > use_fully_qualified_names =3D False > fallback_homedir =3D /home/%u > access_provider =3D ad >=20 > On Fri, Mar 1, 2019 at 7:59 AM Jean-Philippe Chenel > wrote: > Hi Andre, > Thank for the followup. Here are the tests and results: >=20 > I've deleted and created service user postgres in lower case on the AD, a= nd I've made this command. > ktpass -out postgres.keytab -princ postgres/UBUNTU.ad.corp.com@AD.CORP.CO= M -mapUser AD\postgres -pass 'postgr= es' -mapOp add -crypto ALL -ptype KRB5_NT_PRINCIPAL >=20 > Changed pg_hba.conf to > host all all 0.0.0.0/0 gss gss include_realm=3D0 [http:= //krb_realm%3Dad.corp.com/]krb_realm=3DAD.CORP.COM >=20 > kinit is working > kinit ubuntupg(at)AD(dot)CORP(dot)COM >=20 > Ticket cache: FILE:/tmp/krb5cc_0 > Default principal: ubuntupg@AD.CORP.COM >=20 > Valid starting Expires Service principal > 2019-03-01 10:21:50 2019-03-01 20:21:50 krbtgt/AD.CORP.COM@AD.CORP.COM<= mailto:AD.CORP.COM@AD.CORP.COM> > renew until 2019-03-08 10:21:43 >=20 > Here are the bad: > root@UBUNTU:~# psql -h 192.168.20.143 -U ubuntupg > psql: erreur de suite GSSAPI: Unspecified GSS failure. Minor code may pr= ovide more information > erreur de suite GSSAPI: No Kerberos credentials available >=20 > Postgresql log > 2019-03-01 09:59:13.890 EST [8913] postgres@postgres LOG: 00000: connect= ion authorized: user=3Dpostgres database=3Dpostgres > 2019-03-01 09:59:13.890 EST [8913] postgres@postgres LOCATION: PerformAu= thentication, postinit.c:272 > 2019-03-01 09:59:18.992 EST [8942] [unknown]@[unknown] LOG: 00000: conne= ction received: host=3D192.168.20.143 port=3D40024 > 2019-03-01 09:59:18.992 EST [8942] [unknown]@[unknown] LOCATION: Backend= Initialize, postmaster.c:4188 > 2019-03-01 09:59:19.000 EST [8942] ubuntupg@ubuntupg FATAL: 28000: GSSAP= I authentication failed for user "ubuntupg" > 2019-03-01 09:59:19.000 EST [8942] ubuntupg@ubuntupg DETAIL: Connection = matched pg_hba.conf line 96: "host all all 0.0.0= =2E0/0 gss include_realm=3D0 krb_realm=3DAD.CORP.COM" > 2019-03-01 09:59:19.000 EST [8942] ubuntupg@ubuntupg LOCATION: auth_fail= ed, auth.c:307 >=20 > User ubuntupg is created on the AD. In postgresql, does it need to have a= naming convention? At this moment, i've a user named ubuntupg and also ubu= ntupg@ad.corp.com >=20 > > I think setting up PAM authentication with AD on Linux server joined to > > domain via realm SSSD was much easier and transparent. > I don't know this kind of authentication, do you have more information on= this? Maybe I can switch authentication method. >=20 > Best regards, >=20 >=20 > ________________________________ > De : Andre Piwoni > > Envoy=E9 : 28 f=E9vrier 2019 20:19 > =C0 : Jean-Philippe Chenel > Cc : pgsql-general@lists.postgresql.org > Objet : Re: PostgreSQL (linux) configuration with GSSAPI to a Windows dom= ain >=20 > I think setting up PAM authentication with AD on Linux server joined to d= omain via realm SSSD was much easier and transparent. >=20 > Something like this worked for me to create SPN mapping and keytab in one= command without need to use UPPERCASE for POSTGRES: > ktpass -out postgres.keytab -princ POSTGRES/UBUNTU.ad.corp.com@AD.CORP.CO= M -mapUser AD\POSTGRES -pass 'thepas= sword' -mapOp add -crypto ALL -ptype KRB5_NT_PRINCIPAL >=20 > pg_hba.conf > host all all 0.0.0.0/0 gss gss include_realm=3D0 krb_re= alm=3DAD.CORP.COM > ktb_realm should not be needed since you have one in your krb5.conf >=20 > postgresql.conf > krb_server_keyfile =3D '/etc/postgresql/9.6/main/postgres.keytab' > #krb_caseins_users =3D off >=20 > kinit ubuntupg@AD.CORP.COM > psql.exe -h 192.168.1.143 -U ubuntupg >=20 > klist > Ticket cache: FILE:/tmp/krb5cc_0 > Default principal: ubuntupg@AD.CORP.COM >=20 > Valid starting Expires Service principal > 08/03/2018 22:28:47 08/04/2018 08:28:47 krbtgt/AD.CORP.COM@AD.CORP.COM<= mailto:AD.CORP.COM@AD.CORP.COM> > renew until 08/10/2018 22:28:42 > 08/03/2018 22:29:00 08/04/2018 08:28:47 POSTGRES/UBUNTU.ad.corp.com@AD.= CORP.COM > renew until 08/10/2018 22:28:42 >=20 > On Thu, Feb 28, 2019 at 2:54 PM Jean-Philippe Chenel > wrote: >=20 > I'm trying to configure authentication between PostgreSQL database server= on linux and Windows Active Directory. >=20 > First part of configuration is working but when I'm trying to authenticat= e from Windows client, it is not working with message: Can't obtain databas= e list from the server. SSPI continuation error. The specified target is un= known or unreachable (80090303) >=20 > On Windows: >=20 > Domain is AD.CORP.COM >=20 > Host is: WIN.AD.CORP.COM, IP is 192.168.1.173 >=20 > On Linux (Ubuntu 16.04) >=20 > hostname is UBUNTU.ad.corp.com, IP is 192.168.= 1.143 >=20 > DNS are configured to reach the AD sytem (.173) >=20 > PostgreSQL 9.6.9 on x86_64-pc-linux-gnu (Ubuntu 9.6.9-2.pgdg16.04+1), com= piled by gcc (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609, 64-bit >=20 > I've created =E0 service user called POSTGRES and a normal user in AD cal= led ubuntupg. >=20 > Finally I've created the SPN: >=20 > setspn -A POSTGRES/UBUNTU.ad.corp.com POSTGRES >=20 > Generated the keytab to put on the linux server: >=20 > ktpass -out postgres.keytab -princ POSTGRES/UBUNTU.ad.corp.com@AD.CORP.CO= M -mapUser POSTGRES -pass 'thepassword' -crypto all -ptype KRB5_NT_PRINCIPAL >=20 > On the linux /etc/krb5.conf: >=20 > [libdefaults] > debug=3Dtrue > default_realm =3D AD.CORP.COM > dns_lookup_realm =3D false > dns_lookup_kdc =3D false > ticket_lifetime =3D 24h > renew_lifetime =3D 7d > forwardable =3D true >=20 > [realms] > AD.CORP.COM =3D { >=20 > kdc =3D WIN.AD.CORP.COM > } >=20 > [domain_realm] > ad.corp.com =3D AD.CORP.COM >=20 > .ad.corp.com =3D AD.CORP.COM >=20 > Making this command work and klist return a ticket: >=20 > kinit -V -k -t /etc/postgresql/9.6/main/postgres.keytab POSTGRES/UBUNTU.a= d.corp.com@AD.CORP.COM >=20 > klist -k /etc/postgresql/9.6/main/postgres.keytab >=20 > POSTGRES/UBUNTU.ad.corp.com@AD.CORP.COM >=20 > Here is the added onfiguration to postgresql.conf >=20 > krb_server_keyfile =3D '/etc/postgresql/9.6/main/postgres.keytab' >=20 > Here is the configuration of pg_hba.conf >=20 > host all all 0.0.0.0/0 gss >=20 > Up to here, all is working as expected, kinit with ubuntupg is also worki= ng well. ubuntupg and ubuntupg@ad.corp.com is = also created on the database. The probleme is when I try, from a Windows cl= ient, connecting to the DB. >=20 > psql.exe -h 192.168.1.143 -U ubuntupg >=20 > Can't obtain database list from the server. SSPI continuation error. The = specified target is unknown or unreachable (80090303) >=20 > PostgreSQL log file show: >=20 > 2019-02-28 14:02:54.178 EST [6747] [unknown]@[unknown] LOG: 00000: conne= ction received: host=3D192.168.1.176 port=3D57254 > 2019-02-28 14:02:54.178 EST [6747] [unknown]@[unknown] LOCATION: Backend= Initialize, postmaster.c:4188 > 2019-02-28 14:02:54.331 EST [6747] ubuntupg@ubuntupg FATAL: 28000: GSSAP= I authentication failed for user "ubuntupg" > 2019-02-28 14:02:54.331 EST [6747] ubuntupg@ubuntupg DETAIL: Connection = matched pg_hba.conf line 92: "host all all 0.0.0= =2E0/0 gss" > 2019-02-28 14:02:54.331 EST [6747] ubuntupg@ubuntupg LOCATION: auth_fail= ed, auth.c:307 >=20 > psql.exe -h 192.168.1.143 -U ubuntupg@ad.corp.com >=20 > 2019-02-28 14:06:35.992 EST [6866] [unknown]@[unknown] LOG: 00000: conne= ction received: host=3D192.168.1.176 port=3D57282 >=20 > 2019-02-28 14:06:35.992 EST [6866] [unknown]@[unknown] LOCATION: Backend= Initialize, postmaster.c:4188 >=20 > 2019-02-28 14:06:36.148 EST [6866] ubuntupg@ad.corp.com@ubuntupg@ad.corp.= com FATAL: 28000: GSSAPI authentication failed for user "ubuntupg@ad.corp.= com" >=20 > 2019-02-28 14:06:36.148 EST [6866] ubuntupg@ad.corp.com@ubuntupg@ad.corp.= com DETAIL: Connection matched pg_hba.conf line 96: "host all = all 0.0.0.0/0 gss" >=20 > 2019-02-28 14:06:36.148 EST [6866] ubuntupg@ad.corp.com@ubuntupg@ad.corp.= com LOCATION: auth_failed, auth.c:307 >=20 > Thank you very much for your help. >=20 > Best regards, >=20 >=20 > -- >=20 >=20 --QQOJ7tcb1Icu6LtL Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJceZ2CAAoJEO1sijiDR2RVe60QAJsAnIv46iFAaayiGDWNIWwO Y/+AEz7QDhWU0zHFVDSPo3BaCu6ad2wJOnJPuMf7qpDo45IYr8zINCNb/6cRAfW6 5l4RmqJkzTPdYyIKTRpWM+wouoLa9w3nLlkLj9Zox9Qcn43DKlFGZ1YSIkxQRUQ8 jjvYO1mEjNnR0dXiUJix/Ghs4wV2UsMwDHIIw+O5V1xDDE42vMj1Rh/lfrmNOY7b w8OsosxBneWXMerCAzrB+qOBWexVRUhJAt1ifIqwGJlT9C2cDD8GX2kKFGDPrAZP ZnGgXzzZwYQYMDeILl1Xfpii5hagJvUIA2o9TIWNqeW7d1Bm1p4H6AKXlVohw9Iy sM3nuasW9kBRJTyAas3z6sDcMT2/28Sw8/mTeggE8E/3t6qCK1LQYIO6Y2YebaZn HZEG6RMkvs/ua6WOAA5fDmhCSNF6M9WM0r4yiEhiH8dvK6k5aA26K8yDfT5kmj3d DpyzI5aqIMl+J43W8pRelNK6K68ZODr6zflzxptm+u74dx4vCFIazuIRDpLmTRxl SHsI3xMGbxFD0m/W3FtGp2ky89FxpZ7E5CackD/0LVScrv2blgK4VSP8NdgI0mS8 fYDPpHpbVZJXMFqAcyjrf6GHRY9lfeMRCmqpWoBhHUAbhJ1dhCA8Ie04+Z+v/fzs gaq+9t6s16xLSWLnUpk/ =5awC -----END PGP SIGNATURE----- --QQOJ7tcb1Icu6LtL--