Skip to content

Commit 41472e1

Browse files
authored
Merge pull request #11 from hellofresh/feature-multiple-domains
PTII-373 Allow configure multiple domains
2 parents e73567c + b1b0a13 commit 41472e1

File tree

10 files changed

+276
-99
lines changed

10 files changed

+276
-99
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
.molecule
44
pytestdebug.log
55
__pycache__/
6+
.pytest_cache/
7+
.vscode/

.travis.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,5 @@ branches:
88
only:
99
- master
1010

11-
install:
12-
- pip install molecule
13-
- pip install docker-py
14-
1511
script:
16-
- molecule test
12+
- ./run_tests.sh

README.md

Lines changed: 64 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,69 @@ None
1313
Role Variables
1414
--------------
1515

16-
You can override variables in your group_vars
17-
18-
- `sssd_ldap_search_base: dc=example,dc=org`
19-
- `sssd_ldap_user_search_base: see sssd-ldap man page`
20-
- `sssd_ldap_group_search_base: see sssd-ldap man page`
21-
- `sssd_ldap_uri: ldap://example.org`
22-
- `sssd_ldap_default_bind_dn: cn=manager,dc=example,dc=org`
23-
- `sssd_ldap_default_authtok: bind_password`
24-
- `sssd_ldap_user_ssh_public_key: sshPublicKey`
25-
- `sssd_ldap_override_gid: 500`
16+
Role configuration aimed to be similar to SSSD configuration. But, not all configuration options,
17+
supported in `sssd.conf` are available in role variables with the same names. If you setup needs some options that not presented
18+
feel free to create pull requests. You can find available options in `defaults/main.yml` and `templates/sssd.conf.j2`
19+
20+
`[sssd]` section allows to configure following options options:
21+
22+
sssd_defaults:
23+
# Debug level for:
24+
# Fatal failures, Critical failures, Serious failures
25+
# Configuration settings, Function data
26+
debug_level: '0x0370'
27+
services: nss,pam,ssh
28+
29+
`[nss]` section allows to configure following options options:
30+
31+
sssd_nss:
32+
filter_users: root
33+
filter_groups: root
34+
35+
Some default values for domain specific configuration options are:
36+
37+
sssd_domain_defaults:
38+
id_provider: ldap
39+
auth_provider: ldap
40+
enumerate: 'false'
41+
ldap_uri: ldap://localhost
42+
ldap_id_use_start_tls: 'false'
43+
ldap_tls_reqcert: never
44+
ldap_default_bind_dn: cn=manager,dc=example,dc=org
45+
ldap_default_authtok_type: password
46+
ldap_default_authtok: bind_password
47+
ldap_search_base: dc=example,dc=org
48+
49+
Role supports configuring multiple domains using following syntax:
50+
(see sssd man pages for more information)
51+
52+
sssd_domains:
53+
- name: domain_name
54+
id_provider:
55+
auth_provider:
56+
ldap_uri:
57+
ldap_id_use_start_tls:
58+
ldap_tls_reqcert:
59+
ldap_default_bind_dn:
60+
ldap_default_authtok_type:
61+
ldap_default_authtok:
62+
ldap_search_base:
63+
ldap_user_search_base:
64+
ldap_user_object_class:
65+
ldap_user_name:
66+
ldap_user_uid_number:
67+
ldap_user_gid_number:
68+
ldap_user_ssh_public_key:
69+
ldap_user_email:
70+
override_gid:
71+
ldap_group_search_base:
72+
ldap_group_object_class:
73+
ldap_group_name:
74+
ldap_group_gid_number:
75+
ldap_group_member:
76+
77+
Options that are listed in `sssd_domain_defaults` will allways be present in `sssd.conf`,
78+
other options can be omitted.
2679

2780
Dependencies
2881
------------
@@ -36,7 +89,7 @@ An example of how to use the role:
3689

3790
- hosts: servers
3891
roles:
39-
- { role: sssd-ldap }
92+
- { role: ansible-sssd-ldap }
4093

4194
License
4295
-------

defaults/main.yml

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,35 @@
11
---
2-
sssd_ldap_search_base: dc=example,dc=org
3-
sssd_ldap_uri: ldap://example.org
4-
sssd_ldap_default_bind_dn: cn=manager,dc=example,dc=org
5-
sssd_ldap_default_authtok: bind_password
6-
sssd_ldap_user_ssh_public_key: sshPublicKey
7-
# If you need to override user's primary group you can use `sssd_ldap_override_gid` variable
8-
# sssd_ldap_override_gid: 500
2+
sssd_defaults:
3+
# Debug level for:
4+
# Fatal failures, Critical failures, Serious failures
5+
# Configuration settings, Function data
6+
debug_level: '0x0370'
7+
services: nss,pam,ssh
98

10-
# The following variables can be defined:
11-
# sssd_ldap_user_search_base:
12-
# sssd_ldap_group_search_base:
9+
sssd_nss:
10+
filter_users: root
11+
filter_groups: root
12+
13+
sssd_domain_defaults:
14+
id_provider: ldap
15+
auth_provider: ldap
16+
enumerate: 'false'
17+
ldap_uri: ldap://localhost
18+
ldap_id_use_start_tls: 'false'
19+
ldap_tls_reqcert: never
20+
ldap_default_bind_dn: cn=manager,dc=example,dc=org
21+
ldap_default_authtok_type: password
22+
ldap_default_authtok: bind_password
23+
ldap_search_base: dc=example,dc=org
24+
25+
sssd_domains:
26+
- name: default
27+
id_provider: "{{ sssd_domain_defaults.id_provider }}"
28+
auth_provider: "{{ sssd_domain_defaults.auth_provider }}"
29+
ldap_uri: "{{ sssd_domain_defaults.ldap_uri }}"
30+
ldap_id_use_start_tls: "{{ sssd_domain_defaults.ldap_id_use_start_tls }}"
31+
ldap_tls_reqcert: "{{ sssd_domain_defaults.ldap_tls_reqcert }}"
32+
ldap_default_bind_dn: "{{ sssd_domain_defaults.ldap_default_bind_dn }}"
33+
ldap_default_authtok_type: "{{ sssd_domain_defaults.ldap_default_authtok_type }}"
34+
ldap_default_authtok: "{{ sssd_domain_defaults.ldap_default_authtok }}"
35+
ldap_search_base: "{{ sssd_domain_defaults.ldap_search_base }}"

.yamllint renamed to molecule/default/.yamllint

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ rules:
1111
# NOTE(retr0h): Templates no longer fail this lint rule.
1212
# Uncomment if running old Molecule templates.
1313
# truthy: disable
14+
ignore: |
15+
venv/

molecule/default/create.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
volumes: "{{ item.volumes | default(omit) }}"
4646
capabilities: "{{ item.capabilities | default(omit) }}"
4747
ports: "{{ item.exposed_ports | default(omit) }}"
48+
links: "{{ item.links | default(omit) }}"
4849
register: server
4950
with_items: "{{ molecule_yml.platforms }}"
5051
async: 7200

molecule/default/molecule.yml

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,48 @@ driver:
55
name: docker
66
lint:
77
name: yamllint
8+
options:
9+
config-file: molecule/default/.yamllint
810
platforms:
911
- name: ubuntu-trusty
1012
image: ubuntu-upstart
1113
command: /sbin/init
12-
privileged: True
14+
privileged: 'true'
15+
links:
16+
- "openldap:openldap"
1317
- name: ubuntu-xenial
1418
image: solita/ubuntu-systemd
1519
command: /sbin/init
16-
privileged: True
20+
privileged: 'true'
1721
capabilities:
1822
- SYS_ADMIN
1923
volumes:
2024
- /sys/fs/cgroup:/sys/fs/cgroup:ro
25+
links:
26+
- "openldap:openldap"
2127
- name: centos-7
2228
image: centos/systemd
2329
command: /usr/sbin/init
24-
privileged: True
30+
privileged: 'true'
2531
volumes:
2632
- /sys/fs/cgroup:/sys/fs/cgroup:ro
2733
capabilities:
2834
- SYS_ADMIN
35+
links:
36+
- "openldap:openldap"
2937
provisioner:
3038
name: ansible
3139
inventory:
3240
group_vars:
3341
all:
34-
sssd_ldap_search_base: dc=example,dc=com
35-
sssd_ldap_user_search_base: dc=example,dc=com?subtree?(uidNumber=5000)
36-
sssd_ldap_uri: ldap://localhost
37-
sssd_ldap_default_bind_dn: cn=Manager,dc=example,dc=com
38-
sssd_ldap_default_authtok: s3cr3t
39-
sssd_ldap_user_ssh_public_key: sshPublicKey
40-
sssd_ldap_override_gid: 1
42+
sssd_domains:
43+
- name: default
44+
ldap_uri: ldap://openldap
45+
ldap_search_base: dc=example,dc=org?subtree?(uidNumber=5000)
46+
ldap_default_bind_dn: cn=admin,dc=example,dc=org
47+
ldap_default_authtok: s3cr3t
48+
ldap_user_ssh_public_key: sshPublicKey
49+
override_gid: 1
4150
lint:
4251
name: ansible-lint
4352
options:

molecule/default/prepare.yml

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,47 +9,7 @@
99
Debian: openssh-client
1010
RedHat: openssh-clients
1111

12-
roles:
13-
- role: openldap
14-
openldap_server_domain_name: example.com
15-
openldap_server_rootpw: s3cr3t
16-
openldap_server_enable_ssl: false
17-
1812
tasks:
19-
- name: install python-ldap
20-
package:
21-
name: python-ldap
22-
- name: Make sure we have two test users
23-
ldap_entry:
24-
bind_dn: cn=Manager,dc=example,dc=com
25-
bind_pw: s3cr3t
26-
dn: 'uid={{ item.uid }},dc=example,dc=com'
27-
objectClass:
28-
- top
29-
- person
30-
- posixAccount
31-
- inetOrgPerson
32-
- organizationalPerson
33-
- ldapPublicKey
34-
attributes:
35-
uid: "{{ item.uid }}"
36-
uidNumber: "{{ item.uidNumber }}"
37-
givenName: "{{ item.name }}"
38-
sn: "{{ item.name }}"
39-
cn: "{{ item.name }}"
40-
loginShell: /bin/bash
41-
homeDirectory: "/home/{{ item.uid }}"
42-
sshPublicKey: "{{ item.sshPublicKey }}"
43-
gidNumber: "{{ item.uidNumber }}"
44-
with_items:
45-
- name: Test
46-
uid: test
47-
uidNumber: 5000
48-
sshPublicKey: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDYaGyXcqdQUIxjPr3eqXro9X/2LrLH2o+OrFeGRB2u3WxigroynxD8vLjtG6qyYYtgnvR9+2usVhbNNS3QdF3G5wenCR4Zpk6VIYofQrBYmrzJG9Bsig3G4SgnGF2x4KimupjCdD4+1S9OMF/4GzQZdaLl2HkSTYE+6430FbSD8i3IdpbRI526X8q4njrTHgIYUtAVFTPSudZ/3fIzFpfNlWq5wy1CXCGc7aqmHECQzareeoAM5NfgrUkw7TFrKP/zelDkqpJ6pwYTWg2VZYmoXmh2o+ttWFatGzJPUoeU/r+SjMn4YvMunT+L6NIrbJQkXwB9i3upMx2bQcuPl0cl test-key
49-
- name: Filtered
50-
uid: filtered-test
51-
uidNumber: 5001
52-
sshPublicKey: ''
5313
- name: create /root/.ssh dir
5414
file:
5515
path: /root/.ssh

run_tests.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
echo "Create LDAP users"
6+
CUSTOM_LDIF_DIR=$(mktemp --directory)
7+
8+
cat <<EOF >${CUSTOM_LDIF_DIR}/test.ldif
9+
dn: uid=test,dc=example,dc=org
10+
uid: test
11+
cn: test
12+
sn: Test
13+
objectClass: top
14+
objectClass: posixAccount
15+
objectClass: inetOrgPerson
16+
objectClass: ldapPublicKey
17+
loginShell: /bin/bash
18+
homeDirectory: /home/test
19+
uidNumber: 5000
20+
gidNumber: 5000
21+
22+
gecos: Test User
23+
sshPublicKey: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDYaGyXcqdQUIxjPr3eqXro9X/2LrLH2o+OrFeGRB2u3WxigroynxD8vLjtG6qyYYtgnvR9+2usVhbNNS3QdF3G5wenCR4Zpk6VIYofQrBYmrzJG9Bsig3G4SgnGF2x4KimupjCdD4+1S9OMF/4GzQZdaLl2HkSTYE+6430FbSD8i3IdpbRI526X8q4njrTHgIYUtAVFTPSudZ/3fIzFpfNlWq5wy1CXCGc7aqmHECQzareeoAM5NfgrUkw7TFrKP/zelDkqpJ6pwYTWg2VZYmoXmh2o+ttWFatGzJPUoeU/r+SjMn4YvMunT+L6NIrbJQkXwB9i3upMx2bQcuPl0cl test-key
24+
EOF
25+
26+
cat <<EOF >${CUSTOM_LDIF_DIR}/filtered.ldif
27+
dn: uid=filtered,dc=example,dc=org
28+
uid: filtered
29+
cn: filtered
30+
sn: Filtered
31+
objectClass: top
32+
objectClass: posixAccount
33+
objectClass: inetOrgPerson
34+
loginShell: /bin/bash
35+
homeDirectory: /home/filtered
36+
uidNumber: 5001
37+
gidNumber: 5001
38+
39+
gecos: Filtered User
40+
EOF
41+
42+
echo "Starting docker container running OpenLDAP server"
43+
LDAP_CONTAINER_NAME="openldap"
44+
LDAP_ADMIN_PASSWORD="s3cr3t"
45+
docker run --detach --name ${LDAP_CONTAINER_NAME} \
46+
--env LDAP_ADMIN_PASSWORD=${LDAP_ADMIN_PASSWORD} \
47+
--volume ${CUSTOM_LDIF_DIR}:/container/service/slapd/assets/config/bootstrap/ldif/custom \
48+
osixia/openldap:1.2.0 --copy-service
49+
50+
echo -n "Waiting for ldap server to be ready"
51+
until docker logs openldap 2>&1 | grep "slapd starting" >/dev/null 2>&1
52+
do echo -n "."; sleep 1; done
53+
echo
54+
55+
echo "Prepare python virtual env for running tests"
56+
virtualenv --version >/dev/null
57+
if [ $? != 0 ]
58+
then
59+
echo -e "Please install python virtualenv package to perform the tests"
60+
exit 1
61+
fi
62+
virtualenv venv
63+
. ./venv/bin/activate
64+
pip install ansible docker-py molecule
65+
66+
echo "Run molecule tests"
67+
molecule test
68+
69+
echo "Cleanup"
70+
deactivate
71+
rm -rf ./venv/
72+
docker rm -f ${LDAP_CONTAINER_NAME}
73+
rm -rf ${CUSTOM_LDIF_DIR}

0 commit comments

Comments
 (0)