Adding STARTTLS support to users_ldap

lp bug: https://launchpad.net/bugs/389033 fixed

bzr revid: ian@catalyst.net.nz-20110811001429-j62yn9uz1g2o9j9c
This commit is contained in:
Ian Beardslee 2011-08-11 12:14:29 +12:00
parent 6adef2a895
commit 949fa9cdd8
3 changed files with 20 additions and 1 deletions

View File

@ -49,6 +49,12 @@ anonymous authentication for users, it is only for the master
LDAP account that is used to verify if a user exists before LDAP account that is used to verify if a user exists before
attempting to authenticate it. attempting to authenticate it.
Securing the connection with STARTTLS is available for LDAP
servers support STARTTLS. The default is to require STARTTLS.
Configuration of the LDAP connection (certificates etc) should
be done through ``/etc/ldap/ldap.conf`` (or distribution
specific location).
Security Considerations Security Considerations
+++++++++++++++++++++++ +++++++++++++++++++++++
Users' LDAP passwords are never stored in the OpenERP database, Users' LDAP passwords are never stored in the OpenERP database,
@ -77,6 +83,9 @@ OpenERP database (which means no access), the first step
always fails and the LDAP server is queried to do the always fails and the LDAP server is queried to do the
authentication. authentication.
Enabling STARTTLS ensures that the authentication query to the
LDAP server is encrypted.
User Template User Template
+++++++++++++ +++++++++++++
In the LDAP configuration on the Company form, it is possible to In the LDAP configuration on the Company form, it is possible to

View File

@ -50,7 +50,8 @@ class CompanyLDAP(osv.osv):
args = [] args = []
cr.execute(""" cr.execute("""
SELECT id, company, ldap_server, ldap_server_port, ldap_binddn, SELECT id, company, ldap_server, ldap_server_port, ldap_binddn,
ldap_password, ldap_filter, ldap_base, "user", create_user ldap_password, ldap_filter, ldap_base, "user", create_user,
ldap_tls
FROM res_company_ldap FROM res_company_ldap
WHERE ldap_server != '' """ + id_clause + """ ORDER BY sequence WHERE ldap_server != '' """ + id_clause + """ ORDER BY sequence
""", args) """, args)
@ -94,6 +95,8 @@ class CompanyLDAP(osv.osv):
if results and len(results) == 1: if results and len(results) == 1:
dn = results[0][0] dn = results[0][0]
conn = self.connect(conf) conn = self.connect(conf)
if conf['ldap_tls']:
conn.start_tls_s()
conn.simple_bind_s(dn, password) conn.simple_bind_s(dn, password)
conn.unbind() conn.unbind()
entry = results[0] entry = results[0]
@ -131,6 +134,8 @@ class CompanyLDAP(osv.osv):
logger = logging.getLogger('orm.ldap') logger = logging.getLogger('orm.ldap')
try: try:
conn = self.connect(conf) conn = self.connect(conf)
if conf['ldap_tls']:
conn.start_tls_s()
conn.simple_bind_s(conf['ldap_binddn'] or '', conn.simple_bind_s(conf['ldap_binddn'] or '',
conf['ldap_password'] or '') conf['ldap_password'] or '')
results = conn.search_st(conf['ldap_base'], ldap.SCOPE_SUBTREE, results = conn.search_st(conf['ldap_base'], ldap.SCOPE_SUBTREE,
@ -211,12 +216,15 @@ class CompanyLDAP(osv.osv):
help="Model used for user creation"), help="Model used for user creation"),
'create_user': fields.boolean('Create user', 'create_user': fields.boolean('Create user',
help="Create the user if not in database"), help="Create the user if not in database"),
'ldap_tls': fields.boolean('Use TLS',
help="Use STARTTLS to connect to the LDAP server"),
} }
_defaults = { _defaults = {
'ldap_server': '127.0.0.1', 'ldap_server': '127.0.0.1',
'ldap_server_port': 389, 'ldap_server_port': 389,
'sequence': 10, 'sequence': 10,
'create_user': True, 'create_user': True,
'ldap_tls': True,
} }
CompanyLDAP() CompanyLDAP()

View File

@ -20,12 +20,14 @@
<field name="user"/> <field name="user"/>
<newline/> <newline/>
<field name="sequence"/> <field name="sequence"/>
<field name="ldap_tls"/>
</form> </form>
<tree string="LDAP Configuration"> <tree string="LDAP Configuration">
<field name="sequence"/> <field name="sequence"/>
<field name="ldap_server"/> <field name="ldap_server"/>
<field name="ldap_server_port"/> <field name="ldap_server_port"/>
<field name="ldap_base"/> <field name="ldap_base"/>
<field name="ldap_tls"/>
</tree> </tree>
</field> </field>
</xpath> </xpath>