pyceo/.drone/auth1-setup.sh

109 lines
3.3 KiB
Bash
Raw Normal View History

2021-08-20 14:17:00 -04:00
#!/bin/bash
set -ex
. .drone/common.sh
2021-08-20 14:17:00 -04:00
# set FQDN in /etc/hosts
2021-08-21 02:27:33 -04:00
add_fqdn_to_hosts $(get_ip_addr $(hostname)) auth1
2021-08-20 14:17:00 -04:00
2021-09-10 22:41:07 -04:00
if [ -n "$CI" ]; then
# I'm not sure why, but we also need to remove the hosts entry for the
# container's real hostname, otherwise slapd only looks for the principal
# ldap/<container hostname> (this is with the sasl-host option)
sed -E "/\\b$(hostname)\\b/d" /etc/hosts > /tmp/hosts
cat /tmp/hosts > /etc/hosts
rm /tmp/hosts
fi
2021-08-20 14:17:00 -04:00
export DEBIAN_FRONTEND=noninteractive
apt update
apt install -y psmisc
2021-09-09 20:13:39 -04:00
# If we don't do this then OpenLDAP uses a lot of RAM
ulimit -n 1024
2021-08-20 14:17:00 -04:00
# LDAP
apt install -y --no-install-recommends slapd ldap-utils libnss-ldapd sudo-ldap
# `service slapd stop` doesn't seem to work
killall slapd || true
service nslcd stop || true
rm -rf /etc/ldap/slapd.d
rm /var/lib/ldap/*
cp /usr/share/slapd/DB_CONFIG /var/lib/ldap/DB_CONFIG
cp .drone/slapd.conf /etc/ldap/slapd.conf
cp .drone/ldap.conf /etc/ldap/ldap.conf
cp /usr/share/doc/sudo-ldap/schema.OpenLDAP /etc/ldap/schema/sudo.schema
cp .drone/rfc2307bis.schema /etc/ldap/schema/
cp .drone/csc.schema /etc/ldap/schema/
chown -R openldap:openldap /etc/ldap/schema/ /var/lib/ldap/ /etc/ldap/
sleep 0.5 && service slapd start
grep -Eq '^map group member uniqueMember$' /etc/nslcd.conf || \
echo 'map group member uniqueMember' >> /etc/nslcd.conf
sed -E -i 's/^uri .*$/uri ldap:\/\/auth1.csclub.internal/' /etc/nslcd.conf
sed -E -i 's/^base .*$/base dc=csclub,dc=internal/' /etc/nslcd.conf
cp .drone/nsswitch.conf /etc/nsswitch.conf
service nslcd start
ldapadd -c -f .drone/data.ldif -Y EXTERNAL -H ldapi:///
2021-09-09 20:13:39 -04:00
if [ -z "$CI" ]; then
2021-09-17 22:29:34 -04:00
ldapadd -c -f .drone/uwldap_data.ldif -Y EXTERNAL -H ldapi:/// || true
# setup ldapvi for convenience
apt install -y vim ldapvi
echo 'export EDITOR=vim' >> /root/.bashrc
echo 'alias ldapvi="ldapvi -Y EXTERNAL -h ldapi:///"' >> /root/.bashrc
2021-09-09 20:13:39 -04:00
fi
2021-08-20 14:17:00 -04:00
# KERBEROS
apt install -y krb5-admin-server krb5-user libpam-krb5 libsasl2-modules-gssapi-mit sasl2-bin
service krb5-admin-server stop || true
service krb5-kdc stop || true
service saslauthd stop || true
cp .drone/krb5.conf /etc/krb5.conf
cp .drone/kdc.conf /etc/krb5kdc.conf
echo '*/admin *' > /etc/krb5kdc/kadm5.acl
rm -f /var/lib/krb5kdc/*
echo -e 'krb5\nkrb5' | krb5_newrealm
service krb5-kdc start
service krb5-admin-server start
rm -f /etc/krb5.keytab
cat <<EOF | kadmin.local
addpol -minlength 4 default
addprinc -pw krb5 sysadmin/admin
addprinc -pw krb5 ctdalek
2021-09-10 18:29:32 -04:00
addprinc -pw krb5 exec1
2021-08-20 14:17:00 -04:00
addprinc -pw krb5 regular1
addprinc -randkey host/auth1.csclub.internal
addprinc -randkey ldap/auth1.csclub.internal
ktadd host/auth1.csclub.internal
ktadd ldap/auth1.csclub.internal
EOF
groupadd keytab || true
chgrp keytab /etc/krb5.keytab
chmod 640 /etc/krb5.keytab
usermod -a -G keytab openldap
usermod -a -G sasl openldap
cat <<EOF > /usr/lib/sasl2/slapd.conf
mech_list: plain login gssapi external
pwcheck_method: saslauthd
EOF
sed -E -i 's/^START=.*$/START=yes/' /etc/default/saslauthd
sed -E -i 's/^MECHANISMS=.*$/MECHANISMS="kerberos5"/' /etc/default/saslauthd
service saslauthd start
2021-09-10 18:29:32 -04:00
while true; do
killall slapd
sleep 1
if service slapd start; then
break
fi
done
2021-08-20 14:17:00 -04:00
apt install -y netcat-openbsd
2021-09-10 18:29:32 -04:00
# sync with phosphoric-acid
nc -l 0.0.0.0 9000 &
2021-09-09 23:21:22 -04:00
if [ -z "$CI" ]; then
2021-09-10 18:29:32 -04:00
# sync with coffee
nc -l 0.0.0.0 9001 &
2021-09-10 18:29:32 -04:00
# sync with mail
nc -l 0.0.0.0 9002 &
2021-09-09 23:21:22 -04:00
fi