-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathldap-server-install.sh
300 lines (224 loc) · 9.19 KB
/
ldap-server-install.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#!/bin/bash
#ldap server-sdie install script -- run as root
#install git
echo "Installing git..."
yum -y install git
echo "Cloning jwade005's NTI-310 GitHub..."
git clone https://github.com/grantypantyyy/NTI-310-GG.git /tmp/NTI-310
#install ldap
echo "Installing openldap-servers... openldap-clients..."
yum -y install openldap-servers openldap-clients
#copy db config, change ownership
echo "Copying config file and adjusting permissions..."
cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
chown ldap /var/lib/ldap/DB_CONFIG
#enable and start ldap
echo "Enabling and Starting the slapd service..."
systemctl enable slapd
systemctl start slapd
#install apache
echo "Installing apache..."
yum -y install httpd
#enable and start apache
echo "Enabling and starting the httpd service..."
systemctl enable httpd
systemctl start httpd
#install phpldapadmin
echo "Installin the epel-release repo..."
yum -y install epel-release
echo "Installing phpldapadmin..."
yum -y install phpldapadmin
#allow http connection to ldap
echo "Allowing ldap to use httpd..."
setsebool -P httpd_can_connect_ldap on
sleep 5
#generate new hashed password for db.ldif and store it on the server
newsecret=$(slappasswd -g)
newhash=$(slappasswd -s "$newsecret")
echo -n "$newsecret" > /root/ldap_admin_pass
chmod 600 /root/ldap_admin_pass
#copy db.ldif and add to config
echo "echo db.ldif and adding it to ldap configuration..."
#cp /tmp/NTI-310/config_scripts/db.ldif /etc/openldap/slapd.d/db.ldif
echo "dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcSuffix
olcSuffix: dc=grant,dc=local
dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcRootDN
olcRootDN: cn=ldapadm,dc=grant,dc=local
dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcRootPW
olcRootPW: $newhash" >> /etc/openldap/slapd.d/db.ldif
ldapmodify -Y EXTERNAL -H ldapi:/// -f /etc/openldap/slapd.d/db.ldif
sleep 5
#copy monitor.ldif and add to config
echo "Copying monitor.ldif, adjusting ownership, and adding it to ldap configuration..."
cp /tmp/NTI-310/monitor.ldif /etc/openldap/slapd.d/monitor.ldif
chown ldap /etc/openldap/slapd.d/monitor.ldif
ldapmodify -Y EXTERNAL -H ldapi:/// -f /etc/openldap/slapd.d/monitor.ldif
sleep 5
#create ldap cert and keyout
openssl req -new -x509 -nodes -out /etc/openldap/certs/grantldapcert.pem -newkey rsa:2048 -keyout /etc/openldap/certs/grantldapkey.pem -days 365 -subj "/C=US/ST=WA/L=Seattle/O=IT/OU=NTI310IT/CN=grant.local"
chown -R ldap /etc/openldap/certs/nti*.pem
#copy cert ldif and add to config
echo "Copying cert.ldif and adding it to ldap configuration..."
cp /tmp/NTI-310/certs.ldif /etc/openldap/slapd.d/certs.ldif
ldapmodify -Y EXTERNAL -H ldapi:/// -f /etc/openldap/slapd.d/certs.ldif
#create apache-selfsigned cert
yum -y install mod_ssl
mkdir /etc/ssl/private
chmod 700 /etc/ssl/private
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/apache-selfsigned.key -subj "/C=US/ST=WA/L=Seattle/O=IT/OU=NTI310IT/CN=grant.local" -out /etc/ssl/certs/apache-selfsigned.crt
openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
cat /etc/ssl/certs/dhparam.pem | tee -a /etc/ssl/certs/apache-selfsigned.crt
#modify /etc/httpd/conf.d/ssl.conf
sed -i '/<VirtualHost _default_:443>/a Alias \/phpldapadmin \/usr\/share\/phpldapadmin\/htdocs' /etc/httpd/conf.d/ssl.conf
sed -i '/Alias \/phpldapadmin \/usr\/share\/phpldapadmin\/htdocs/a Alias \/ldapadmin \/usr\/share\/phpldapadmin\/htdocs' /etc/httpd/conf.d/ssl.conf
sed -i '/Alias \/ldapadmin \/usr\/share\/phpldapadmin\/htdocs/a DocumentRoot \"\/usr\/share\/phpldapadmin\/htdocs\"' /etc/httpd/conf.d/ssl.conf
sed -i '/DocumentRoot \"\/usr\/share\/phpldapadmin\/htdocs\"/a ServerName grant.local:443' /etc/httpd/conf.d/ssl.conf
#update cypher suite
sed -i "s/SSLProtocol all -SSLv2/#SSLProtocol all -SSLv2/g" /etc/httpd/conf.d/ssl.conf
sed -i "s/SSLCipherSuite HIGH:MEDIUM:\!aNULL:\!MD5:\!SEED:\!IDEA/#SSLCipherSuite HIGH:MEDIUM:\!aNULL:\!MD5:\!SEED:\!IDEA/g" /etc/httpd/conf.d/ssl.conf
cat <<EOT>> /etc/httpd/conf.d/ssl.conf
# Begin copied text
# from https://cipherli.st/
# and https://raymii.org/s/tutorials/Strong_SSL_Security_On_Apache2.html
SSLCipherSuite EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH
SSLProtocol All -SSLv2 -SSLv3
SSLHonorCipherOrder On
# Disable preloading HSTS for now. You can use the commented out header line that includes
# the "preload" directive if you understand the implications.
#Header always set Strict-Transport-Security "max-age=63072000; includeSubdomains; preload"
Header always set Strict-Transport-Security "max-age=63072000; includeSubdomains"
Header always set X-Frame-Options DENY
Header always set X-Content-Type-Options nosniff
# Requires Apache >= 2.4
SSLCompression off
SSLUseStapling on
SSLStaplingCache "shmcb:logs/stapling-cache(150000)"
# Requires Apache >= 2.4.11
# SSLSessionTickets Off
EOT
#edit /etc/sysconfig/slapd
sed -i 's/SLAPD_URLS="ldapi:\/\/\/ ldap:\/\/\/"/SLAPD_URLS=\"ldapi:\/\/\/ ldap:\/\/\/ ldaps:\/\/\/"/g' /etc/sysconfig/slapd
#restart slapd
systemctl restart slapd
#restart the httpd service
systemctl restart httpd
#add the cosine and nis LDAP schemas
echo "Adding the cosine and nis schemas..."
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/cosine.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/nis.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/inetorgperson.ldif
#create base.ldif file for domain
echo "Copying the base.ldif file for the domain and adding it to ldap configuration..."
cp /tmp/NTI-310/base.ldif /etc/openldap/slapd.d/base.ldif
ldapadd -x -D "cn=ldapadm,dc=grant,dc=local" -f /etc/openldap/slapd.d/base.ldif -y /root/ldap_admin_pass
#add nti310 group
echo "# LDIF Export for cn=nti310,ou=Group,dc=jwade,dc=local
# Server: grant LDAP Server (127.0.0.1)
# Search Scope: base
# Search Filter: (objectClass=*)
# Total Entries: 1
#
# Generated by phpLDAPadmin (http://phpldapadmin.sourceforge.net) on February 19, 2017 2:35 pm
# Version: 1.2.3
version: 1
# Entry 1: cn=nti310,ou=Group,dc=grant,dc=local
dn: cn=nti310,ou=Group,dc=grant,dc=local
cn: nti310
gidnumber: 500
objectclass: posixGroup
objectclass: top
" >> /etc/openldap/slapd.d/nti310group.ldif
ldapadd -x -D "cn=ldapadm,dc=jwade,dc=local" -f /etc/openldap/slapd.d/nti310group.ldif -y /root/ldap_admin_pass
sleep 5
echo "# LDIF Export for cn=admin,ou=Group,dc=grant,dc=local
# Server: grant LDAP Server (127.0.0.1)
# Search Scope: base
# Search Filter: (objectClass=*)
# Total Entries: 1
#
# Generated by phpLDAPadmin (http://phpldapadmin.sourceforge.net) on February 19, 2017 2:35 pm
# Version: 1.2.3
version: 1
# Entry 1: cn=admin,ou=Group,dc=grant,dc=local
dn: cn=admin,ou=Group,dc=grant,dc=local
cn: admin
gidnumber: 501
objectclass: posixGroup
objectclass: top
" >> /etc/openldap/slapd.d/admin.ldif
ldapadd -x -D "cn=ldapadm,dc=grant,dc=local" -f /etc/openldap/slapd.d/admin.ldif -y /root/ldap_admin_pass
sleep 5
#add user jwade to ldap
echo "# LDIF Export for cn=jonathan wade,ou=People,dc=jwade,dc=local
# Server: grant LDAP Server (127.0.0.1)
# Search Scope: base
# Search Filter: (objectClass=*)
# Total Entries: 1
#
# Generated by phpLDAPadmin (http://phpldapadmin.sourceforge.net) on March 16, 2017 4:49 am
# Version: 1.2.3
version: 1
# Entry 1: cn=Grant Grismore,ou=People,dc=grant,dc=local
dn: cn=Grant Grismore,ou=People,dc=grant,dc=local
cn: grant grismore
gidnumber: 500
givenname: grant
homedirectory: /home/users/ggrism01
loginshell: /bin/sh
objectclass: inetOrgPerson
objectclass: posixAccount
objectclass: top
sn: wade
uid: ggrismore
uidnumber: 1001
userpassword: {MD5}i46XFdEuTKEsTD60hlqvag==" >> /etc/openldap/slapd.d/grant.ldif
ldapadd -x -D "cn=ldapadm,dc=jwade,dc=local" -f /etc/openldap/slapd.d/grant.ldif -y /root/ldap_admin_pass
sleep 5
#add user auser to ldap
echo "# LDIF Export for cn=adam user,ou=People,dc=grant,dc=local
# Server: grant LDAP Server (127.0.0.1)
# Search Scope: base
# Search Filter: (objectClass=*)
# Total Entries: 1
#
# Generated by phpLDAPadmin (http://phpldapadmin.sourceforge.net) on February 21, 2017 1:12 am
# Version: 1.2.3
version: 1
# Entry 1: cn=adam user,ou=People,dc=grant,dc=local
dn: cn=adam user,ou=People,dc=grant,dc=local
cn: adam user
gidnumber: 500
givenname: adam
homedirectory: /home/users/auser
loginshell: /bin/sh
objectclass: inetOrgPerson
objectclass: posixAccount
objectclass: top
sn: user
uid: auser
uidnumber: 1002
userpassword: {MD5}sPoJGPa5defWVEDhD+udWA==" >> /etc/openldap/slapd.d/auser.ldif
ldapadd -x -D "cn=ldapadm,dc=grant,dc=local" -f /etc/openldap/slapd.d/auser.ldif -y /root/ldap_admin_pass
sleep 5
#allow cn=xxx,dc=xxx,dc=xxx login
echo "Setting login to fqdn..."
cp -f /tmp/NTI-310/config.php /etc/phpldapadmin/config.php
#allow login from the web
echo "Making ldap htdocs accessible from the web..."
cp -f /tmp/NTI-310/phpldapadmin.conf /etc/httpd/conf.d/phpldapadmin.conf
#restart htttpd, slapd services
echo "Restarting the httpd and slapd services..."
systemctl restart httpd
systemctl restart slapd
#configure firewall to allow access
echo "Configuring the built-in firewall to allow access..."
firewall-cmd --permanent --add-port=636/tcp
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --reload
echo "ldap configuration complete. Point your browser to http://<serverIPaddress>/phpldapadmin to login..."