diff --git a/roles/svc-db-openldap/handlers/main.yml b/roles/svc-db-openldap/handlers/main.yml new file mode 100644 index 00000000..eb91107b --- /dev/null +++ b/roles/svc-db-openldap/handlers/main.yml @@ -0,0 +1,40 @@ +- name: Load memberof module from file in OpenLDAP container + shell: > + docker exec -i {{ OPENLDAP_CONTAINER }} ldapmodify -Y EXTERNAL -H ldapi:/// -f "{{ [OPENLDAP_LDIF_PATH_DOCKER, 'configuration/01_member_of_configuration.ldif' ] | path_join }}" + listen: + - "Import configuration LDIF files" + # @todo Remove the following ignore errors when setting up a new server + # Just here because debugging would take to much time + ignore_errors: true + +- name: Refint Module Activation for OpenLDAP + shell: > + docker exec -i {{ OPENLDAP_CONTAINER }} ldapadd -Y EXTERNAL -H ldapi:/// -f "{{ [ OPENLDAP_LDIF_PATH_DOCKER, 'configuration/02_member_of_configuration.ldif' ] | path_join }}" + listen: + - "Import configuration LDIF files" + register: ldapadd_result + failed_when: ldapadd_result.rc not in [0, 68] + # @todo Remove the following ignore errors when setting up a new server + # Just here because debugging would take to much time + ignore_errors: true + +- name: Refint Overlay Configuration for OpenLDAP + shell: > + docker exec -i {{ OPENLDAP_CONTAINER }} ldapmodify -Y EXTERNAL -H ldapi:/// -f "{{ [ OPENLDAP_LDIF_PATH_DOCKER, 'configuration/03_member_of_configuration.ldif' ] | path_join }}" + listen: + - "Import configuration LDIF files" + register: ldapadd_result + failed_when: ldapadd_result.rc not in [0, 68] + # @todo Remove the following ignore errors when setting up a new server + # Just here because debugging would take to much time + ignore_errors: true + +- name: "Import users, groups, etc. to LDAP" + shell: > + docker exec -i {{ OPENLDAP_CONTAINER }} ldapadd -x -D "{{ LDAP.DN.ADMINISTRATOR.DATA }}" -w "{{ LDAP.BIND_CREDENTIAL }}" -c -f "{{ [ OPENLDAP_LDIF_PATH_DOCKER, 'groups', (item | basename | regex_replace('\.j2$', '')) ] | path_join }}" + register: ldapadd_result + changed_when: "'adding new entry' in ldapadd_result.stdout" + failed_when: ldapadd_result.rc not in [0, 20, 68, 65] + listen: + - "Import groups LDIF files" + loop: "{{ query('fileglob', role_path ~ '/templates/ldif/groups/*.j2') | sort }}" diff --git a/roles/svc-db-openldap/tasks/01_credentials.yml b/roles/svc-db-openldap/tasks/01_credentials.yml index 65f3346b..99d3bc6b 100644 --- a/roles/svc-db-openldap/tasks/01_credentials.yml +++ b/roles/svc-db-openldap/tasks/01_credentials.yml @@ -3,7 +3,7 @@ - name: "Query available LDAP databases" shell: | - docker exec {{ OPENLDAP_NAME }} \ + docker exec {{ OPENLDAP_CONTAINER }} \ ldapsearch -Y EXTERNAL -H ldapi:/// -LLL -b cn=config "(olcDatabase=*)" dn register: ldap_databases @@ -27,13 +27,13 @@ - name: "Generate hash for Database Admin password" shell: | - docker exec {{ OPENLDAP_NAME }} \ + docker exec {{ OPENLDAP_CONTAINER }} \ slappasswd -s "{{ LDAP.BIND_CREDENTIAL }}" register: database_admin_pw_hash - name: "Reset Database Admin password in LDAP (olcRootPW)" shell: | - docker exec -i {{ OPENLDAP_NAME }} ldapmodify -Y EXTERNAL -H ldapi:/// < bash -c ' diff --git a/roles/svc-db-openldap/templates/env.j2 b/roles/svc-db-openldap/templates/env.j2 index b0967577..174a95b1 100644 --- a/roles/svc-db-openldap/templates/env.j2 +++ b/roles/svc-db-openldap/templates/env.j2 @@ -3,24 +3,24 @@ # GENERAL ## Admin (Data) -LDAP_ADMIN_USERNAME= {{ applications | get_app_conf(application_id, 'users.administrator.username') }} # LDAP database admin user. -LDAP_ADMIN_PASSWORD= {{ LDAP.BIND_CREDENTIAL }} # LDAP database admin password. +LDAP_ADMIN_USERNAME= {{ applications | get_app_conf(application_id, 'users.administrator.username') }} # LDAP database admin user. +LDAP_ADMIN_PASSWORD= {{ LDAP.BIND_CREDENTIAL }} # LDAP database admin password. ## Users -LDAP_USERS= ' ' # Comma separated list of LDAP users to create in the default LDAP tree. Default: user01,user02 -LDAP_PASSWORDS= ' ' # Comma separated list of passwords to use for LDAP users. Default: bitnami1,bitnami2 -LDAP_ROOT= {{ LDAP.DN.ROOT }} # LDAP baseDN (or suffix) of the LDAP tree. Default: dc=example,dc=org +LDAP_USERS= ' ' # Comma separated list of LDAP users to create in the default LDAP tree. Default: user01,user02 +LDAP_PASSWORDS= ' ' # Comma separated list of passwords to use for LDAP users. Default: bitnami1,bitnami2 +LDAP_ROOT= {{ LDAP.DN.ROOT }} # LDAP baseDN (or suffix) of the LDAP tree. Default: dc=example,dc=org ## Admin (Config) -LDAP_ADMIN_DN= {{LDAP.DN.ADMINISTRATOR.DATA}} +LDAP_ADMIN_DN= {{ LDAP.DN.ADMINISTRATOR.DATA }} LDAP_CONFIG_ADMIN_ENABLED= yes LDAP_CONFIG_ADMIN_USERNAME= {{ applications | get_app_conf(application_id, 'users.administrator.username') }} LDAP_CONFIG_ADMIN_PASSWORD= {{ applications | get_app_conf(application_id, 'credentials.administrator_password') }} # Network -LDAP_PORT_NUMBER= {{OPENLDAP_DOCKER_PORT_OPEN}} # Route to default port -LDAP_ENABLE_TLS= no # Using nginx proxy for tls -LDAP_LDAPS_PORT_NUMBER= {{OPENLDAP_DOCKER_PORT_SECURE}} # Port used for TLS secure traffic. Priviledged port is supported (e.g. 636). Default: 1636 (non privileged port). +LDAP_PORT_NUMBER= {{ OPENLDAP_DOCKER_PORT_OPEN }} # Route to default port +LDAP_ENABLE_TLS= no # Using nginx proxy for tls +LDAP_LDAPS_PORT_NUMBER= {{ OPENLDAP_DOCKER_PORT_SECURE }} # Port used for TLS secure traffic. Priviledged port is supported (e.g. 636). Default: 1636 (non privileged port). # Security -LDAP_ALLOW_ANON_BINDING= no # Allow anonymous bindings to the LDAP server. Default: yes. \ No newline at end of file +LDAP_ALLOW_ANON_BINDING= no # Allow anonymous bindings to the LDAP server. Default: yes. \ No newline at end of file diff --git a/roles/svc-db-openldap/templates/ldif/groups/01_rbac_group.ldif.j2 b/roles/svc-db-openldap/templates/ldif/groups/01_rbac_group.ldif.j2 deleted file mode 100644 index 6bb0ebd9..00000000 --- a/roles/svc-db-openldap/templates/ldif/groups/01_rbac_group.ldif.j2 +++ /dev/null @@ -1,30 +0,0 @@ -{# -@todo: activate -{% for dn, entry in (applications | build_ldap_role_entries(users, ldap)).items() %} - -dn: {{ dn }} -{% for oc in entry.objectClass %} -objectClass: {{ oc }} -{% endfor %} -{% if entry.ou is defined %} -ou: {{ entry.ou }} -{% else %} -cn: {{ entry.cn }} -{% endif %} -{% if entry.gidNumber is defined %} -gidNumber: {{ entry.gidNumber }} -{% endif %} -description: {{ entry.description }} -{% if entry.memberUid is defined %} -{% for uid in entry.memberUid %} -memberUid: {{ uid }} -{% endfor %} -{% endif %} -{% if entry.member is defined %} -{% for m in entry.member %} -member: {{ m }} -{% endfor %} -{% endif %} - -{% endfor %} -#} \ No newline at end of file diff --git a/roles/svc-db-openldap/templates/ldif/groups/02_rbac_roles.ldif.j2 b/roles/svc-db-openldap/templates/ldif/groups/01_rbac_roles.ldif.j2 similarity index 96% rename from roles/svc-db-openldap/templates/ldif/groups/02_rbac_roles.ldif.j2 rename to roles/svc-db-openldap/templates/ldif/groups/01_rbac_roles.ldif.j2 index 18b1e417..e56a0935 100644 --- a/roles/svc-db-openldap/templates/ldif/groups/02_rbac_roles.ldif.j2 +++ b/roles/svc-db-openldap/templates/ldif/groups/01_rbac_roles.ldif.j2 @@ -1,4 +1,4 @@ -{% for dn, entry in (applications | build_ldap_role_entries(users, ldap)).items() %} +{% for dn, entry in (applications | build_ldap_role_entries(users, LDAP)).items() %} dn: {{ dn }} {% for oc in entry.objectClass %} diff --git a/roles/svc-db-openldap/vars/main.yml b/roles/svc-db-openldap/vars/main.yml index 88d8538d..1c7be164 100644 --- a/roles/svc-db-openldap/vars/main.yml +++ b/roles/svc-db-openldap/vars/main.yml @@ -13,10 +13,9 @@ OPENLDAP_LDIF_PATH_DOCKER: "/tmp/ldif/" OPENLDAP_LDIF_TYPES: - configuration - groups - - schema # Don't know if this is still needed, it's now setup via tasks # Container -OPENLDAP_NAME: "{{ applications | get_app_conf(application_id, 'docker.services.openldap.name') }}" +OPENLDAP_CONTAINER: "{{ applications | get_app_conf(application_id, 'docker.services.openldap.name') }}" OPENLDAP_IMAGE: "{{ applications | get_app_conf(application_id, 'docker.services.openldap.image') }}" OPENLDAP_VERSION: "{{ applications | get_app_conf(application_id, 'docker.services.openldap.version') }}" OPENLDAP_VOLUME: "{{ applications | get_app_conf(application_id, 'docker.volumes.data') }}"