pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Allow ldaps when using ldap authentication
4+ messages / 3 participants
[nested] [flat]

* pgsql: Allow ldaps when using ldap authentication
@ 2018-01-03 15:14  Peter Eisentraut <peter_e@gmx.net>
  0 siblings, 1 reply; 4+ messages in thread

From: Peter Eisentraut @ 2018-01-03 15:14 UTC (permalink / raw)
  To: pgsql-committers

Allow ldaps when using ldap authentication

While ldaptls=1 provides an RFC 4513 conforming way to do LDAP
authentication with TLS encryption, there was an earlier de facto
standard way to do LDAP over SSL called LDAPS.  Even though it's not
enshrined in a standard, it's still widely used and sometimes required
by organizations' network policies.  There seems to be no reason not to
support it when available in the client library.  Therefore, add support
when using OpenLDAP 2.4+ or Windows.  It can be configured with
ldapscheme=ldaps or ldapurl=ldaps://...

Add tests for both ways of requesting LDAPS and a test for the
pre-existing ldaptls=1.  Modify the 001_auth.pl test for "diagnostic
messages", which was previously relying on the server rejecting
ldaptls=1.

Author: Thomas Munro
Reviewed-By: Peter Eisentraut
Discussion: https://postgr.es/m/CAEepm=1s+pA-LZUjQ-9GQz0Z4rX_eK=DFXAF1nBQ+ROPimuOYQ@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/35c0754fadca8010955f6b10cb47af00bdbe1286

Modified Files
--------------
configure                     | 11 ++++++++
configure.in                  |  1 +
doc/src/sgml/client-auth.sgml | 50 ++++++++++++++++++++++++++---------
src/backend/libpq/auth.c      | 59 ++++++++++++++++++++++++++++++++++++-----
src/backend/libpq/hba.c       | 16 +++++++++++-
src/include/libpq/hba.h       |  1 +
src/include/pg_config.h.in    |  3 +++
src/test/ldap/t/001_auth.pl   | 61 ++++++++++++++++++++++++++++++++++++++++---
8 files changed, 178 insertions(+), 24 deletions(-)



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: pgsql: Allow ldaps when using ldap authentication
@ 2018-01-03 20:07  Thomas Munro <thomas.munro@enterprisedb.com>
  parent: Peter Eisentraut <peter_e@gmx.net>
  0 siblings, 1 reply; 4+ messages in thread

From: Thomas Munro @ 2018-01-03 20:07 UTC (permalink / raw)
  To: Peter Eisentraut <peter_e@gmx.net>; +Cc: pgsql-committers

On Thu, Jan 4, 2018 at 4:14 AM, Peter Eisentraut <peter_e@gmx.net> wrote:
> Allow ldaps when using ldap authentication

Other Windows systems seem OK with this, but baiji said:

.\src\backend\libpq\auth.c(2538): error C2065: 'LDAPS_PORT' :
undeclared identifier

Checking where that's supposed to come from...

-- 
Thomas Munro
http://www.enterprisedb.com




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: pgsql: Allow ldaps when using ldap authentication
@ 2018-01-03 21:24  Thomas Munro <thomas.munro@enterprisedb.com>
  parent: Thomas Munro <thomas.munro@enterprisedb.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Thomas Munro @ 2018-01-03 21:24 UTC (permalink / raw)
  To: Peter Eisentraut <peter_e@gmx.net>; +Cc: pgsql-committers

On Thu, Jan 4, 2018 at 9:07 AM, Thomas Munro
<thomas.munro@enterprisedb.com> wrote:
> On Thu, Jan 4, 2018 at 4:14 AM, Peter Eisentraut <peter_e@gmx.net> wrote:
>> Allow ldaps when using ldap authentication
>
> Other Windows systems seem OK with this, but baiji said:
>
> .\src\backend\libpq\auth.c(2538): error C2065: 'LDAPS_PORT' :
> undeclared identifier
>
> Checking where that's supposed to come from...

Windows documentation talks about LDAP_SSL_PORT instead.  I assume
that "Vista Ultimate 6.0.6000 MSVC 2005 Pro 8.0.50727.867" doesn't
define LDAPS_PORT, but some later version added it for compatibility
with OpenLDAP.  Let's just define it ourselves if it's undefined as we
did for some other LDAP macros, since its value is well known (it's an
IANA-registered port).  See attached.

While poking around in the documentation, I came across this
surprising sentence[1]: "Be aware that even if the secure parameter is
set to zero, if the PortNumber parameter is set to LDAP_SSL_PORT (636)
or to LDAP_SSL_GC_PORT (3269), an encrypted session is initiated."
Huh.  That wasn't mentioned on the main  page for the function[2] and
I don't like it, because it means that the same connection string
could have a different meaning on Windows and Unix.  So I also propose
that we also tweak the code to prevent that.

I don't have a Windows system myself, but this builds OK on Appveyor CI.

[1] https://msdn.microsoft.com/en-us/library/aa367031(v=vs.85).aspx
[2] https://msdn.microsoft.com/en-us/library/aa366996(v=vs.85).aspx

-- 
Thomas Munro
http://www.enterprisedb.com

Attachments:

tweak-ldaps-windows.patch (application/octet-stream, 1.7K) download From c2907c0c30c8d9d8118f3f4ad56d4132533518f5 Mon Sep 17 00:00:00 2001 From: Thomas Munro <thomas.munro@enterprisedb.com> Date: Thu, 4 Jan 2018 09:25:32 +1300 Subject: [PATCH] Define LDAPS_PORT if it's missing and disable implicit LDAPS on Windows. Some versions of Windows don't define LDAPS_PORT. Also, Windows' ldap_sslinit() is documented to use LDAPS even if you said secure=0 when the port number happens to be 636 or 3269. Let's avoid using the port number to imply that you want LDAPS, so that connection strings have the same meaning on Windows and Unix. Author: Thomas Munro Discussion: https://postgr.es/m/CAEepm%3D23B7GV4AUz3MYH1TKpTv030VHxD2Sn%2BLYWDv8d-qWxww%40mail.gmail.com --- src/backend/libpq/auth.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c index 3560edc33a0..f327f7bb1bf 100644 --- a/src/backend/libpq/auth.c +++ b/src/backend/libpq/auth.c @@ -2363,9 +2363,10 @@ InitializeLDAPConnection(Port *port, LDAP **ldap) if (scheme == NULL) scheme = "ldap"; #ifdef WIN32 - *ldap = ldap_sslinit(port->hba->ldapserver, - port->hba->ldapport, - strcmp(scheme, "ldaps") == 0); + if (strcmp(scheme, "ldaps") == 0) + *ldap = ldap_sslinit(port->hba->ldapserver, port->hba->ldapport, 1); + else + *ldap = ldap_init(port->hba->ldapserver, port->hba->ldapport); if (!*ldap) { ereport(LOG, @@ -2489,6 +2490,11 @@ InitializeLDAPConnection(Port *port, LDAP **ldap) #define LDAP_NO_ATTRS "1.1" #endif +/* Not all LDAP implementations define this. */ +#ifndef LDAPS_PORT +#define LDAPS_PORT 636 +#endif + /* * Return a newly allocated C string copied from "pattern" with all * occurrences of the placeholder "$username" replaced with "user_name". -- 2.15.0
^ permalink raw reply [nested|flat] 4+ messages in thread

* Re: pgsql: Allow ldaps when using ldap authentication
@ 2018-01-04 15:53  Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  parent: Thomas Munro <thomas.munro@enterprisedb.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Peter Eisentraut @ 2018-01-04 15:53 UTC (permalink / raw)
  To: Thomas Munro <thomas.munro@enterprisedb.com>; +Cc: pgsql-committers

On 1/3/18 16:24, Thomas Munro wrote:
> Windows documentation talks about LDAP_SSL_PORT instead.  I assume
> that "Vista Ultimate 6.0.6000 MSVC 2005 Pro 8.0.50727.867" doesn't
> define LDAPS_PORT, but some later version added it for compatibility
> with OpenLDAP.  Let's just define it ourselves if it's undefined as we
> did for some other LDAP macros, since its value is well known (it's an
> IANA-registered port).  See attached.
> 
> While poking around in the documentation, I came across this
> surprising sentence[1]: "Be aware that even if the secure parameter is
> set to zero, if the PortNumber parameter is set to LDAP_SSL_PORT (636)
> or to LDAP_SSL_GC_PORT (3269), an encrypted session is initiated."
> Huh.  That wasn't mentioned on the main  page for the function[2] and
> I don't like it, because it means that the same connection string
> could have a different meaning on Windows and Unix.  So I also propose
> that we also tweak the code to prevent that.

pushed

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services




^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2018-01-04 15:53 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-01-03 15:14 pgsql: Allow ldaps when using ldap authentication Peter Eisentraut <peter_e@gmx.net>
2018-01-03 20:07 ` Thomas Munro <thomas.munro@enterprisedb.com>
2018-01-03 21:24   ` Thomas Munro <thomas.munro@enterprisedb.com>
2018-01-04 15:53     ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox