2014-06-03 11:12:38 +00:00
|
|
|
source setup/functions.sh # load our functions
|
2014-05-01 19:13:00 +00:00
|
|
|
|
2014-10-04 21:57:26 +00:00
|
|
|
# Basic System Configuration
|
2014-09-21 17:43:21 +00:00
|
|
|
# -------------------------
|
|
|
|
|
2014-10-04 21:57:26 +00:00
|
|
|
# ### Install Packages
|
2014-09-21 17:43:21 +00:00
|
|
|
|
2014-10-04 21:57:26 +00:00
|
|
|
# Update system packages to make sure we have the latest upstream versions of things from Ubuntu.
|
2013-08-21 02:27:32 +00:00
|
|
|
|
2014-07-16 13:06:45 +00:00
|
|
|
echo Updating system packages...
|
|
|
|
hide_output apt-get update
|
|
|
|
hide_output apt-get -y upgrade
|
2013-08-21 02:27:32 +00:00
|
|
|
|
2014-05-02 18:23:56 +00:00
|
|
|
# Install basic utilities.
|
2014-07-21 11:12:59 +00:00
|
|
|
#
|
2014-09-21 17:43:21 +00:00
|
|
|
# * haveged: Provides extra entropy to /dev/random so it doesn't stall
|
2014-07-21 11:12:59 +00:00
|
|
|
# when generating random numbers for private keys (e.g. during
|
|
|
|
# ldns-keygen).
|
2014-09-21 17:43:21 +00:00
|
|
|
# * unattended-upgrades: Apt tool to install security updates automatically.
|
|
|
|
# * ntp: keeps the system time correct
|
|
|
|
# * fail2ban: scans log files for repeated failed login attempts and blocks the remote IP at the firewall
|
2014-05-02 18:23:56 +00:00
|
|
|
|
2014-09-17 21:56:09 +00:00
|
|
|
apt_install python3 python3-dev python3-pip \
|
2014-09-07 12:09:37 +00:00
|
|
|
wget curl \
|
2014-08-23 12:31:33 +00:00
|
|
|
haveged unattended-upgrades ntp fail2ban
|
2014-03-16 20:50:24 +00:00
|
|
|
|
2014-08-23 12:31:33 +00:00
|
|
|
# Allow apt to install system updates automatically every day.
|
2013-08-21 02:27:32 +00:00
|
|
|
|
2014-08-23 12:31:33 +00:00
|
|
|
cat > /etc/apt/apt.conf.d/02periodic <<EOF;
|
|
|
|
APT::Periodic::MaxAge "7";
|
|
|
|
APT::Periodic::Update-Package-Lists "1";
|
|
|
|
APT::Periodic::Unattended-Upgrade "1";
|
|
|
|
APT::Periodic::Verbose "1";
|
|
|
|
EOF
|
2013-08-21 02:27:32 +00:00
|
|
|
|
2014-09-21 17:43:21 +00:00
|
|
|
# ### Firewall
|
2014-09-20 12:25:54 +00:00
|
|
|
|
2014-09-21 17:43:21 +00:00
|
|
|
# Various virtualized environments like Docker and some VPSs don't provide #NODOC
|
|
|
|
# a kernel that supports iptables. To avoid error-like output in these cases, #NODOC
|
|
|
|
# we skip this if the user sets DISABLE_FIREWALL=1. #NODOC
|
|
|
|
if [ -z "$DISABLE_FIREWALL" ]; then
|
|
|
|
# Install `ufw` which provides a simple firewall configuration.
|
2014-05-02 02:39:45 +00:00
|
|
|
apt_install ufw
|
2014-09-20 12:25:54 +00:00
|
|
|
|
2014-09-21 17:43:21 +00:00
|
|
|
# Allow incoming connections to SSH.
|
2014-05-02 02:39:45 +00:00
|
|
|
ufw_allow ssh;
|
2014-09-20 12:25:54 +00:00
|
|
|
|
2014-10-04 21:57:26 +00:00
|
|
|
# ssh might be running on an alternate port. Use sshd -T to dump sshd's #NODOC
|
|
|
|
# settings, find the port it is supposedly running on, and open that port #NODOC
|
|
|
|
# too. #NODOC
|
|
|
|
SSH_PORT=$(sshd -T 2>/dev/null | grep "^port " | sed "s/port //") #NODOC
|
2014-09-20 12:25:54 +00:00
|
|
|
if [ ! -z "$SSH_PORT" ]; then
|
2014-09-21 17:43:21 +00:00
|
|
|
if [ "$SSH_PORT" != "22" ]; then
|
|
|
|
|
2014-10-04 21:57:26 +00:00
|
|
|
echo Opening alternate SSH port $SSH_PORT. #NODOC
|
|
|
|
ufw_allow $SSH_PORT #NODOC
|
2014-09-21 17:43:21 +00:00
|
|
|
|
|
|
|
fi
|
2014-09-20 12:25:54 +00:00
|
|
|
fi
|
|
|
|
|
2014-05-02 02:39:45 +00:00
|
|
|
ufw --force enable;
|
2014-09-21 17:43:21 +00:00
|
|
|
fi #NODOC
|
2014-06-18 23:41:35 +00:00
|
|
|
|
2014-09-21 17:43:21 +00:00
|
|
|
# ### Local DNS Service
|
|
|
|
|
|
|
|
# Install a local DNS server, rather than using the DNS server provided by the
|
|
|
|
# ISP's network configuration.
|
|
|
|
#
|
|
|
|
# We do this to ensure that DNS queries
|
2014-06-18 23:41:35 +00:00
|
|
|
# that *we* make (i.e. looking up other external domains) perform DNSSEC checks.
|
|
|
|
# We could use Google's Public DNS, but we don't want to create a dependency on
|
2014-09-21 17:43:21 +00:00
|
|
|
# Google per our goals of decentralization. `bind9`, as packaged for Ubuntu, has
|
2014-06-18 23:41:35 +00:00
|
|
|
# DNSSEC enabled by default via "dnssec-validation auto".
|
|
|
|
#
|
2014-09-21 17:43:21 +00:00
|
|
|
# So we'll be running `bind9` bound to 127.0.0.1 for locally-issued DNS queries
|
|
|
|
# and `nsd` bound to the public ethernet interface for remote DNS queries asking
|
|
|
|
# about our domain names. `nsd` is configured later.
|
2014-06-18 23:41:35 +00:00
|
|
|
#
|
|
|
|
# About the settings:
|
|
|
|
#
|
2014-09-21 17:43:21 +00:00
|
|
|
# * RESOLVCONF=yes will have `bind9` take over /etc/resolv.conf to tell
|
2014-06-18 23:41:35 +00:00
|
|
|
# local services that DNS queries are handled on localhost.
|
2014-09-21 17:43:21 +00:00
|
|
|
# * Adding -4 to OPTIONS will have `bind9` not listen on IPv6 addresses
|
2014-06-18 23:41:35 +00:00
|
|
|
# so that we're sure there's no conflict with nsd, our public domain
|
|
|
|
# name server, on IPV6.
|
2014-09-21 17:43:21 +00:00
|
|
|
# * The listen-on directive in named.conf.options restricts `bind9` to
|
2014-06-18 23:41:35 +00:00
|
|
|
# binding to the loopback interface instead of all interfaces.
|
2014-08-07 13:49:14 +00:00
|
|
|
apt_install bind9 resolvconf
|
2014-06-18 23:41:35 +00:00
|
|
|
tools/editconf.py /etc/default/bind9 \
|
|
|
|
RESOLVCONF=yes \
|
|
|
|
"OPTIONS=\"-u bind -4\""
|
|
|
|
if ! grep -q "listen-on " /etc/bind/named.conf.options; then
|
|
|
|
# Add a listen-on directive if it doesn't exist inside the options block.
|
|
|
|
sed -i "s/^}/\n\tlisten-on { 127.0.0.1; };\n}/" /etc/bind/named.conf.options
|
|
|
|
fi
|
2014-08-07 13:49:14 +00:00
|
|
|
if [ -f /etc/resolvconf/resolv.conf.d/original ]; then
|
2014-09-21 17:43:21 +00:00
|
|
|
echo "Archiving old resolv.conf (was /etc/resolvconf/resolv.conf.d/original, now /etc/resolvconf/resolv.conf.original)." #NODOC
|
|
|
|
mv /etc/resolvconf/resolv.conf.d/original /etc/resolvconf/resolv.conf.original #NODOC
|
2014-08-07 13:49:14 +00:00
|
|
|
fi
|
2014-06-18 23:41:35 +00:00
|
|
|
|
2014-09-21 17:43:21 +00:00
|
|
|
# Restart the DNS services.
|
|
|
|
|
2014-07-16 13:06:45 +00:00
|
|
|
restart_service bind9
|
2014-08-07 13:49:14 +00:00
|
|
|
restart_service resolvconf
|