0
|
1 |
# :mode=shellscript:
|
|
2 |
|
|
3 |
krb5_packages="krb5-admin-server krb5-kdc"
|
|
4 |
ldap_packages="slapd ldap-utils"
|
|
5 |
sasl_packages="sasl2-bin libsasl2-modules-gssapi-mit"
|
|
6 |
radius_packages="freeradius freeradius-ldap freeradius-common"
|
|
7 |
http_packages="apache2.2-bin libapache2-mod-php5 libapache2-webauth libapache2-webkdc webauth-weblogin php-pear"
|
|
8 |
|
|
9 |
patch_hosts_file()
|
|
10 |
{
|
|
11 |
sed -re '/^127\.0\.1\.1\s+/d' -i /etc/hosts
|
|
12 |
#sed -re '/^10\.0\.2\.2\s+/d' -i /etc/hosts
|
|
13 |
echo -e "127.0.1.1\tssoinabox.${domain}\tssoinabox" >> /etc/hosts
|
|
14 |
#echo -e "10.0.2.2\tsso-clients.${domain}\tssoinabox" >> /etc/hosts
|
|
15 |
|
|
16 |
echo -n "ssoinabox.$domain" > /etc/hostname
|
|
17 |
hostname `cat /etc/hostname`
|
|
18 |
}
|
|
19 |
|
|
20 |
generate_krb5_config()
|
|
21 |
{
|
|
22 |
cat <<EOF > /etc/krb5.conf
|
|
23 |
[libdefaults]
|
|
24 |
default_realm = $krb5_realm
|
|
25 |
dns_lookup_realm = false
|
|
26 |
dns_lookup_kdc = false
|
|
27 |
ticket_lifetime = 24h
|
|
28 |
forwardable = yes
|
|
29 |
|
|
30 |
[realms]
|
|
31 |
$krb5_realm = {
|
|
32 |
kdc = ssoinabox.$domain:88
|
|
33 |
admin_server = ssoinabox.$domain:749
|
|
34 |
kcrap = ssoinabox.$domain:1999
|
|
35 |
}
|
|
36 |
|
|
37 |
[domain_realm]
|
|
38 |
$domain = $krb5_realm
|
|
39 |
.$domain = $krb5_realm
|
|
40 |
|
|
41 |
[login]
|
|
42 |
krb4_convert = true
|
|
43 |
krb4_get_tickets = false
|
|
44 |
|
|
45 |
|
|
46 |
EOF
|
|
47 |
}
|
|
48 |
|
|
49 |
generate_slapd_config()
|
|
50 |
{
|
|
51 |
cat <<EOF > /etc/ldap/slapd.conf
|
|
52 |
# vim: set ft=conf
|
|
53 |
include /etc/ldap/schema/core.schema
|
|
54 |
include /etc/ldap/schema/cosine.schema
|
|
55 |
include /etc/ldap/schema/inetorgperson.schema
|
|
56 |
include /etc/ldap/schema/nis.schema
|
|
57 |
|
|
58 |
pidfile /var/run/slapd/slapd.pid
|
|
59 |
argsfile /var/run/slapd/slapd.args
|
|
60 |
|
|
61 |
# for replication
|
|
62 |
moduleload back_bdb.la
|
|
63 |
moduleload syncprov
|
|
64 |
|
|
65 |
disallow bind_anon
|
|
66 |
|
|
67 |
database bdb
|
|
68 |
suffix "$ldap_suffix"
|
|
69 |
|
|
70 |
authz-policy from
|
|
71 |
authz-regexp "^uid=([^,/]+)(,cn=${domain//\./\\.})?,cn=gssapi,cn=auth" "cn=\$1,ou=People,$ldap_suffix"
|
|
72 |
|
|
73 |
rootdn "cn=Manager,$ldap_suffix"
|
|
74 |
rootpw ${ldap_manager_pw_hash}
|
|
75 |
|
|
76 |
directory /var/lib/ldap
|
|
77 |
|
|
78 |
index objectClass eq
|
|
79 |
|
|
80 |
sasl-realm ${krb5_realm}
|
|
81 |
sasl-host ssoinabox.${domain}
|
|
82 |
sasl-secprops noplain,noactive,noanonymous
|
|
83 |
|
|
84 |
#TLSCACertificateFile /etc/ssl/certs/fixme.crt
|
|
85 |
#TLSCertificateFile /etc/ssl/certs/fixme.crt
|
|
86 |
#TLSCertificateKeyFile /etc/ssl/private/fixme.key
|
|
87 |
|
|
88 |
overlay syncprov
|
|
89 |
syncprov-checkpoint 100 10
|
|
90 |
syncprov-sessionlog 100
|
|
91 |
|
|
92 |
##
|
|
93 |
# ACLs
|
|
94 |
|
|
95 |
access to dn="cn=ldap-reader,ou=Roles,$ldap_suffix"
|
|
96 |
by anonymous auth
|
|
97 |
|
|
98 |
access to attrs=userPassword
|
|
99 |
by self =xw
|
|
100 |
by anonymous auth
|
|
101 |
by * none
|
|
102 |
|
|
103 |
access to *
|
|
104 |
by self write
|
|
105 |
by dn="cn=ldap-reader,ou=Roles,$ldap_suffix" read
|
|
106 |
by dn="cn=freeradius,ou=Roles,$ldap_suffix" read
|
|
107 |
by dn="cn=replicator,ou=Roles,$ldap_suffix" read
|
|
108 |
|
|
109 |
# Lock down attributes a user shouldn't change
|
|
110 |
access to attrs="loginShell,homeDirectory,uidNumber,gidNumber,uid,cn"
|
|
111 |
by self read
|
|
112 |
by dn="cn=replicator,ou=Roles,$ldap_suffix" read
|
|
113 |
by dn="cn=ldap-reader,ou=Roles,$ldap_suffix" read
|
|
114 |
|
|
115 |
access to *
|
|
116 |
by anonymous auth
|
|
117 |
by users read
|
|
118 |
|
|
119 |
EOF
|
|
120 |
}
|
|
121 |
|
|
122 |
generate_base_ldif()
|
|
123 |
{
|
|
124 |
domainbit=`echo $domain | cut -d. -f1`
|
|
125 |
gn="`echo $fullname | awk '{print \$1;}'`"
|
|
126 |
sn="`echo $fullname | awk '{print \$2;}'`"
|
|
127 |
cat <<EOF
|
|
128 |
dn: $ldap_suffix
|
|
129 |
objectClass: dcObject
|
|
130 |
objectClass: organization
|
|
131 |
o: $domain
|
|
132 |
dc: $domainbit
|
|
133 |
|
|
134 |
dn: cn=Manager,$ldap_suffix
|
|
135 |
cn: Manager
|
|
136 |
objectClass: top
|
|
137 |
objectClass: organizationalRole
|
|
138 |
description: LDAP admin entry with root level access to the server
|
|
139 |
|
|
140 |
dn: ou=People,$ldap_suffix
|
|
141 |
ou: People
|
|
142 |
objectClass: top
|
|
143 |
objectClass: organizationalUnit
|
|
144 |
description: User accounts representing people
|
|
145 |
|
|
146 |
dn: uid=$username,ou=People,$ldap_suffix
|
|
147 |
uid: $username
|
|
148 |
objectClass: top
|
|
149 |
objectClass: person
|
|
150 |
objectClass: inetOrgPerson
|
|
151 |
objectClass: organizationalPerson
|
|
152 |
objectClass: posixAccount
|
|
153 |
cn: $fullname
|
|
154 |
givenName: $gn
|
|
155 |
sn: $sn
|
|
156 |
loginShell: /bin/bash
|
|
157 |
homeDirectory: /home/users/$username
|
|
158 |
uidNumber: 501
|
|
159 |
gidNumber: 500
|
|
160 |
userPassword: {SASL}$username@$krb5_realm
|
|
161 |
|
|
162 |
dn: ou=Groups,$ldap_suffix
|
|
163 |
ou: Groups
|
|
164 |
objectClass: top
|
|
165 |
objectClass: organizationalUnit
|
|
166 |
description: POSIX user account groups
|
|
167 |
|
|
168 |
dn: cn=users,ou=Groups,$ldap_suffix
|
|
169 |
cn: users
|
|
170 |
objectClass: top
|
|
171 |
objectClass: posixGroup
|
|
172 |
description: Default POSIX group for users
|
|
173 |
gidNumber: 500
|
3
|
174 |
memberUid: $username
|
0
|
175 |
|
|
176 |
dn: cn=rtp,ou=Groups,$ldap_suffix
|
|
177 |
cn: rtp
|
|
178 |
objectClass: top
|
|
179 |
objectClass: posixGroup
|
|
180 |
description: POSIX group for people with root access to servers
|
|
181 |
gidNumber: 501
|
|
182 |
memberUid: $username
|
|
183 |
|
|
184 |
dn: ou=Roles,$ldap_suffix
|
|
185 |
ou: Roles
|
|
186 |
objectClass: top
|
|
187 |
objectClass: organizationalUnit
|
|
188 |
description: User accounts representing bots or other administrative functions
|
|
189 |
|
|
190 |
dn: cn=ldap-reader,ou=Roles,$ldap_suffix
|
|
191 |
cn: ldap-reader
|
|
192 |
objectClass: top
|
|
193 |
objectClass: organizationalRole
|
|
194 |
objectClass: simpleSecurityObject
|
|
195 |
description: Low-security account used for read-only LDAP access by NSS clients
|
|
196 |
userPassword: $ldap_reader_pw
|
|
197 |
|
|
198 |
|
|
199 |
EOF
|
|
200 |
}
|
|
201 |
|
|
202 |
configure_saslauthd()
|
|
203 |
{
|
|
204 |
sed -re 's/^START=no$/START=yes/' \
|
|
205 |
-e 's/^MECHANISMS=".+"$/MECHANISMS="kerberos5"/' \
|
|
206 |
-i /etc/default/saslauthd
|
|
207 |
}
|
|
208 |
|
|
209 |
generate_password()
|
|
210 |
{
|
|
211 |
local length="${1:-64}"
|
|
212 |
dd if=/dev/urandom bs=2048 count=1 2>/dev/null | tr -dc 'A-Za-z0-9' | cut -c 1-$length
|
|
213 |
}
|
|
214 |
|
|
215 |
build_kcrap()
|
|
216 |
{
|
|
217 |
oldcwd="`pwd`"
|
|
218 |
tempdir=`mktemp -d /tmp/kcrapXXXXXX`
|
|
219 |
cd "$tempdir"
|
|
220 |
wget https://aur.archlinux.org/packages/kc/kcrap/kcrap.tar.gz
|
|
221 |
tar xzvf kcrap.tar.gz
|
|
222 |
cd kcrap
|
|
223 |
mkdir pkg src
|
|
224 |
export srcdir="$PWD/src"
|
|
225 |
export pkgdir="$PWD/pkg"
|
|
226 |
. PKGBUILD
|
|
227 |
wget "${source[0]}"
|
|
228 |
for f in ${source[@]}; do
|
|
229 |
f=`basename $f`
|
|
230 |
ln -sf ../$f src/$f
|
|
231 |
done
|
|
232 |
cd "${srcdir}"
|
|
233 |
for f in *.tar.bz2; do
|
|
234 |
tar xjf $f
|
|
235 |
done
|
|
236 |
patch -p0 -i "$oldcwd/patches/kcrap-0.2.3-ntlm-extra.patch.patch"
|
|
237 |
cd kcrap-0.2.3
|
|
238 |
patch -p1 -i "$oldcwd/patches/kcrapclient.patch"
|
|
239 |
cd ..
|
|
240 |
build
|
|
241 |
make install
|
|
242 |
cp -v "test/kcrapclient" "/usr/local/bin/"
|
|
243 |
cd "$oldcwd" && rm -rf "$tempdir"
|
|
244 |
|
|
245 |
echo "/usr/local/lib" > /etc/ld.so.conf.d/usrlocal.conf
|
|
246 |
ldconfig
|
|
247 |
}
|
|
248 |
|
|
249 |
configure_kcrap()
|
|
250 |
{
|
|
251 |
cat <<EOF > /etc/kcrap_server.conf
|
|
252 |
[kcrap_server]
|
|
253 |
port = 1999
|
|
254 |
realm = $krb5_realm
|
|
255 |
|
|
256 |
[realms]
|
|
257 |
$krb5_realm = {
|
|
258 |
database_name = /var/lib/krb5kdc/principal
|
|
259 |
key_stash_file = /etc/krb5kdc/stash
|
|
260 |
}
|
|
261 |
|
|
262 |
EOF
|
|
263 |
}
|
|
264 |
|
|
265 |
configure_freerad()
|
|
266 |
{
|
|
267 |
# mschap module needs to use our ntlm_auth program for auth requests
|
|
268 |
sed -re 's/^#?(\s*)ntlm_auth = ".+"$/\1ntlm_auth = "\/usr\/local\/bin\/kcrapclient %{%{Stripped-User-Name}:-%{%{User-Name}:-None}} %{%{mschap:Challenge}:-00} %{%{mschap:NT-Response}:-00}"/' \
|
|
269 |
-i /etc/freeradius/modules/mschap
|
|
270 |
|
|
271 |
# configure ldap module with our settings
|
|
272 |
sed -re 's/^(\s*)#?server = ".+"$/\1server = "ssoinabox.'$domain'"/' \
|
|
273 |
-e 's/^(\s*)#?identity = ".+"$/\1identity = "cn=ldap-reader,ou=Roles,'$ldap_suffix'"/' \
|
|
274 |
-e 's/^(\s*)#?password = .+$/\1password = "'$ldap_reader_pw'"/' \
|
|
275 |
-e 's/^(\s*)#?basedn = ".+"$/\1basedn = "'$ldap_suffix'"/' \
|
|
276 |
-i /etc/freeradius/modules/ldap
|
|
277 |
|
|
278 |
# enable ldap for authorization and authentication
|
|
279 |
for site in default inner-tunnel; do
|
|
280 |
sed -rf `dirname $0`/resources/freerad-site-patcher.sed \
|
|
281 |
-i /etc/freeradius/sites-available/$site
|
|
282 |
done
|
|
283 |
|
|
284 |
# give freerad access to the kerberos keytab
|
|
285 |
setfacl -m u:freerad:r /etc/krb5.keytab
|
|
286 |
}
|
|
287 |
|
|
288 |
test_freerad()
|
|
289 |
{
|
|
290 |
build_eapol_test > /dev/null
|
|
291 |
set +e
|
|
292 |
echo -n "Testing RADIUS auth via EAP/TTLS/PAP..."
|
|
293 |
conf=`mktemp /tmp/frXXXXXX`
|
|
294 |
cat <<EOF > $conf
|
|
295 |
network={
|
|
296 |
ssid="example"
|
|
297 |
key_mgmt=WPA-EAP
|
|
298 |
eap=TTLS
|
|
299 |
anonymous_identity="$username"
|
|
300 |
identity="$username"
|
|
301 |
password="$password"
|
|
302 |
phase2="auth=PAP"
|
|
303 |
}
|
|
304 |
|
|
305 |
EOF
|
|
306 |
if /usr/local/bin/eapol_test -s testing123 -c "$conf" 2>&1 > /dev/null; then
|
|
307 |
echo "GOOD"
|
|
308 |
else
|
|
309 |
echo "BAD"
|
|
310 |
fi
|
|
311 |
echo -n "Testing RADIUS auth via PEAP/MSCHAPv2..."
|
|
312 |
cat <<EOF > $conf
|
|
313 |
network={
|
|
314 |
ssid="example"
|
|
315 |
key_mgmt=WPA-EAP
|
|
316 |
eap=PEAP
|
|
317 |
anonymous_identity="$username"
|
|
318 |
identity="$username"
|
|
319 |
password="$password"
|
|
320 |
phase2="autheap=MSCHAPv2"
|
|
321 |
}
|
|
322 |
|
|
323 |
EOF
|
|
324 |
if /usr/local/bin/eapol_test -s testing123 -c "$conf" 2>&1 > /dev/null; then
|
|
325 |
echo "GOOD"
|
|
326 |
else
|
|
327 |
echo "BAD"
|
|
328 |
fi
|
|
329 |
rm -f $conf
|
|
330 |
set -e
|
|
331 |
}
|
|
332 |
|
|
333 |
generate_web_yaml()
|
|
334 |
{
|
|
335 |
test -d /usr/local/etc/ssoinabox || mkdir -p /usr/local/etc/ssoinabox
|
|
336 |
cat <<EOF > /usr/local/etc/ssoinabox/webcreds.yml
|
|
337 |
LDAP_BASEDN: $ldap_suffix
|
|
338 |
|
|
339 |
UID_MIN: 501
|
|
340 |
GID_MIN: 500
|
|
341 |
|
|
342 |
ldap_server: ldap://localhost:389/
|
|
343 |
ldap_manager:
|
|
344 |
dn: cn=Manager,$ldap_suffix
|
|
345 |
password: $ldap_manager_pw
|
|
346 |
|
|
347 |
ldap_user_basedn: ou=People,$ldap_suffix
|
|
348 |
ldap_group_basedn: ou=Groups,$ldap_suffix
|
|
349 |
|
|
350 |
kerberos_admin:
|
|
351 |
principal: webkerb/admin
|
|
352 |
password: $webkerb_pw
|
|
353 |
|
|
354 |
PHONE_EXT_MIN: 500
|
|
355 |
|
3
|
356 |
hmac_secret: `generate_password 40`
|
|
357 |
|
0
|
358 |
EOF
|
|
359 |
|
|
360 |
chown root:www-data /usr/local/etc/ssoinabox/webcreds.yml
|
|
361 |
chmod 640 /usr/local/etc/ssoinabox/webcreds.yml
|
|
362 |
}
|
|
363 |
|
|
364 |
configure_webkdc()
|
|
365 |
{
|
|
366 |
cat <<EOF > /etc/webkdc/webkdc.conf
|
|
367 |
our \$KEYRING_PATH = '/var/lib/webkdc/keyring';
|
|
368 |
our \$TEMPLATE_PATH = '/usr/local/share/weblogin/ssoinabox/templates';
|
|
369 |
our \$TEMPLATE_COMPILE_PATH = '/var/cache/weblogin';
|
|
370 |
our \$URL = 'http://ssoinabox/webkdc-service';
|
|
371 |
our \$BYPASS_CONFIRM = 1;
|
|
372 |
|
|
373 |
EOF
|
|
374 |
|
|
375 |
cat <<EOF > /etc/webkdc/token.acl
|
|
376 |
krb5:webauth/*@$krb5_realm id
|
|
377 |
|
|
378 |
EOF
|
|
379 |
|
|
380 |
test -f /etc/webkdc/keytab && rm -f /etc/webkdc/keytab
|
|
381 |
kadmin.local -q "ank -randkey service/webkdc"
|
|
382 |
kadmin.local -q "ktadd -norandkey -k /etc/webkdc/keytab service/webkdc"
|
|
383 |
|
|
384 |
chown root:www-data /etc/webkdc/keytab
|
|
385 |
chmod 640 /etc/webkdc/keytab
|
|
386 |
}
|
|
387 |
|
|
388 |
configure_webauth()
|
|
389 |
{
|
|
390 |
cat <<EOF > /etc/apache2/conf.d/webauth
|
|
391 |
WebAuthWebKdcPrincipal service/webkdc
|
|
392 |
WebAuthLoginURL "http://ssoinabox.$domain/login"
|
|
393 |
WebAuthWebKdcURL "http://ssoinabox.$domain/webkdc-service"
|
|
394 |
WebAuthSSLRedirect off
|
|
395 |
WebAuthRequireSSL off
|
|
396 |
WebAuthDebug on
|
|
397 |
|
|
398 |
EOF
|
|
399 |
|
|
400 |
test -f /etc/webauth/keytab && rm -f /etc/webauth/keytab
|
|
401 |
kadmin.local -q "ank -randkey webauth/ssoinabox.$domain"
|
|
402 |
kadmin.local -q "ktadd -norandkey -k /etc/webauth/keytab webauth/ssoinabox.$domain"
|
|
403 |
|
|
404 |
chown root:www-data /etc/webauth/keytab
|
|
405 |
chmod 640 /etc/webauth/keytab
|
|
406 |
|
|
407 |
# doesn't exist by default...?
|
|
408 |
# chown www-data:www-data /var/lib/webauth/keyring
|
|
409 |
}
|
|
410 |
|
|
411 |
configure_apache2()
|
|
412 |
{
|
|
413 |
cp `dirname $0`/resources/apache2-site.conf /etc/apache2/sites-available/ssoinabox
|
|
414 |
sed -re "s/^(\s*)ServerName .+$/\1ServerName ssoinabox.$domain/" -i /etc/apache2/sites-available/ssoinabox
|
|
415 |
|
|
416 |
a2ensite ssoinabox
|
|
417 |
a2dissite default
|
|
418 |
}
|
|
419 |
|
|
420 |
build_kadm5()
|
|
421 |
{
|
|
422 |
test -d tarballs || mkdir tarballs
|
|
423 |
test -f tarballs/kadm5.tar.gz || wget -O tarballs/kadm5.tar.gz http://pecl.php.net/get/kadm5
|
|
424 |
oldcwd="`pwd`"
|
|
425 |
tempdir=`mktemp -d /tmp/kadm5XXXXXX`
|
|
426 |
cd $tempdir
|
|
427 |
|
|
428 |
tar xzf "$oldcwd/tarballs/kadm5.tar.gz"
|
|
429 |
cd kadm5-*
|
|
430 |
patch -p1 -i "$oldcwd/patches/kadm5.patch"
|
|
431 |
phpize
|
|
432 |
./configure
|
|
433 |
make
|
|
434 |
make install
|
|
435 |
|
|
436 |
cd "$oldcwd" && rm -rf "$tempdir"
|
|
437 |
echo "extension=kadm5.so" > /etc/php5/conf.d/kadm5.ini
|
|
438 |
}
|
|
439 |
|
|
440 |
build_eapol_test()
|
|
441 |
{
|
|
442 |
test -x /usr/local/bin/eapol_test && return 0
|
|
443 |
|
|
444 |
test -d tarballs || mkdir tarballs
|
|
445 |
test -f tarballs/wpa_supplicant-1.1.tar.gz || wget -O tarballs/wpa_supplicant-1.1.tar.gz "http://hostap.epitest.fi/releases/wpa_supplicant-1.1.tar.gz"
|
|
446 |
|
|
447 |
oldcwd="`pwd`"
|
|
448 |
tempdir=`mktemp -d /tmp/wpasXXXXXX`
|
|
449 |
cd $tempdir
|
|
450 |
|
|
451 |
tar xzf "$oldcwd/tarballs/wpa_supplicant-1.1.tar.gz"
|
|
452 |
cd wpa_supplicant-1.1/wpa_supplicant
|
|
453 |
cp defconfig .config
|
|
454 |
sed -re 's/^#?CONFIG_EAPOL_TEST=.+$/CONFIG_EAPOL_TEST=y/' -i .config
|
|
455 |
make eapol_test
|
|
456 |
cp -v eapol_test /usr/local/bin/
|
|
457 |
|
|
458 |
cd "$oldcwd" && rm -rf "$tempdir"
|
|
459 |
}
|