forked from OpenStackCookbook/OpenStackCookbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ldap.sh
executable file
·83 lines (70 loc) · 2.1 KB
/
ldap.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
export DEBIAN_FRONTEND=noninteractive
source /vagrant/openrc
# Install OpenLDAP
echo -e " \
slapd slapd/internal/generated_adminpw password openstack
slapd slapd/password2 password openstack
slapd slapd/internal/adminpw password openstack
slapd slapd/password1 password openstack
" | sudo debconf-set-selections
sudo apt-get install -y slapd ldap-utils expect
# Check that it's working
sudo slapcat
# Let's pull tenants out of keystone, dump them into ldap
SUFFIX='dc=cook,dc=book'
LDIF='/tmp/cookbook.ldif'
echo -n > $LDIF
# Make our OUs
echo "dn: ou=Roles,$SUFFIX" >> $LDIF
echo "objectclass:organizationalunit" >> $LDIF
echo "ou: Roles" >> $LDIF
echo "description: generic groups branch" >> $LDIF
echo -e "\n" >> $LDIF
echo "dn: ou=Users,$SUFFIX" >> $LDIF
echo "objectclass:organizationalunit" >> $LDIF
echo "ou: Users" >> $LDIF
echo "description: generic groups branch" >> $LDIF
echo -e "\n" >> $LDIF
echo "dn: ou=Groups,$SUFFIX" >> $LDIF
echo "objectclass:organizationalunit" >> $LDIF
echo "ou: Groups" >> $LDIF
echo "description: generic groups branch" >> $LDIF
echo -e "\n" >> $LDIF
# Roles
for line in `keystone role-list | awk '($4 != "name") && ($4 != "") {print $4}'`
do
CN=$line
echo "dn: cn=$CN,ou=Roles,$SUFFIX" >> $LDIF
echo "objectClass: organizationalRole" >> $LDIF
echo "cn: $CN" >> $LDIF
echo -e "\n" >> $LDIF
done
# Users
for line in `keystone user-list | awk '($4 != "name") && ($4 != "") {print $4}'`
do
CN=$line
echo "dn: cn=$CN,ou=Users,$SUFFIX" >> $LDIF
echo "objectClass: inetOrgPerson" >> $LDIF
echo "cn: $CN" >> $LDIF
echo "sn: cookbook" >> $LDIF
echo -e "\n" >> $LDIF
done
# Tenants
for line in `keystone tenant-list | awk '($4 != "name") && ($4 != "") {print $4}'`
do
CN=$line
echo "dn: cn=$CN,ou=Groups,$SUFFIX" >> $LDIF
echo "objectClass: groupOfNames" >> $LDIF
echo "member: cn=admin,$SUFFIX" >> $LDIF
echo "cn: $CN" >> $LDIF
echo -e "\n" >> $LDIF
done
# Import those into LDAP
expect<<EOF
spawn ldapadd -x -D cn=admin,dc=cook,dc=book -W -f /tmp/cookbook.ldif
expect "Enter LDAP Password:"
send "openstack\n"
expect eof
EOF
# Configure Keystone for LDAP