diff --git a/CHANGELOG.md b/CHANGELOG.md index 4651873d..156977da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,14 @@ CHANGELOG ========= -Still In Development --------------------- +v0.15 Release Candidate +----------------------- Mail: * Updated Roundcube to version 1.1.3. -* Auto-create RFC2142 aliases for abuse@. +* Auto-create aliases for abuse@, as required by RFC2142. +* The DANE TLSA record is changed to use the certificate subject public key rather than the whole certificate, which means the record remains valid after certificate changes (so long as the private key remains the same, which it does for us). Control panel: @@ -16,16 +17,22 @@ Control panel: * DNS checks now have a timeout in case a DNS server is not responding, so the checks don't stall indefinitely. * Better messages if external DNS is used and, weirdly, custom secondary nameservers are set. * Add POP to the mail client settings documentation. +* The box's IP address is added to the fail2ban whitelist so that the status checks don't trigger the machine banning itself, which results in the status checks showing services down even though they are running. +* For SSL certificates, rather than asking you what country you are in during setup, ask at the time a CSR is generated. The default system self-signed certificate now omits a country in the subject (it was never needed). The CSR_COUNTRY Mail-in-a-Box setting is dropped entirely. System: +* Nightly backups and system status checks are now moved to 3am in the system's timezone. +* fail2ban's recidive jail is now active, which guards against persistent brute force login attacks over long periods of time. +* Setup (first run only) now asks for your timezone to set the system time. * The Exchange/ActiveSync server is now taken offline during nightly backups (along with SMTP and IMAP). * The machine's random number generator (/dev/urandom) is now seeded with Ubuntu Pollinate and a blocking read on /dev/random. * DNSSEC key generation during install now uses /dev/urandom (instead of /dev/random), which is faster. +* The $STORAGE_ROOT/ssl directory is flattened by a migration script and the system SSL certificate path is now a symlink to the actual certificate. * If ownCloud sends out email, it will use the box's administrative address now (admin@yourboxname). * Z-Push (Exchange/ActiveSync) logs now exclude warnings and are now rotated to save disk space. * Fix pip command that might have not installed all necessary Python packages. -* The control panel and backup would not work on Google Compute Engine because they install a conflicting boto package. +* The control panel and backup would not work on Google Compute Engine because GCE installs a conflicting boto package. * Added a new command `management/backup.py --restore` to restore files from a backup to a target directory (command line arguments are passed to `duplicity restore`). v0.14 (November 4, 2015) diff --git a/Vagrantfile b/Vagrantfile index 2a21dd08..c6ef0ab9 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -22,7 +22,6 @@ Vagrant.configure("2") do |config| export PUBLIC_IP=auto export PUBLIC_IPV6=auto export PRIMARY_HOSTNAME=auto-easy - export CSR_COUNTRY=US #export SKIP_NETWORK_CHECKS=1 # Start the setup script. diff --git a/setup/csr_country_codes.tsv b/management/csr_country_codes.tsv similarity index 98% rename from setup/csr_country_codes.tsv rename to management/csr_country_codes.tsv index 3f8f6586..21fde999 100644 --- a/setup/csr_country_codes.tsv +++ b/management/csr_country_codes.tsv @@ -1,27 +1,28 @@ # This list is derived from https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2. # The columns are ISO_3166-1_alpha-2 code, display name, Wikipedia page name. -# The top 20 countries by number of Internet users are grouped first, see +# The top 21 countries by number of Internet users are grouped first, see # https://en.wikipedia.org/wiki/List_of_countries_by_number_of_Internet_users. -BR Brazil -CA Canada CN China -EG Egypt -FR France -DE Germany IN India -ID Indonesia -IT Italy -JP Japan -MX Mexico -NG Nigeria -PH Philippines -RU Russian Federation Russia -ES Spain -KR South Korea -TR Turkey -GB United Kingdom US United States +JP Japan +BR Brazil +RU Russian Federation Russia +DE Germany +NG Nigeria +GB United Kingdom +FR France +MX Mexico +EG Egypt +KR South Korea VN Vietnam +ID Indonesia +PH Philippines +TR Turkey +IT Italy +PK Pakistan +ES Spain +CA Canada AD Andorra AE United Arab Emirates AF Afghanistan @@ -183,7 +184,6 @@ PA Panama PE Peru PF French Polynesia PG Papua New Guinea -PK Pakistan PL Poland PM Saint Pierre and Miquelon PN Pitcairn Pitcairn Islands diff --git a/management/daemon.py b/management/daemon.py index 4f56a767..27e18e8f 100755 --- a/management/daemon.py +++ b/management/daemon.py @@ -28,6 +28,14 @@ try: except OSError: pass +# for generating CSRs we need a list of country codes +csr_country_codes = [] +with open(os.path.join(os.path.dirname(me), "csr_country_codes.tsv")) as f: + for line in f: + if line.strip() == "" or line.startswith("#"): continue + code, name = line.strip().split("\t")[0:2] + csr_country_codes.append((code, name)) + app = Flask(__name__, template_folder=os.path.abspath(os.path.join(os.path.dirname(me), "templates"))) # Decorator to protect views that require a user with 'admin' privileges. @@ -101,9 +109,12 @@ def index(): return render_template('index.html', hostname=env['PRIMARY_HOSTNAME'], storage_root=env['STORAGE_ROOT'], + no_users_exist=no_users_exist, no_admins_exist=no_admins_exist, + backup_s3_hosts=backup_s3_hosts, + csr_country_codes=csr_country_codes, ) @app.route('/me') @@ -321,7 +332,7 @@ def dns_get_dump(): def ssl_get_csr(domain): from ssl_certificates import create_csr ssl_private_key = os.path.join(os.path.join(env["STORAGE_ROOT"], 'ssl', 'ssl_private_key.pem')) - return create_csr(domain, ssl_private_key, env) + return create_csr(domain, ssl_private_key, request.form.get('countrycode', ''), env) @app.route('/ssl/install', methods=['POST']) @authorized_personnel_only diff --git a/management/daily_tasks.sh b/management/daily_tasks.sh new file mode 100755 index 00000000..6237e6c2 --- /dev/null +++ b/management/daily_tasks.sh @@ -0,0 +1,8 @@ +#!/bin/bash +# This script is run daily (at 3am each night). + +# Take a backup. +management/backup.py + +# Run status checks and email the administrator if anything changed. +management/status_checks.py --show-changes --smtp diff --git a/management/dns_update.py b/management/dns_update.py index 1ec88607..0aae94cf 100755 --- a/management/dns_update.py +++ b/management/dns_update.py @@ -283,26 +283,40 @@ def build_zone(domain, all_domains, additional_records, www_redirect_domains, en def build_tlsa_record(env): # A DANE TLSA record in DNS specifies that connections on a port - # must use TLS and the certificate must match a particular certificate. + # must use TLS and the certificate must match a particular criteria. # # Thanks to http://blog.huque.com/2012/10/dnssec-and-certificates.html - # for explaining all of this! + # and https://community.letsencrypt.org/t/please-avoid-3-0-1-and-3-0-2-dane-tlsa-records-with-le-certificates/7022 + # for explaining all of this! Also see https://tools.ietf.org/html/rfc6698#section-2.1 + # and https://github.com/mail-in-a-box/mailinabox/issues/268#issuecomment-167160243. + # + # There are several criteria. We used to use "3 0 1" criteria, which + # meant to pin a leaf (3) certificate (0) with SHA256 hash (1). But + # certificates change, and especially as we move to short-lived certs + # they change often. The TLSA record handily supports the criteria of + # a leaf certificate (3)'s subject public key (1) with SHA256 hash (1). + # The subject public key is the public key portion of the private key + # that generated the CSR that generated the certificate. Since we + # generate a private key once the first time Mail-in-a-Box is set up + # and reuse it for all subsequent certificates, the TLSA record will + # remain valid indefinitely. - # Get the hex SHA256 of the DER-encoded server certificate: - certder = shell("check_output", [ - "/usr/bin/openssl", - "x509", - "-in", os.path.join(env["STORAGE_ROOT"], "ssl", "ssl_certificate.pem"), - "-outform", "DER" - ], - return_bytes=True) - certhash = hashlib.sha256(certder).hexdigest() + from ssl_certificates import load_cert_chain, load_pem + from cryptography.hazmat.primitives.serialization import Encoding, PublicFormat + + fn = os.path.join(env["STORAGE_ROOT"], "ssl", "ssl_certificate.pem") + cert = load_pem(load_cert_chain(fn)[0]) + + subject_public_key = cert.public_key().public_bytes(Encoding.DER, PublicFormat.SubjectPublicKeyInfo) + # We could have also loaded ssl_private_key.pem and called priv_key.public_key().public_bytes(...) + + pk_hash = hashlib.sha256(subject_public_key).hexdigest() # Specify the TLSA parameters: - # 3: This is the certificate that the client should trust. No CA is needed. - # 0: The whole certificate is matched. - # 1: The certificate is SHA256'd here. - return "3 0 1 " + certhash + # 3: Match the (leaf) certificate. (No CA, no trust path needed.) + # 1: Match its subject public key. + # 1: Use SHA256. + return "3 1 1 " + pk_hash def build_sshfp_records(): # The SSHFP record is a way for us to embed this server's SSH public diff --git a/management/ssl_certificates.py b/management/ssl_certificates.py index 0365251c..1e9a9ca8 100644 --- a/management/ssl_certificates.py +++ b/management/ssl_certificates.py @@ -137,12 +137,12 @@ def get_domain_ssl_files(domain, ssl_certificates, env, allow_missing_cert=False return cert_info['private-key'], cert_info['certificate'], via -def create_csr(domain, ssl_key, env): +def create_csr(domain, ssl_key, country_code, env): return shell("check_output", [ "openssl", "req", "-new", "-key", ssl_key, "-sha256", - "-subj", "/C=%s/ST=/L=/O=/CN=%s" % (env["CSR_COUNTRY"], domain)]) + "-subj", "/C=%s/ST=/L=/O=/CN=%s" % (country_code, domain)]) def install_cert(domain, ssl_cert, ssl_chain, env): # Write the combined cert+chain to a temporary path and validate that it is OK. @@ -184,21 +184,22 @@ def install_cert(domain, ssl_cert, ssl_chain, env): # When updating the cert for PRIMARY_HOSTNAME, symlink it from the system # certificate path, which is hard-coded for various purposes, and then - # update DNS (because of the DANE TLSA record), postfix, and dovecot, - # which all use the file. + # restart postfix and dovecot. if domain == env['PRIMARY_HOSTNAME']: # Update symlink. system_ssl_certificate = os.path.join(os.path.join(env["STORAGE_ROOT"], 'ssl', 'ssl_certificate.pem')) os.unlink(system_ssl_certificate) os.symlink(ssl_certificate, system_ssl_certificate) - # Update DNS & restart postfix and dovecot so they pick up the new file. - from dns_update import do_dns_update - ret.append( do_dns_update(env) ) + # Restart postfix and dovecot so they pick up the new file. shell('check_call', ["/usr/sbin/service", "postfix", "restart"]) shell('check_call', ["/usr/sbin/service", "dovecot", "restart"]) ret.append("mail services restarted") + # The DANE TLSA record will remain valid so long as the private key + # hasn't changed. We don't ever change the private key automatically. + # If the user does it, they must manually update DNS. + # Update the web configuration so nginx picks up the new certificate file. from web_update import do_web_update ret.append( do_web_update(env) ) diff --git a/management/templates/ssl.html b/management/templates/ssl.html index 060bd447..d411098c 100644 --- a/management/templates/ssl.html +++ b/management/templates/ssl.html @@ -28,6 +28,15 @@
+What country are you in? This is required by some SSL certificate providers. You may leave this blank if you know your SSL certificate provider doesn't require it.
+ + + -/path/to/mailinabox
")
return v