Skip to content

Commit 504cc78

Browse files
committed
added first pass of the ldapd role
Signed-off-by: Aisha Tammy <[email protected]>
1 parent 023fd4f commit 504cc78

File tree

5 files changed

+136
-0
lines changed

5 files changed

+136
-0
lines changed

defaults/main.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
3+
ldap_domains: []
4+
# - domain: domain.tld
5+
# users:
6+
# - uid: puffy
7+
# first: "Puffy"
8+
# last: "Fish"
9+
# pw_hash: "$2b$10$leismHABjnpr/lGk4bQ6ce374PYKP/8LyNDh7ZYJAgAG0CNFVdcj2"
10+
# pubkey: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDUJHLRqynSi5YpWU0v6xogi0hiRFdXAckAw+KOek6TA"
11+
12+
ldap_admin: root
13+
ldap_passwd: '{BSDAUTH}root'
14+
15+
ldap_uid_start: 1000
16+
ldap_gid_start: 1000
17+
18+
ldap_indexes:
19+
- objectClass
20+
- uid
21+
- uidNumber
22+
- gidNumber
23+
- userPassword
24+
- cn # common name
25+
- sn # surname
26+
- givenName # first name
27+
- ou # organizational unit
28+
- mail
29+
- sshPublicKey
30+
- quotaBytes
31+
32+
ldap_schemas:
33+
- "ldap_extras.schema"
34+
35+
36+
ldap_groups: [
37+
{ gidnum: 666, name: _ldap, member_uids: [ puffy ] }
38+
]

files/ldap_extras.schema

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
attributetype ( 1.3.6.1.4.1.30155.115.3 NAME 'sshPublicKey'
2+
DESC 'SSH public key'
3+
EQUALITY caseExactIA5Match
4+
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )
5+
6+
attributetype ( 1.3.6.1.4.1.30155.115.4 NAME 'mailQuotaBytes'
7+
DESC 'Dovecot mailbox quota'
8+
EQUALITY integerMatch
9+
SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )

handlers/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
- name: restart ldapd
3+
service:
4+
name: ldapd
5+
state: restarted

tasks/main.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
- name: install additional ldap packages
3+
openbsd_pkg:
4+
name: '{{ item }}'
5+
state: present
6+
with_items: "{{ ldap_packages }}"
7+
8+
- name: install schema files
9+
copy:
10+
src: "{{ item }}"
11+
dest: "/etc/ldap/{{ item }}"
12+
with_items: "{{ ldap_schemas }}"
13+
14+
- name: make sure extra config files exist
15+
file:
16+
path: "{{ item }}"
17+
state: touch
18+
owner: root
19+
group: wheel
20+
mode: 0600
21+
with_items:
22+
- "/etc/ldapd_before.conf"
23+
- "/etc/ldapd_after.conf"
24+
25+
- name: generate ldap config file
26+
template:
27+
src: ldapd.conf.j2
28+
dest: /etc/ldapd.conf
29+
mode: 0600
30+
owner: root
31+
group: wheel
32+
validate: /usr/sbin/ldapd -n -f %s
33+
notify: restart ldapd
34+
35+
- name: enable and start ldapd service
36+
service:
37+
name: ldapd
38+
state: started
39+
enabled: true
40+
41+

templates/ldap.conf.j2

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
include "/etc/ldapd_before.conf"
2+
3+
listen on "/var/run/ldapi"
4+
listen on "/var/www/run/ldapi"
5+
listen on lo0 secure
6+
7+
schema "/etc/ldap/core.schema"
8+
schema "/etc/ldap/inetorgperson.schema"
9+
schema "/etc/ldap/nis.schema"
10+
schema "/etc/ldap/excision.schema"
11+
12+
{% for domain in ldap_domains %}
13+
namespace "dc={{ domain.name }},dc={{ domain.tld }}" {
14+
rootdn "cn={{ domain.admin | default(ldap_admin) }},dc={{ domain.name }},dc={{ domain.tld }}"
15+
rootpw "{CRYPT}{{ lookup('pipe', 'encrypt -b a ' + ( domain.passwd | default(ldap_rootpw) ) |quote ) }}"
16+
17+
{% for i in ldap_indexes %}
18+
index {{ i }}
19+
{% endfor %}
20+
21+
deny
22+
allow read access to subtree "{{ domain.name }}"
23+
allow bind access to children of "ou=users,{{ domain.name }}"
24+
allow write access to any attribute sshPublicKey by self
25+
deny to any attribute userPassword
26+
allow read access to any attribute userPassword by self
27+
allow write access to any attribute userPassword by self
28+
29+
# TODO: need a way for user's to change their own password, but there's nothing
30+
# stopping them from writing a plain text password into their entry.
31+
#
32+
# Solution is probably a service user with write access to all userPassword
33+
# entries which writes a new {CRYPT} string after verifying a bind with the
34+
# user's old password.
35+
36+
{% for user in (domain.admin_users | default([])) %}
37+
allow to any by "uid={{ user }},ou=users,{{ domain.name }}"
38+
{% endfor %}
39+
}
40+
41+
{% endfor %}
42+
43+
include "/etc/ldapd_after.conf"

0 commit comments

Comments
 (0)