2014-07-19 16:31:05 +00:00
|
|
|
#!/bin/bash
|
2014-10-04 21:57:26 +00:00
|
|
|
# DNS
|
2014-09-21 17:43:21 +00:00
|
|
|
# -----------------------------------------------
|
2013-09-01 14:13:51 +00:00
|
|
|
|
2014-06-13 00:18:53 +00:00
|
|
|
# This script installs packages, but the DNS zone files are only
|
|
|
|
# created by the /dns/update API in the management server because
|
|
|
|
# the set of zones (domains) hosted by the server depends on the
|
|
|
|
# mail users & aliases created by the user later.
|
2013-09-01 14:13:51 +00:00
|
|
|
|
2014-06-03 11:12:38 +00:00
|
|
|
source setup/functions.sh # load our functions
|
2014-10-08 12:48:43 +00:00
|
|
|
source /etc/mailinabox.conf # load global vars
|
2014-05-01 19:13:00 +00:00
|
|
|
|
2014-09-21 17:43:21 +00:00
|
|
|
# Install `nsd`, our DNS server software, and `ldnsutils` which helps
|
2014-06-17 22:21:12 +00:00
|
|
|
# us sign zones for DNSSEC.
|
2013-08-21 20:53:22 +00:00
|
|
|
|
2014-04-23 21:53:59 +00:00
|
|
|
# ...but first, we have to create the user because the
|
|
|
|
# current Ubuntu forgets to do so in the .deb
|
2014-10-04 21:57:26 +00:00
|
|
|
# (see issue #25 and https://bugs.launchpad.net/ubuntu/+source/nsd/+bug/1311886)
|
2014-04-23 21:53:59 +00:00
|
|
|
if id nsd > /dev/null 2>&1; then
|
2014-10-04 21:57:26 +00:00
|
|
|
true #echo "nsd user exists... good"; #NODOC
|
2014-04-23 21:53:59 +00:00
|
|
|
else
|
|
|
|
useradd nsd;
|
2014-04-23 22:40:33 +00:00
|
|
|
fi
|
|
|
|
|
2014-06-13 00:18:53 +00:00
|
|
|
# Okay now install the packages.
|
2014-08-27 12:56:17 +00:00
|
|
|
#
|
2014-09-21 17:43:21 +00:00
|
|
|
# * nsd: The non-recursive nameserver that publishes our DNS records.
|
|
|
|
# * ldnsutils: Helper utilities for signing DNSSEC zones.
|
|
|
|
# * openssh-client: Provides ssh-keyscan which we use to create SSHFP records.
|
2014-04-23 22:40:33 +00:00
|
|
|
|
2014-08-27 12:56:17 +00:00
|
|
|
apt_install nsd ldnsutils openssh-client
|
2013-08-21 20:53:22 +00:00
|
|
|
|
2014-04-18 00:17:24 +00:00
|
|
|
# Prepare nsd's configuration.
|
2013-09-01 14:13:51 +00:00
|
|
|
|
2014-10-04 18:06:08 +00:00
|
|
|
mkdir -p /var/run/nsd
|
2013-09-01 14:13:51 +00:00
|
|
|
|
2014-06-17 22:21:12 +00:00
|
|
|
# Create DNSSEC signing keys.
|
|
|
|
|
|
|
|
mkdir -p "$STORAGE_ROOT/dns/dnssec";
|
2014-10-04 17:29:42 +00:00
|
|
|
|
|
|
|
# TLDs don't all support the same algorithms, so we'll generate keys using a few
|
2014-10-13 14:00:26 +00:00
|
|
|
# different algorithms. RSASHA1-NSEC3-SHA1 was possibly the first widely used
|
|
|
|
# algorithm that supported NSEC3, which is a security best practice. However TLDs
|
|
|
|
# will probably be moving away from it to a a SHA256-based algorithm.
|
2014-10-04 17:29:42 +00:00
|
|
|
#
|
2014-10-04 21:57:26 +00:00
|
|
|
# Supports `RSASHA1-NSEC3-SHA1` (didn't test with `RSASHA256`):
|
2014-10-04 17:29:42 +00:00
|
|
|
#
|
2014-10-04 21:57:26 +00:00
|
|
|
# * .info
|
|
|
|
# * .me
|
|
|
|
#
|
|
|
|
# Requires `RSASHA256`
|
|
|
|
#
|
|
|
|
# * .email
|
|
|
|
|
|
|
|
FIRST=1 #NODOC
|
2014-10-04 17:29:42 +00:00
|
|
|
for algo in RSASHA1-NSEC3-SHA1 RSASHA256; do
|
|
|
|
if [ ! -f "$STORAGE_ROOT/dns/dnssec/$algo.conf" ]; then
|
|
|
|
if [ $FIRST == 1 ]; then
|
|
|
|
echo "Generating DNSSEC signing keys. This may take a few minutes..."
|
2014-10-04 21:57:26 +00:00
|
|
|
FIRST=0 #NODOC
|
2014-10-04 17:29:42 +00:00
|
|
|
fi
|
2014-06-17 22:21:12 +00:00
|
|
|
|
2014-10-13 14:00:26 +00:00
|
|
|
# Create the Key-Signing Key (KSK) (with `-k`) which is the so-called
|
|
|
|
# Secure Entry Point. The domain name we provide ("_domain_") doesn't
|
|
|
|
# matter -- we'll use the same keys for all our domains.
|
2014-10-04 21:57:26 +00:00
|
|
|
#
|
|
|
|
# `ldns-keygen` outputs the new key's filename to stdout, which
|
|
|
|
# we're capturing into the `KSK` variable.
|
2014-10-04 17:29:42 +00:00
|
|
|
KSK=$(umask 077; cd $STORAGE_ROOT/dns/dnssec; ldns-keygen -a $algo -b 2048 -k _domain_);
|
2014-06-17 22:21:12 +00:00
|
|
|
|
|
|
|
# Now create a Zone-Signing Key (ZSK) which is expected to be
|
|
|
|
# rotated more often than a KSK, although we have no plans to
|
|
|
|
# rotate it (and doing so would be difficult to do without
|
2014-10-13 14:00:26 +00:00
|
|
|
# disturbing DNS availability.) Omit `-k` and use a shorter key length.
|
2014-10-04 17:29:42 +00:00
|
|
|
ZSK=$(umask 077; cd $STORAGE_ROOT/dns/dnssec; ldns-keygen -a $algo -b 1024 _domain_);
|
2014-06-17 22:21:12 +00:00
|
|
|
|
|
|
|
# These generate two sets of files like:
|
2014-09-21 17:43:21 +00:00
|
|
|
#
|
2014-10-13 14:00:26 +00:00
|
|
|
# * `K_domain_.+007+08882.ds`: DS record normally provided to domain name registrar (but it's actually invalid with `_domain_`)
|
|
|
|
# * `K_domain_.+007+08882.key`: public key
|
2014-09-21 17:43:21 +00:00
|
|
|
# * `K_domain_.+007+08882.private`: private key (secret!)
|
2014-06-17 22:21:12 +00:00
|
|
|
|
|
|
|
# The filenames are unpredictable and encode the key generation
|
|
|
|
# options. So we'll store the names of the files we just generated.
|
|
|
|
# We might have multiple keys down the road. This will identify
|
|
|
|
# what keys are the current keys.
|
2014-10-04 17:29:42 +00:00
|
|
|
cat > $STORAGE_ROOT/dns/dnssec/$algo.conf << EOF;
|
2014-06-17 22:21:12 +00:00
|
|
|
KSK=$KSK
|
|
|
|
ZSK=$ZSK
|
|
|
|
EOF
|
|
|
|
fi
|
2014-10-04 21:57:26 +00:00
|
|
|
|
|
|
|
# And loop to do the next algorithm...
|
2014-10-04 17:29:42 +00:00
|
|
|
done
|
2014-06-17 22:21:12 +00:00
|
|
|
|
2014-10-04 21:57:26 +00:00
|
|
|
# Force the dns_update script to be run every day to re-sign zones for DNSSEC
|
|
|
|
# before they expire. When we sign zones (in `dns_update.py`) we specify a
|
|
|
|
# 30-day validation window, so we had better re-sign before then.
|
2014-06-17 22:21:12 +00:00
|
|
|
cat > /etc/cron.daily/mailinabox-dnssec << EOF;
|
2014-07-25 12:15:30 +00:00
|
|
|
#!/bin/bash
|
2014-06-17 22:21:12 +00:00
|
|
|
# Mail-in-a-Box
|
|
|
|
# Re-sign any DNS zones with DNSSEC because the signatures expire periodically.
|
2014-07-19 16:31:05 +00:00
|
|
|
`pwd`/tools/dns_update
|
2014-06-17 22:21:12 +00:00
|
|
|
EOF
|
|
|
|
chmod +x /etc/cron.daily/mailinabox-dnssec
|
|
|
|
|
2013-09-01 14:13:51 +00:00
|
|
|
# Permit DNS queries on TCP/UDP in the firewall.
|
2013-08-21 20:53:22 +00:00
|
|
|
|
2014-05-01 19:35:18 +00:00
|
|
|
ufw_allow domain
|
2013-08-21 20:53:22 +00:00
|
|
|
|