Commit c66be1fd authored by nimrod's avatar nimrod
Browse files

LDAPS support is done, but still needs testing with specified certificate (not snakeoil).

parent 4836a606
Loading
Loading
Loading
Loading
+5
Changes for .gitignore: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
*~
~*
*.swp
*.swo
files/ldap_password
+6 −3
Changes for README.rst: 6 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -15,9 +15,10 @@ Role Variables
    organization: '{{ ansible_domain }}' #Organization name, defaults to the domain name.
    domain: '{{ ansible_domain }}' #LDAP domain, converted to ldap formatted. Defaults to the domain name of the machine.
    basedn: #LDAP base distinguished name, defaults to machine's domain converted to LDAP format.
    password: #Password for admin account, if blank a random password will be generated and shown on screen.
    password: #Password for admin account, if blank a random password will be generated and saved under files/ldap_password.
    tls_cert: #Certificate for LDAPS, if blank the self-signed snakeoil cert is used.
    tls_key: #Key for LDAPS, if blank the self-signed snakeoil key is used.
    cipherlist: #Cipher list for GnuTLS, used for LDAPS connection.

Dependencies
------------
@@ -46,7 +47,9 @@ Restore procedure
-----------------

Deleting existing basedn: ::
    ldapdelete -rxWD "cn=admin,dc=example,dc=com"
    ldapdelete -Y EXTERNAL -H ldapi:/// -rD "cn=admin,dc=example,dc=com" #Run as root, no password needed.
    ldapdelete -rxWD "cn=admin,dc=example,dc=com" #Run as any user, asks for OpenLDAP admin password.

Restoring from backup: ::
    ldapadd -xWD "cn=admin,dc=example,dc=com -f backup.ldif
    ldapadd -Y EXTERNAL -H ldapi:/// -D "cn=admin,dc=example,dc=com -f backup.ldif #Run as root, no password needed.
    ldapadd -xWD "cn=admin,dc=example,dc=com -f backup.ldif #Run as any user, asks for OpenLDAP admin password.
+2
Changes for defaults/main.yml: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -4,3 +4,5 @@
organization: '{{ ansible_domain }}'
domain: '{{ ansible_domain }}'
basedn: 'dc={{ domain.split(".") | join(",dc=") }}'
password: '{{ lookup("password", "ldap_password") }}'
cipherlist: '+AES-128-GCM:+AES-256-GCM:+AES-128-CBC:+AES-256-CBC:+ECDHE-RSA:+DHE-RSA:+AEAD:+SHA1:+SHA256:+SHA384'

Empty file added.

+53 −4
Changes for tasks/main.yml: 53 added lines, 4 removed lines.
Original line number Diff line number Diff line
---
# tasks file for ansible-ldap

- name: Copy TLS certificate and key
  when: tls_cert is defined and tls_key is defined
  copy:
    src: '{{ item.src }}'
    dest: '{{ item.dest }}'
    owner: root
    group: ssl-cert
    mode: '{{ item.mode }}'
  register: ldap_tls_copy
  with_items:
    - src: '{{ tls_key }}'
      dest: '/etc/ssl/private/{{ tls_key.split(".")[:-1]|join(".") }}.key'
      mode: '0640'
    - src: '{{ tls_cert }}'
      dest: '/usr/local/share/ca-certificates/{{ tls_cert.split(".")[:-1]|join(".") }}.crt'
      mode: '0644'

- name: Update certificate authority store
  command: /usr/sbin/update-ca-certificates
  when: ldap_tls_copy.changed
  notify:
    - Restart OpenLDAP

- name: Preconfigure packages
  debconf:
    name: '{{ item.name }}'
@@ -42,6 +65,14 @@
    - phpldapadmin
    - gnutls-bin

- name: Allow OpenLDAP access to the TLS key
  user:
    name: openldap
    groups: ssl-cert
    state: present
  notify:
    - Restart OpenLDAP

- name: Configure UFW
  ufw:
    rule: allow
@@ -50,15 +81,20 @@
  with_items:
    - 22
    - 636
  notify:
    - Reload UFW

- name: Configure UFW default policy
  ufw:
    policy: reject
    state: enabled

- name: Set slapd binds
  lineinfile:
    dest: /etc/default/slapd
    line: SLAPD_SERVICES="ldap:/// ldapi:/// ldaps:///"
    regexp: '^SLAPD_SERVICES='
    state: present
  notify:
    - Reload UFW
    - Restart OpenLDAP

- name: Set default ldap client settings
  lineinfile:
@@ -72,10 +108,23 @@
    - line: 'URI    ldap://localhost'
      regexp: '^URI'

- name: Generate LDAPS configuration
  template:
    src: ldaps.ldif.j2
    dest: /root/ldaps.ldif
    owner: root
    group: root
    mode: '0644'

- name: Configure LDAPS
  command: '/usr/bin/ldapmodify -Y EXTERNAL -H ldapi:/// -f /root/ldaps.ldif -D "cn=admin,{{ basedn }}"'
  notify:
    - Restart OpenLDAP

- name: Add backup cron job
  cron:
    name: OpenLDAP daily backup
    special_time: daily
    job: 'ldapsearch -Lxw password -D "cn=admin,{{ basedn }}" > /var/backups/{{ basedn }}.ldif'
    job: 'ldapsearch -L -Y EXTERNAL -H ldapi:/// -D "cn=admin,{{ basedn }}" > /var/backups/{{ basedn }}.ldif 2>/dev/null'
    state: present
    user: root
Loading