Skip to content

Commit

Permalink
[AIRFLOW-3164] Verify server certificate when connecting to LDAP (#4006)
Browse files Browse the repository at this point in the history
Misconfiguration and improper checking of exceptions disabled
server certificate checking. We now only support TLS connections
and do not support insecure connections anymore.
  • Loading branch information
bolkedebruin authored and ashb committed Nov 8, 2018
1 parent c39c961 commit 66d0d05
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
11 changes: 11 additions & 0 deletions UPDATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ configuration, so creating EMR clusters might fail until your connection is upda
Ec2SubnetId, TerminationProtection and KeepJobFlowAliveWhenNoSteps were all top-level keys when they
should be inside the "Instances" dict)

### LDAP Auth Backend now requires TLS

Connecting to an LDAP serever over plain text is not supported anymore. The
certificate presented by the LDAP server must be signed by a trusted
certificiate, or you must provide the `cacert` option under `[ldap]` in the
config file.

If you want to use LDAP auth backend without TLS then you will habe to create a
custom-auth backend based on
https://github.com/apache/incubator-airflow/blob/1.10.0/airflow/contrib/auth/backends/ldap_auth.py

## Airflow 1.10

Installation and upgrading requires setting `SLUGIFY_USES_TEXT_UNIDECODE=yes` in your environment or
Expand Down
14 changes: 8 additions & 6 deletions airflow/contrib/auth/backends/ldap_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,18 @@ class LdapException(Exception):


def get_ldap_connection(dn=None, password=None):
tls_configuration = None
use_ssl = False
try:
cacert = configuration.conf.get("ldap", "cacert")
tls_configuration = Tls(validate=ssl.CERT_REQUIRED, ca_certs_file=cacert)
use_ssl = True
except Exception:
except AirflowConfigException:
pass

server = Server(configuration.conf.get("ldap", "uri"), use_ssl, tls_configuration)
tls_configuration = Tls(validate=ssl.CERT_REQUIRED,
ca_certs_file=cacert)

server = Server(configuration.conf.get("ldap", "uri"),
use_ssl=True,
tls=tls_configuration)

conn = Connection(server, native(dn), native(password))

if not conn.bind():
Expand Down
3 changes: 1 addition & 2 deletions docs/security.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ LDAP
''''

To turn on LDAP authentication configure your ``airflow.cfg`` as follows. Please note that the example uses
an encrypted connection to the ldap server as you probably do not want passwords be readable on the network level.
It is however possible to configure without encryption if you really want to.
an encrypted connection to the ldap server as we do not want passwords be readable on the network level.

Additionally, if you are using Active Directory, and are not explicitly specifying an OU that your users are in,
you will need to change ``search_scope`` to "SUBTREE".
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def write_version(filename=os.path.join(*['airflow',
'snakebite[kerberos]>=2.7.8']
kubernetes = ['kubernetes>=3.0.0',
'cryptography>=2.0.0']
ldap = ['ldap3>=0.9.9.1']
ldap = ['ldap3>=2.5.1']
mssql = ['pymssql>=2.1.1']
mysql = ['mysqlclient>=1.3.6']
oracle = ['cx_Oracle>=5.1.2']
Expand Down

0 comments on commit 66d0d05

Please sign in to comment.