From 178c5876542d3b9c756e4f153d02167dd169bf86 Mon Sep 17 00:00:00 2001 From: Joshua Tauberer Date: Sun, 11 Apr 2021 16:07:09 -0400 Subject: [PATCH 01/20] Migrate to the ECDSAP256SHA256 (13) DNSSEC algorithm * Stop generating RSASHA1-NSEC3-SHA1 keys on new installs since it is no longer recommended, but preserve the key on existing installs so that we continue to sign zones with existing keys to retain the chain of trust with existing DS records. * Start generating ECDSAP256SHA256 keys during setup, the current best practice (in addition to RSASHA256 which is also ok). See https://www.iana.org/assignments/dns-sec-alg-numbers/dns-sec-alg-numbers.xhtml#dns-sec-alg-numbers-1 and https://www.cloudflare.com/dns/dnssec/ecdsa-and-dnssec/. * Sign zones using all available keys rather than choosing just one based on the TLD to enable rotation/migration to the new key and to give the user some options since not every registrar/TLD supports every algorithm. * Allow a user to drop a key from signing specific domains using DOMAINS= in our key configuration file. Signing the zones with extraneous keys may increase the size of DNS responses, which isn't ideal, although I don't know if this is a problem in practice. (Although a user can delete the RSASHA1-NSEC3-SHA1 key file, the other keys will be re-generated on upgrade.) * When generating zonefiles, add a hash of all of the DNSSEC signing keys so that when the keys change the zone is definitely regenerated and re-signed. * In status checks, if DNSSEC is not active (or not valid), offer to use all of the keys that have been generated (for RSASHA1-NSEC3-SHA1 on existing installs, RSASHA256, and now ECDSAP256SHA256) with all digest types, since not all registers support everything, but list them in an order that guides users to the best practice. * In status checks, if the deployed DS record doesn't use a ECDSAP256SHA256 key, prompt the user to update their DS record. * In status checks, if multiple DS records are set, only fail if none are valid. If some use ECDSAP256SHA256 and some don't, remind the user to delete the DS records that don't. * Don't fail if the DS record uses the SHA384 digest (by pre-generating a DS record with that digest type) but don't recommend it because it is not in the IANA mandatory list yet (https://www.iana.org/assignments/ds-rr-types/ds-rr-types.xhtml). See #1953 --- CHANGELOG.md | 5 ++ management/dns_update.py | 148 ++++++++++++++++++++++-------------- management/status_checks.py | 134 ++++++++++++++++++++++---------- setup/dns.sh | 43 +++++------ 4 files changed, 207 insertions(+), 123 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a75a9a43..80988981 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +In Development +-------------- + +* Migrate to the ECDSAP256SHA256 DNSSEC algorithm. If a DS record is set for any of your domain names that have DNS hosted on your box, you will be prompted by status checks to update the DS record. + v0.53 (April 12, 2021) ---------------------- diff --git a/management/dns_update.py b/management/dns_update.py index b2901bc8..89777fb0 100755 --- a/management/dns_update.py +++ b/management/dns_update.py @@ -429,6 +429,7 @@ def build_sshfp_records(): # to the zone file (that trigger bumping the serial number). However, # if SSH has been configured to listen on a nonstandard port, we must # specify that port to sshkeyscan. + port = 22 with open('/etc/ssh/sshd_config', 'r') as f: for line in f: @@ -439,8 +440,11 @@ def build_sshfp_records(): except ValueError: pass break + keys = shell("check_output", ["ssh-keyscan", "-t", "rsa,dsa,ecdsa,ed25519", "-p", str(port), "localhost"]) - for key in sorted(keys.split("\n")): + keys = sorted(keys.split("\n")) + + for key in keys: if key.strip() == "" or key[0] == "#": continue try: host, keytype, pubkey = key.split(" ") @@ -460,13 +464,16 @@ def write_nsd_zone(domain, zonefile, records, env, force): # On the $ORIGIN line, there's typically a ';' comment at the end explaining # what the $ORIGIN line does. Any further data after the domain confuses # ldns-signzone, however. It used to say '; default zone domain'. - + # # The SOA contact address for all of the domains on this system is hostmaster # @ the PRIMARY_HOSTNAME. Hopefully that's legit. - + # # For the refresh through TTL fields, a good reference is: # http://www.peerwisdom.org/2013/05/15/dns-understanding-the-soa-record/ - + # + # A hash of the available DNSSEC keys are added in a comment so that when + # the keys change we force a re-generation of the zone which triggers + # re-signing it. zone = """ $ORIGIN {domain}. @@ -502,6 +509,9 @@ $TTL 86400 ; default time to live value = v2 zone += value + "\n" + # Append a stable hash of DNSSEC signing keys in a comment. + zone += "\n; DNSSEC signing keys hash: {}\n".format(hash_dnssec_keys(domain, env)) + # DNSSEC requires re-signing a zone periodically. That requires # bumping the serial number even if no other records have changed. # We don't see the DNSSEC records yet, so we have to figure out @@ -612,53 +622,77 @@ zone: ######################################################################## -def dnssec_choose_algo(domain, env): - if '.' in domain and domain.rsplit('.')[-1] in \ - ("email", "guide", "fund", "be", "lv"): - # At GoDaddy, RSASHA256 is the only algorithm supported - # for .email and .guide. - # A variety of algorithms are supported for .fund. This - # is preferred. - # Gandi tells me that .be does not support RSASHA1-NSEC3-SHA1 - # Nic.lv does not support RSASHA1-NSEC3-SHA1 for .lv tld's - return "RSASHA256" +def find_dnssec_signing_keys(domain, env): + # For key that we generated (one per algorithm)... + d = os.path.join(env['STORAGE_ROOT'], 'dns/dnssec') + keyconfs = [f for f in os.listdir(d) if f.endswith(".conf")] + for keyconf in keyconfs: + # Load the file holding the KSK and ZSK key filenames. + keyconf_fn = os.path.join(d, keyconf) + keyinfo = load_env_vars_from_file(keyconf_fn) - # For any domain we were able to sign before, don't change the algorithm - # on existing users. We'll probably want to migrate to SHA256 later. - return "RSASHA1-NSEC3-SHA1" + # Skip this key if the conf file has a setting named DOMAINS, + # holding a comma-separated list of domain names, and if this + # domain is not in the list. This allows easily disabling a + # key by setting "DOMAINS=" or "DOMAINS=none", other than + # deleting the key's .conf file, which might result in the key + # being regenerated next upgrade. Keys should be disabled if + # they are not needed to reduce the DNSSEC query response size. + if "DOMAINS" in keyinfo and domain not in [dd.strip() for dd in keyinfo["DOMAINS"].split(",")]: + continue + + for keytype in ("KSK", "ZSK"): + yield keytype, keyinfo[keytype] + +def hash_dnssec_keys(domain, env): + # Create a stable (by sorting the items) hash of all of the private keys + # that will be used to sign this domain. + keydata = [] + for keytype, keyfn in sorted(find_dnssec_signing_keys(domain, env)): + oldkeyfn = os.path.join(env['STORAGE_ROOT'], 'dns/dnssec', keyfn + ".private") + keydata.append(keytype) + keydata.append(keyfn) + with open(oldkeyfn, "r") as fr: + keydata.append( fr.read() ) + keydata = "".join(keydata).encode("utf8") + return hashlib.sha1(keydata).hexdigest() def sign_zone(domain, zonefile, env): - algo = dnssec_choose_algo(domain, env) - dnssec_keys = load_env_vars_from_file(os.path.join(env['STORAGE_ROOT'], 'dns/dnssec/%s.conf' % algo)) + # Sign the zone with all of the keys that were generated during + # setup so that the user can choose which to use in their DS record at + # their registrar, and also to support migration to newer algorithms. - # In order to use the same keys for all domains, we have to generate - # a new .key file with a DNSSEC record for the specific domain. We - # can reuse the same key, but it won't validate without a DNSSEC - # record specifically for the domain. + # In order to use the key files generated at setup which are for + # the domain _domain_, we have to re-write the files and place + # the actual domain name in it, so that ldns-signzone works. # - # Copy the .key and .private files to /tmp to patch them up. - # - # Use os.umask and open().write() to securely create a copy that only - # we (root) can read. - files_to_kill = [] - for key in ("KSK", "ZSK"): - if dnssec_keys.get(key, "").strip() == "": raise Exception("DNSSEC is not properly set up.") - oldkeyfn = os.path.join(env['STORAGE_ROOT'], 'dns/dnssec/' + dnssec_keys[key]) - newkeyfn = '/tmp/' + dnssec_keys[key].replace("_domain_", domain) - dnssec_keys[key] = newkeyfn + # Patch each key, storing the patched version in /tmp for now. + # Each key has a .key and .private file. Collect a list of filenames + # for all of the keys (and separately just the key-signing keys). + all_keys = [] + ksk_keys = [] + for keytype, keyfn in find_dnssec_signing_keys(domain, env): + newkeyfn = '/tmp/' + keyfn.replace("_domain_", domain) + for ext in (".private", ".key"): - if not os.path.exists(oldkeyfn + ext): raise Exception("DNSSEC is not properly set up.") - with open(oldkeyfn + ext, "r") as fr: + # Copy the .key and .private files to /tmp to patch them up. + # + # Use os.umask and open().write() to securely create a copy that only + # we (root) can read. + oldkeyfn = os.path.join(env['STORAGE_ROOT'], 'dns/dnssec', keyfn + ext) + with open(oldkeyfn, "r") as fr: keydata = fr.read() - keydata = keydata.replace("_domain_", domain) # trick ldns-signkey into letting our generic key be used by this zone - fn = newkeyfn + ext + keydata = keydata.replace("_domain_", domain) prev_umask = os.umask(0o77) # ensure written file is not world-readable try: - with open(fn, "w") as fw: + with open(newkeyfn + ext, "w") as fw: fw.write(keydata) finally: os.umask(prev_umask) # other files we write should be world-readable - files_to_kill.append(fn) + + # Put the patched key filename base (without extension) into the list of keys we'll sign with. + all_keys.append(newkeyfn) + if keytype == "KSK": ksk_keys.append(newkeyfn) # Do the signing. expiry_date = (datetime.datetime.now() + datetime.timedelta(days=30)).strftime("%Y%m%d") @@ -671,32 +705,34 @@ def sign_zone(domain, zonefile, env): # zonefile to sign "/etc/nsd/zones/" + zonefile, - + ] # keys to sign with (order doesn't matter -- it'll figure it out) - dnssec_keys["KSK"], - dnssec_keys["ZSK"], - ]) + + all_keys + ) # Create a DS record based on the patched-up key files. The DS record is specific to the # zone being signed, so we can't use the .ds files generated when we created the keys. # The DS record points to the KSK only. Write this next to the zone file so we can # get it later to give to the user with instructions on what to do with it. # - # We want to be able to validate DS records too, but multiple forms may be valid depending - # on the digest type. So we'll write all (both) valid records. Only one DS record should - # actually be deployed. Preferebly the first. + # Generate a DS record for each key. There are also several possible hash algorithms that may + # be used, so we'll pre-generate all for each key. One DS record per line. Only one + # needs to actually be deployed at the registrar. We'll select the preferred one + # in the status checks. with open("/etc/nsd/zones/" + zonefile + ".ds", "w") as f: - for digest_type in ('2', '1'): - rr_ds = shell('check_output', ["/usr/bin/ldns-key2ds", - "-n", # output to stdout - "-" + digest_type, # 1=SHA1, 2=SHA256 - dnssec_keys["KSK"] + ".key" - ]) - f.write(rr_ds) + for key in ksk_keys: + for digest_type in ('1', '2', '4'): + rr_ds = shell('check_output', ["/usr/bin/ldns-key2ds", + "-n", # output to stdout + "-" + digest_type, # 1=SHA1, 2=SHA256, 4=SHA384 + key + ".key" + ]) + f.write(rr_ds) - # Remove our temporary file. - for fn in files_to_kill: - os.unlink(fn) + # Remove the temporary patched key files. + for fn in all_keys: + os.unlink(fn + ".private") + os.unlink(fn + ".key") ######################################################################## diff --git a/management/status_checks.py b/management/status_checks.py index 631a82a2..607fd578 100755 --- a/management/status_checks.py +++ b/management/status_checks.py @@ -42,7 +42,7 @@ def get_services(): { "name": "HTTPS Web (nginx)", "port": 443, "public": True, }, ] -def run_checks(rounded_values, env, output, pool): +def run_checks(rounded_values, env, output, pool, domains_to_check=None): # run systems checks output.add_heading("System") @@ -63,7 +63,7 @@ def run_checks(rounded_values, env, output, pool): # perform other checks asynchronously run_network_checks(env, output) - run_domain_checks(rounded_values, env, output, pool) + run_domain_checks(rounded_values, env, output, pool, domains_to_check=domains_to_check) def get_ssh_port(): # Returns ssh port @@ -300,7 +300,7 @@ def run_network_checks(env, output): which may prevent recipients from receiving your email. See http://www.spamhaus.org/query/ip/%s.""" % (env['PUBLIC_IP'], zen, env['PUBLIC_IP'])) -def run_domain_checks(rounded_time, env, output, pool): +def run_domain_checks(rounded_time, env, output, pool, domains_to_check=None): # Get the list of domains we handle mail for. mail_domains = get_mail_domains(env) @@ -311,7 +311,8 @@ def run_domain_checks(rounded_time, env, output, pool): # Get the list of domains we serve HTTPS for. web_domains = set(get_web_domains(env)) - domains_to_check = mail_domains | dns_domains | web_domains + if domains_to_check is None: + domains_to_check = mail_domains | dns_domains | web_domains # Remove "www", "autoconfig", "autodiscover", and "mta-sts" subdomains, which we group with their parent, # if their parent is in the domains to check list. @@ -557,61 +558,103 @@ def check_dns_zone_suggestions(domain, env, output, dns_zonefiles, domains_with_ def check_dnssec(domain, env, output, dns_zonefiles, is_checking_primary=False): - # See if the domain has a DS record set at the registrar. The DS record may have - # several forms. We have to be prepared to check for any valid record. We've - # pre-generated all of the valid digests --- read them in. + # See if the domain has a DS record set at the registrar. The DS record must + # match one of the keys that we've used to sign the zone. It may use one of + # several hashing algorithms. We've pre-generated all possible valid DS + # records, although some will be preferred. + + alg_name_map = { '7': 'RSASHA1-NSEC3-SHA1', '8': 'RSASHA256', '13': 'ECDSAP256SHA256' } + digalg_name_map = { '1': 'SHA-1', '2': 'SHA-256', '4': 'SHA-384' } + + # Read in the pre-generated DS records + expected_ds_records = { } ds_file = '/etc/nsd/zones/' + dns_zonefiles[domain] + '.ds' if not os.path.exists(ds_file): return # Domain is in our database but DNS has not yet been updated. - ds_correct = open(ds_file).read().strip().split("\n") - digests = { } - for rr_ds in ds_correct: - ds_keytag, ds_alg, ds_digalg, ds_digest = rr_ds.split("\t")[4].split(" ") - digests[ds_digalg] = ds_digest + with open(ds_file) as f: + for rr_ds in f: + rr_ds = rr_ds.rstrip() + ds_keytag, ds_alg, ds_digalg, ds_digest = rr_ds.split("\t")[4].split(" ") - # Some registrars may want the public key so they can compute the digest. The DS - # record that we suggest using is for the KSK (and that's how the DS records were generated). - alg_name_map = { '7': 'RSASHA1-NSEC3-SHA1', '8': 'RSASHA256' } - dnssec_keys = load_env_vars_from_file(os.path.join(env['STORAGE_ROOT'], 'dns/dnssec/%s.conf' % alg_name_map[ds_alg])) - dnsssec_pubkey = open(os.path.join(env['STORAGE_ROOT'], 'dns/dnssec/' + dnssec_keys['KSK'] + '.key')).read().split("\t")[3].split(" ")[3] + # Some registrars may want the public key so they can compute the digest. The DS + # record that we suggest using is for the KSK (and that's how the DS records were generated). + # We'll also give the nice name for the key algorithm. + dnssec_keys = load_env_vars_from_file(os.path.join(env['STORAGE_ROOT'], 'dns/dnssec/%s.conf' % alg_name_map[ds_alg])) + dnsssec_pubkey = open(os.path.join(env['STORAGE_ROOT'], 'dns/dnssec/' + dnssec_keys['KSK'] + '.key')).read().split("\t")[3].split(" ")[3] + + expected_ds_records[ (ds_keytag, ds_alg, ds_digalg, ds_digest) ] = { + "record": rr_ds, + "keytag": ds_keytag, + "alg": ds_alg, + "alg_name": alg_name_map[ds_alg], + "digalg": ds_digalg, + "digalg_name": digalg_name_map[ds_digalg], + "digest": ds_digest, + "pubkey": dnsssec_pubkey, + } # Query public DNS for the DS record at the registrar. - ds = query_dns(domain, "DS", nxdomain=None) - ds_looks_valid = ds and len(ds.split(" ")) == 4 - if ds_looks_valid: ds = ds.split(" ") - if ds_looks_valid and ds[0] == ds_keytag and ds[1] == ds_alg and ds[3] == digests.get(ds[2]): - if is_checking_primary: return - output.print_ok("DNSSEC 'DS' record is set correctly at registrar.") + ds = query_dns(domain, "DS", nxdomain=None, as_list=True) + if ds is None or isinstance(ds, str): ds = [] + + # There may be more that one record, so we get the result as a list. + # Filter out records that don't look valid, just in case, and split + # each record on spaces. + ds = [tuple(str(rr).split(" ")) for rr in ds if len(str(rr).split(" ")) == 4] + + if len(ds) == 0: + output.print_warning("""This domain's DNSSEC DS record is not set. The DS record is optional. The DS record activates DNSSEC. See below for instructions.""") else: - if ds == None: - if is_checking_primary: return - output.print_warning("""This domain's DNSSEC DS record is not set. The DS record is optional. The DS record activates DNSSEC. - To set a DS record, you must follow the instructions provided by your domain name registrar and provide to them this information:""") + matched_ds = set(ds) & set(expected_ds_records) + if matched_ds: + # At least one DS record matches one that corresponds with one of the ways we signed + # the zone, so it is valid. + # + # But it may not be preferred. Only algorithm 13 is preferred. Warn if any of the + # matched zones uses a different algorithm. + if set(r[1] for r in matched_ds) == { '13' }: # all are alg 13 + output.print_ok("DNSSEC 'DS' record is set correctly at registrar.") + return + elif '13' in set(r[1] for r in matched_ds): # some but not all are alg 13 + output.print_ok("DNSSEC 'DS' record is set correctly at registrar. (Records using algorithm other than ECDSAP256SHA256 should be removed.)") + return + else: # no record uses alg 13 + output.print_warning("DNSSEC 'DS' record set at registrar is valid but should be updated to ECDSAP256SHA256 (see below).") else: if is_checking_primary: output.print_error("""The DNSSEC 'DS' record for %s is incorrect. See further details below.""" % domain) return output.print_error("""This domain's DNSSEC DS record is incorrect. The chain of trust is broken between the public DNS system and this machine's DNS server. It may take several hours for public DNS to update after a change. If you did not recently - make a change, you must resolve this immediately by following the instructions provided by your domain name registrar and - provide to them this information:""") + make a change, you must resolve this immediately (see below).""") + + output.print_line("""Follow the instructions provided by your domain name registrar to set a DS record. + Registrars support different sorts of DS records. Use the first option that works:""") + preferred_ds_order = [(7, 1), (7, 2), (8, 4), (13, 4), (8, 1), (8, 2), (13, 1), (13, 2)] # low to high + def preferred_ds_order_func(ds_suggestion): + k = (int(ds_suggestion['alg']), int(ds_suggestion['digalg'])) + if k in preferred_ds_order: + return preferred_ds_order.index(k) + return -1 # index before first item + output.print_line("") + for i, ds_suggestion in enumerate(sorted(expected_ds_records.values(), key=preferred_ds_order_func, reverse=True)): output.print_line("") - output.print_line("Key Tag: " + ds_keytag + ("" if not ds_looks_valid or ds[0] == ds_keytag else " (Got '%s')" % ds[0])) + output.print_line("Option " + str(i+1) + ":") + output.print_line("----------") + output.print_line("Key Tag: " + ds_suggestion['keytag']) output.print_line("Key Flags: KSK") - output.print_line( - ("Algorithm: %s / %s" % (ds_alg, alg_name_map[ds_alg])) - + ("" if not ds_looks_valid or ds[1] == ds_alg else " (Got '%s')" % ds[1])) - # see http://www.iana.org/assignments/dns-sec-alg-numbers/dns-sec-alg-numbers.xhtml - output.print_line("Digest Type: 2 / SHA-256") - # http://www.ietf.org/assignments/ds-rr-types/ds-rr-types.xml - output.print_line("Digest: " + digests['2']) - if ds_looks_valid and ds[3] != digests.get(ds[2]): - output.print_line("(Got digest type %s and digest %s which do not match.)" % (ds[2], ds[3])) + output.print_line("Algorithm: %s / %s" % (ds_suggestion['alg'], ds_suggestion['alg_name'])) + output.print_line("Digest Type: %s / %s" % (ds_suggestion['digalg'], ds_suggestion['digalg_name'])) + output.print_line("Digest: " + ds_suggestion['digest']) output.print_line("Public Key: ") - output.print_line(dnsssec_pubkey, monospace=True) + output.print_line(ds_suggestion['pubkey'], monospace=True) output.print_line("") output.print_line("Bulk/Record Format:") - output.print_line("" + ds_correct[0]) + output.print_line(ds_suggestion['record'], monospace=True) + if len(ds) > 0: output.print_line("") + output.print_line("The DS record is currently set to:") + for rr in ds: + output.print_line("Key Tag: {0}, Algorithm: {1}, Digest Type: {2}, Digest: {3}".format(*rr)) def check_mail_domain(domain, env, output): # Check the MX record. @@ -713,7 +756,7 @@ def check_web_domain(domain, rounded_time, ssl_certificates, env, output): # website for also needs a signed certificate. check_ssl_cert(domain, rounded_time, ssl_certificates, env, output) -def query_dns(qname, rtype, nxdomain='[Not Set]', at=None): +def query_dns(qname, rtype, nxdomain='[Not Set]', at=None, as_list=False): # Make the qname absolute by appending a period. Without this, dns.resolver.query # will fall back a failed lookup to a second query with this machine's hostname # appended. This has been causing some false-positive Spamhaus reports. The @@ -750,6 +793,9 @@ def query_dns(qname, rtype, nxdomain='[Not Set]', at=None): if rtype in ("A", "AAAA"): response = [normalize_ip(str(r)) for r in response] + if as_list: + return response + # There may be multiple answers; concatenate the response. Remove trailing # periods from responses since that's how qnames are encoded in DNS but is # confusing for us. The order of the answers doesn't matter, so sort so we @@ -1050,3 +1096,7 @@ if __name__ == "__main__": elif sys.argv[1] == "--version": print(what_version_is_this(env)) + + elif sys.argv[1] == "--only": + with multiprocessing.pool.Pool(processes=10) as pool: + run_checks(False, env, ConsoleOutput(), pool, domains_to_check=sys.argv[2:]) diff --git a/setup/dns.sh b/setup/dns.sh index 5d86227a..2a1b6da0 100755 --- a/setup/dns.sh +++ b/setup/dns.sh @@ -68,27 +68,15 @@ echo "include: /etc/nsd/zones.conf" >> /etc/nsd/nsd.conf; mkdir -p "$STORAGE_ROOT/dns/dnssec"; -# TLDs don't all support the same algorithms, so we'll generate keys using a few -# 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. -# -# Supports `RSASHA1-NSEC3-SHA1` (didn't test with `RSASHA256`): -# -# * .info -# * .me -# -# Requires `RSASHA256` -# -# * .email -# * .guide -# -# Supports `RSASHA256` (and defaulting to this) -# -# * .fund - +# TLDs, registrars, and validating nameservers don't all support the same algorithms, +# so we'll generate keys using a few different algorithms so that dns_update.py can +# choose which algorithm to use when generating the zonefiles. See #1953 for recent +# discussion. File for previously used algorithms (i.e. RSASHA1-NSEC3-SHA1) may still +# be in the output directory, and we'll continue to support signing zones with them +# so that trust isn't broken with deployed DS records, but we won't generate those +# keys on new systems. FIRST=1 #NODOC -for algo in RSASHA1-NSEC3-SHA1 RSASHA256; do +for algo in RSASHA256 ECDSAP256SHA256; do if [ ! -f "$STORAGE_ROOT/dns/dnssec/$algo.conf" ]; then if [ $FIRST == 1 ]; then echo "Generating DNSSEC signing keys..." @@ -97,7 +85,7 @@ if [ ! -f "$STORAGE_ROOT/dns/dnssec/$algo.conf" ]; then # 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. + # matter -- we'll use the same keys for all our domains. # # `ldns-keygen` outputs the new key's filename to stdout, which # we're capturing into the `KSK` variable. @@ -105,17 +93,22 @@ if [ ! -f "$STORAGE_ROOT/dns/dnssec/$algo.conf" ]; then # ldns-keygen uses /dev/random for generating random numbers by default. # This is slow and unecessary if we ensure /dev/urandom is seeded properly, # so we use /dev/urandom. See system.sh for an explanation. See #596, #115. - KSK=$(umask 077; cd $STORAGE_ROOT/dns/dnssec; ldns-keygen -r /dev/urandom -a $algo -b 2048 -k _domain_); + # (This previously used -b 2048 but it's unclear if this setting makes sense + # for non-RSA keys, so it's removed. The RSA-based keys are not recommended + # anymore anyway.) + KSK=$(umask 077; cd $STORAGE_ROOT/dns/dnssec; ldns-keygen -r /dev/urandom -a $algo -k _domain_); # 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 - # disturbing DNS availability.) Omit `-k` and use a shorter key length. - ZSK=$(umask 077; cd $STORAGE_ROOT/dns/dnssec; ldns-keygen -r /dev/urandom -a $algo -b 1024 _domain_); + # disturbing DNS availability.) Omit `-k`. + # (This previously used -b 1024 but it's unclear if this setting makes sense + # for non-RSA keys, so it's removed.) + ZSK=$(umask 077; cd $STORAGE_ROOT/dns/dnssec; ldns-keygen -r /dev/urandom -a $algo _domain_); # These generate two sets of files like: # - # * `K_domain_.+007+08882.ds`: DS record normally provided to domain name registrar (but it's actually invalid with `_domain_`) + # * `K_domain_.+007+08882.ds`: DS record normally provided to domain name registrar (but it's actually invalid with `_domain_` so we don't use this file) # * `K_domain_.+007+08882.key`: public key # * `K_domain_.+007+08882.private`: private key (secret!) From 8cda58fb2282f53ed0bb5c3707bafe031c2ae7d7 Mon Sep 17 00:00:00 2001 From: Joshua Tauberer Date: Mon, 12 Apr 2021 18:46:35 -0400 Subject: [PATCH 02/20] Speed up status checks a bit by removing a redundant check if the PRIMARY_HOSTNAME certificate is signed and valid --- management/dns_update.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/management/dns_update.py b/management/dns_update.py index 89777fb0..c595bc3b 100755 --- a/management/dns_update.py +++ b/management/dns_update.py @@ -127,6 +127,10 @@ def build_zones(env): from web_update import get_web_domains www_redirect_domains = set(get_web_domains(env)) - set(get_web_domains(env, include_www_redirects=False)) + # For MTA-STS, we'll need to check if the PRIMARY_HOSTNAME certificate is + # singned and valid. Check that now rather than repeatedly for each domain. + env["-primary-hostname-certificate-is-valid"] = is_domain_cert_signed_and_valid(env["PRIMARY_HOSTNAME"], env) + # Build DNS records for each zone. for domain, zonefile in zonefiles: # Build the records to put in the zone. @@ -322,24 +326,11 @@ def build_zone(domain, all_domains, additional_records, www_redirect_domains, en # certificate in use is not valid (e.g. because it is self-signed and a valid certificate has not # yet been provisioned). Since we cannot provision a certificate without A/AAAA records, we # always set them --- only the TXT records depend on there being valid certificates. - mta_sts_enabled = False mta_sts_records = [ ("mta-sts", "A", env["PUBLIC_IP"], "Optional. MTA-STS Policy Host serving /.well-known/mta-sts.txt."), ("mta-sts", "AAAA", env.get('PUBLIC_IPV6'), "Optional. MTA-STS Policy Host serving /.well-known/mta-sts.txt."), ] - if domain in get_mail_domains(env): - # Check that PRIMARY_HOSTNAME and the mta_sts domain both have valid certificates. - for d in (env['PRIMARY_HOSTNAME'], "mta-sts." + domain): - cert = get_ssl_certificates(env).get(d) - if not cert: - break # no certificate provisioned for this domain - cert_status = check_certificate(d, cert['certificate'], cert['private-key']) - if cert_status[0] != 'OK': - break # certificate is not valid - else: - # 'break' was not encountered above, so both domains are good - mta_sts_enabled = True - if mta_sts_enabled: + if domain in get_mail_domains(env) and env["-primary-hostname-certificate-is-valid"] and is_domain_cert_signed_and_valid("mta-sts." + domain, env): # Compute an up-to-32-character hash of the policy file. We'll take a SHA-1 hash of the policy # file (20 bytes) and encode it as base-64 (28 bytes, using alphanumeric alternate characters # instead of '+' and '/' which are not allowed in an MTA-STS policy id) but then just take its @@ -365,6 +356,13 @@ def build_zone(domain, all_domains, additional_records, www_redirect_domains, en return records +def is_domain_cert_signed_and_valid(domain, env): + cert = get_ssl_certificates(env).get(domain) + if not cert: return False # no certificate provisioned + cert_status = check_certificate(domain, cert['certificate'], cert['private-key']) + print(domain, cert_status) + return cert_status[0] == 'OK' + ######################################################################## def build_tlsa_record(env): From 2c295bcafd8e00a8f6a33a8b9d827a7aeacedbb5 Mon Sep 17 00:00:00 2001 From: Joshua Tauberer Date: Fri, 23 Apr 2021 17:02:31 -0400 Subject: [PATCH 03/20] Upgrade the Roundcube persistent login cookie encryption to AES-256-CBC and increase the key length accordingly This change will force everyone to be logged out of Roundcube since the encryption key and cipher won't match anyone's already-set cookie, but this happens anyway after every Mail-in-a-Box update since we generate a new key each time already. Fixes #1968. --- CHANGELOG.md | 1 + setup/webmail.sh | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80988981..1efe77d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ In Development -------------- * Migrate to the ECDSAP256SHA256 DNSSEC algorithm. If a DS record is set for any of your domain names that have DNS hosted on your box, you will be prompted by status checks to update the DS record. +* Roundcube's login cookie is updated to use a new encryption algorithm (AES-256-CBC instead of DES-EDE-CBC). v0.53 (April 12, 2021) ---------------------- diff --git a/setup/webmail.sh b/setup/webmail.sh index 912bd5e5..98e12d1a 100755 --- a/setup/webmail.sh +++ b/setup/webmail.sh @@ -91,8 +91,9 @@ fi # ### Configuring Roundcube -# Generate a safe 24-character secret key of safe characters. -SECRET_KEY=$(dd if=/dev/urandom bs=1 count=18 2>/dev/null | base64 | fold -w 24 | head -n 1) +# Generate a secret key of PHP-string-safe characters appropriate +# for the cipher algorithm selected below. +SECRET_KEY=$(dd if=/dev/urandom bs=1 count=32 2>/dev/null | base64 | sed s/=//g) # Create a configuration file. # @@ -126,7 +127,8 @@ cat > $RCM_CONFIG < ~256 bits for AES-256, see above \$config['plugins'] = array('html5_notifier', 'archive', 'zipdownload', 'password', 'managesieve', 'jqueryui', 'persistent_login', 'carddav'); \$config['skin'] = 'elastic'; \$config['login_autocomplete'] = 2; From ae3feebd80195bd467262208f2cdada1b3fc458b Mon Sep 17 00:00:00 2001 From: Joshua Tauberer Date: Mon, 3 May 2021 19:04:59 -0400 Subject: [PATCH 04/20] Fix warnings reported by shellcheck * SC2068: Double quote array expansions to avoid re-splitting elements. * SC2186: tempfile is deprecated. Use mktemp instead. * SC2124: Assigning an array to a string! Assign as array, or use * instead of @ to concatenate. * SC2102: Ranges can only match single chars (mentioned due to duplicates). * SC2005: Useless echo? Instead of 'echo $(cmd)', just use 'cmd'. --- setup/functions.sh | 9 ++++----- setup/mail-postfix.sh | 2 +- setup/start.sh | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/setup/functions.sh b/setup/functions.sh index 90c4c55d..718a2283 100644 --- a/setup/functions.sh +++ b/setup/functions.sh @@ -9,12 +9,12 @@ function hide_output { # and returns a non-zero exit code. # Get a temporary file. - OUTPUT=$(tempfile) + OUTPUT=$(mktemp) # Execute command, redirecting stderr/stdout to the temporary file. Since we # check the return code ourselves, disable 'set -e' temporarily. set +e - $@ &> $OUTPUT + "$@" &> $OUTPUT E=$? set -e @@ -22,7 +22,7 @@ function hide_output { if [ $E != 0 ]; then # Something failed. echo - echo FAILED: $@ + echo FAILED: "$@" echo ----------------------------------------- cat $OUTPUT echo ----------------------------------------- @@ -53,8 +53,7 @@ function apt_install { # install' for all of the packages. Calling `dpkg` on each package is slow, # and doesn't affect what we actually do, except in the messages, so let's # not do that anymore. - PACKAGES=$@ - apt_get_quiet install $PACKAGES + apt_get_quiet install "$@" } function get_default_hostname { diff --git a/setup/mail-postfix.sh b/setup/mail-postfix.sh index 0a66cb0f..b16fd94a 100755 --- a/setup/mail-postfix.sh +++ b/setup/mail-postfix.sh @@ -191,7 +191,7 @@ tools/editconf.py /etc/postfix/main.cf \ # # In a basic setup we would pass mail directly to Dovecot by setting # virtual_transport to `lmtp:unix:private/dovecot-lmtp`. -tools/editconf.py /etc/postfix/main.cf virtual_transport=lmtp:[127.0.0.1]:10025 +tools/editconf.py /etc/postfix/main.cf "virtual_transport=lmtp:[127.0.0.1]:10025" # Because of a spampd bug, limit the number of recipients in each connection. # See https://github.com/mail-in-a-box/mailinabox/issues/1523. tools/editconf.py /etc/postfix/main.cf lmtp_destination_recipient_limit=1 diff --git a/setup/start.sh b/setup/start.sh index cedc426d..b4e38e65 100755 --- a/setup/start.sh +++ b/setup/start.sh @@ -78,7 +78,7 @@ if [ ! -d $STORAGE_ROOT ]; then mkdir -p $STORAGE_ROOT fi if [ ! -f $STORAGE_ROOT/mailinabox.version ]; then - echo $(setup/migrate.py --current) > $STORAGE_ROOT/mailinabox.version + setup/migrate.py --current > $STORAGE_ROOT/mailinabox.version chown $STORAGE_USER.$STORAGE_USER $STORAGE_ROOT/mailinabox.version fi From 9b07d86bf786bda73bc8c5ad95d2d9cb9e08be3f Mon Sep 17 00:00:00 2001 From: Joshua Tauberer Date: Mon, 3 May 2021 19:28:23 -0400 Subject: [PATCH 05/20] Use $(...) notation instead of legacy backtick notation for embedded shell commands shellcheck reported SC2006: Use $(...) notation instead of legacy backticked `...`. Fixed by applying shellcheck's diff output as a patch. --- setup/bootstrap.sh | 8 ++++---- setup/dns.sh | 2 +- setup/firstuser.sh | 4 ++-- setup/mail-dovecot.sh | 4 ++-- setup/management.sh | 4 ++-- setup/nextcloud.sh | 2 +- setup/preflight.sh | 2 +- setup/start.sh | 2 +- setup/webmail.sh | 2 +- setup/zpush.sh | 2 +- 10 files changed, 16 insertions(+), 16 deletions(-) diff --git a/setup/bootstrap.sh b/setup/bootstrap.sh index d804cadf..a9bc2ce8 100644 --- a/setup/bootstrap.sh +++ b/setup/bootstrap.sh @@ -18,11 +18,11 @@ if [ -z "$TAG" ]; then # space, but if we put it in a comment it would confuse the status checks!) # to get the latest version, so the first such line must be the one that we # want to display in status checks. - if [ "`lsb_release -d | sed 's/.*:\s*//' | sed 's/18\.04\.[0-9]/18.04/' `" == "Ubuntu 18.04 LTS" ]; then + if [ "$(lsb_release -d | sed 's/.*:\s*//' | sed 's/18\.04\.[0-9]/18.04/' )" == "Ubuntu 18.04 LTS" ]; then # This machine is running Ubuntu 18.04. TAG=v0.53 - elif [ "`lsb_release -d | sed 's/.*:\s*//' | sed 's/14\.04\.[0-9]/14.04/' `" == "Ubuntu 14.04 LTS" ]; then + elif [ "$(lsb_release -d | sed 's/.*:\s*//' | sed 's/14\.04\.[0-9]/14.04/' )" == "Ubuntu 14.04 LTS" ]; then # This machine is running Ubuntu 14.04. echo "You are installing the last version of Mail-in-a-Box that will" echo "support Ubuntu 14.04. If this is a new installation of Mail-in-a-Box," @@ -68,11 +68,11 @@ fi cd $HOME/mailinabox # Update it. -if [ "$TAG" != `git describe` ]; then +if [ "$TAG" != $(git describe) ]; then echo Updating Mail-in-a-Box to $TAG . . . git fetch --depth 1 --force --prune origin tag $TAG if ! git checkout -q $TAG; then - echo "Update failed. Did you modify something in `pwd`?" + echo "Update failed. Did you modify something in $(pwd)?" exit 1 fi echo diff --git a/setup/dns.sh b/setup/dns.sh index 2a1b6da0..b64a6580 100755 --- a/setup/dns.sh +++ b/setup/dns.sh @@ -132,7 +132,7 @@ cat > /etc/cron.daily/mailinabox-dnssec << EOF; #!/bin/bash # Mail-in-a-Box # Re-sign any DNS zones with DNSSEC because the signatures expire periodically. -`pwd`/tools/dns_update +$(pwd)/tools/dns_update EOF chmod +x /etc/cron.daily/mailinabox-dnssec diff --git a/setup/firstuser.sh b/setup/firstuser.sh index e2d6531c..7caec35d 100644 --- a/setup/firstuser.sh +++ b/setup/firstuser.sh @@ -1,5 +1,5 @@ # If there aren't any mail users yet, create one. -if [ -z "`management/cli.py user`" ]; then +if [ -z "$(management/cli.py user)" ]; then # The outut of "management/cli.py user" is a list of mail users. If there # aren't any yet, it'll be empty. @@ -10,7 +10,7 @@ if [ -z "`management/cli.py user`" ]; then input_box "Mail Account" \ "Let's create your first mail account. \n\nWhat email address do you want?" \ - me@`get_default_hostname` \ + me@$(get_default_hostname) \ EMAIL_ADDR if [ -z "$EMAIL_ADDR" ]; then diff --git a/setup/mail-dovecot.sh b/setup/mail-dovecot.sh index c6e6cb3a..b569c40d 100755 --- a/setup/mail-dovecot.sh +++ b/setup/mail-dovecot.sh @@ -45,8 +45,8 @@ apt_install \ # - https://www.dovecot.org/list/dovecot/2012-August/137569.html # - https://www.dovecot.org/list/dovecot/2011-December/132455.html tools/editconf.py /etc/dovecot/conf.d/10-master.conf \ - default_process_limit=$(echo "`nproc` * 250" | bc) \ - default_vsz_limit=$(echo "`free -tm | tail -1 | awk '{print $2}'` / 3" | bc)M \ + default_process_limit=$(echo "$(nproc) * 250" | bc) \ + default_vsz_limit=$(echo "$(free -tm | tail -1 | awk '{print $2}') / 3" | bc)M \ log_path=/var/log/mail.log # The inotify `max_user_instances` default is 128, which constrains diff --git a/setup/management.sh b/setup/management.sh index dcef0891..1c57bb2e 100755 --- a/setup/management.sh +++ b/setup/management.sh @@ -97,7 +97,7 @@ export LANG=en_US.UTF-8 export LC_TYPE=en_US.UTF-8 source $venv/bin/activate -exec python `pwd`/management/daemon.py +exec python $(pwd)/management/daemon.py EOF chmod +x $inst_dir/start cp --remove-destination conf/mailinabox.service /lib/systemd/system/mailinabox.service # target was previously a symlink so remove it first @@ -112,7 +112,7 @@ minute=$((RANDOM % 60)) # avoid overloading mailinabox.email cat > /etc/cron.d/mailinabox-nightly << EOF; # Mail-in-a-Box --- Do not edit / will be overwritten on update. # Run nightly tasks: backup, status checks. -$minute 3 * * * root (cd `pwd` && management/daily_tasks.sh) +$minute 3 * * * root (cd $(pwd) && management/daily_tasks.sh) EOF # Start the management server. diff --git a/setup/nextcloud.sh b/setup/nextcloud.sh index 200eba9e..98645987 100755 --- a/setup/nextcloud.sh +++ b/setup/nextcloud.sh @@ -128,7 +128,7 @@ if [ ! -d /usr/local/lib/owncloud/ ] || [[ ! ${CURRENT_NEXTCLOUD_VER} =~ ^$nextc # Backup the existing ownCloud/Nextcloud. # Create a backup directory to store the current installation and database to - BACKUP_DIRECTORY=$STORAGE_ROOT/owncloud-backup/`date +"%Y-%m-%d-%T"` + BACKUP_DIRECTORY=$STORAGE_ROOT/owncloud-backup/$(date +"%Y-%m-%d-%T") mkdir -p "$BACKUP_DIRECTORY" if [ -d /usr/local/lib/owncloud/ ]; then echo "Upgrading Nextcloud --- backing up existing installation, configuration, and database to directory to $BACKUP_DIRECTORY..." diff --git a/setup/preflight.sh b/setup/preflight.sh index acaf80c9..9d2715c5 100644 --- a/setup/preflight.sh +++ b/setup/preflight.sh @@ -8,7 +8,7 @@ if [[ $EUID -ne 0 ]]; then fi # Check that we are running on Ubuntu 18.04 LTS (or 18.04.xx). -if [ "`lsb_release -d | sed 's/.*:\s*//' | sed 's/18\.04\.[0-9]/18.04/' `" != "Ubuntu 18.04 LTS" ]; then +if [ "$(lsb_release -d | sed 's/.*:\s*//' | sed 's/18\.04\.[0-9]/18.04/' )" != "Ubuntu 18.04 LTS" ]; then echo "Mail-in-a-Box only supports being installed on Ubuntu 18.04, sorry. You are running:" echo lsb_release -d | sed 's/.*:\s*//' diff --git a/setup/start.sh b/setup/start.sh index b4e38e65..0cca66be 100755 --- a/setup/start.sh +++ b/setup/start.sh @@ -46,7 +46,7 @@ fi # in the first dialog prompt, so we should do this before that starts. cat > /usr/local/bin/mailinabox << EOF; #!/bin/bash -cd `pwd` +cd $(pwd) source setup/start.sh EOF chmod +x /usr/local/bin/mailinabox diff --git a/setup/webmail.sh b/setup/webmail.sh index 98e12d1a..55fea631 100755 --- a/setup/webmail.sh +++ b/setup/webmail.sh @@ -47,7 +47,7 @@ needs_update=0 #NODOC if [ ! -f /usr/local/lib/roundcubemail/version ]; then # not installed yet #NODOC needs_update=1 #NODOC -elif [[ "$UPDATE_KEY" != `cat /usr/local/lib/roundcubemail/version` ]]; then +elif [[ "$UPDATE_KEY" != $(cat /usr/local/lib/roundcubemail/version) ]]; then # checks if the version is what we want needs_update=1 #NODOC fi diff --git a/setup/zpush.sh b/setup/zpush.sh index 1a84e86a..783f39a4 100755 --- a/setup/zpush.sh +++ b/setup/zpush.sh @@ -27,7 +27,7 @@ TARGETHASH=4b312d64227ef887b24d9cc8f0ae17519586f6e2 needs_update=0 #NODOC if [ ! -f /usr/local/lib/z-push/version ]; then needs_update=1 #NODOC -elif [[ $VERSION != `cat /usr/local/lib/z-push/version` ]]; then +elif [[ $VERSION != $(cat /usr/local/lib/z-push/version) ]]; then # checks if the version needs_update=1 #NODOC fi From 69fc2fdd3aa0e1c88d7fa7434560025e1b97848c Mon Sep 17 00:00:00 2001 From: Joshua Tauberer Date: Mon, 3 May 2021 19:41:00 -0400 Subject: [PATCH 06/20] Hide spurrious Nextcloud setup output --- setup/nextcloud.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/setup/nextcloud.sh b/setup/nextcloud.sh index 98645987..3d865359 100755 --- a/setup/nextcloud.sh +++ b/setup/nextcloud.sh @@ -312,7 +312,9 @@ sudo -u www-data php /usr/local/lib/owncloud/occ upgrade if [ \( $? -ne 0 \) -a \( $? -ne 3 \) ]; then exit 1; fi # Disable default apps that we don't support -sudo -u www-data php /usr/local/lib/owncloud/occ app:disable photos dashboard activity +sudo -u www-data \ + php /usr/local/lib/owncloud/occ app:disable photos dashboard activity \ + | grep -v "No such app enabled" # Set PHP FPM values to support large file uploads # (semicolon is the comment character in this file, hashes produce deprecation warnings) From 16e81e14392ed70ce36c241b53c83e2751060e5f Mon Sep 17 00:00:00 2001 From: jvolkenant Date: Sat, 8 May 2021 05:18:49 -0700 Subject: [PATCH 07/20] Fix to allow for non forced "enforce" MTA_STS_MODE (#1970) --- setup/start.sh | 2 +- setup/web.sh | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/setup/start.sh b/setup/start.sh index 0cca66be..bd743ac5 100755 --- a/setup/start.sh +++ b/setup/start.sh @@ -94,7 +94,7 @@ PUBLIC_IP=$PUBLIC_IP PUBLIC_IPV6=$PUBLIC_IPV6 PRIVATE_IP=$PRIVATE_IP PRIVATE_IPV6=$PRIVATE_IPV6 -MTA_STS_MODE=${MTA_STS_MODE-} +MTA_STS_MODE=${DEFAULT_MTA_STS_MODE:-enforce} EOF # Start service configuration. diff --git a/setup/web.sh b/setup/web.sh index 42c301ec..4433ff0d 100755 --- a/setup/web.sh +++ b/setup/web.sh @@ -126,13 +126,13 @@ chmod a+r /var/lib/mailinabox/mozilla-autoconfig.xml # nginx configuration at /.well-known/mta-sts.txt # more documentation is available on: # https://www.uriports.com/blog/mta-sts-explained/ -# default mode is "enforce". Change to "testing" which means -# "Messages will be delivered as though there was no failure -# but a report will be sent if TLS-RPT is configured" if you -# are not sure you want this yet. Or "none". +# default mode is "enforce". In /etc/mailinabox.conf change +# "MTA_STS_MODE=testing" which means "Messages will be delivered +# as though there was no failure but a report will be sent if +# TLS-RPT is configured" if you are not sure you want this yet. Or "none". PUNY_PRIMARY_HOSTNAME=$(echo "$PRIMARY_HOSTNAME" | idn2) cat conf/mta-sts.txt \ - | sed "s/MODE/${MTA_STS_MODE:-enforce}/" \ + | sed "s/MODE/${MTA_STS_MODE}/" \ | sed "s/PRIMARY_HOSTNAME/$PUNY_PRIMARY_HOSTNAME/" \ > /var/lib/mailinabox/mta-sts.txt chmod a+r /var/lib/mailinabox/mta-sts.txt From 49813534bdaeaa82e3ac1ee70b78e91af5783dba Mon Sep 17 00:00:00 2001 From: jvolkenant Date: Sat, 8 May 2021 05:24:04 -0700 Subject: [PATCH 08/20] Updated Nextcloud to 20.0.8, contacts to 3.5.1, calendar to 2.2.0 (#1960) --- setup/nextcloud.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/setup/nextcloud.sh b/setup/nextcloud.sh index 3d865359..57e5e039 100755 --- a/setup/nextcloud.sh +++ b/setup/nextcloud.sh @@ -97,12 +97,12 @@ InstallNextcloud() { } # Nextcloud Version to install. Checks are done down below to step through intermediate versions. -nextcloud_ver=20.0.1 -nextcloud_hash=f2b3faa570c541df73f209e873a1c2852e79eab8 -contacts_ver=3.4.1 -contacts_hash=aee680a75e95f26d9285efd3c1e25cf7f3bfd27e -calendar_ver=2.1.2 -calendar_hash=930c07863bb7a65652dec34793802c8d80502336 +nextcloud_ver=20.0.8 +nextcloud_hash=372b0b4bb07c7984c04917aff86b280e68fbe761 +contacts_ver=3.5.1 +contacts_hash=d2ffbccd3ed89fa41da20a1dff149504c3b33b93 +calendar_ver=2.2.0 +calendar_hash=673ad72ca28adb8d0f209015ff2dca52ffad99af user_external_ver=1.0.0 user_external_hash=3bf2609061d7214e7f0f69dd8883e55c4ec8f50a From 12aaebfc54972cab4edd990f1eec519535314a69 Mon Sep 17 00:00:00 2001 From: Jawad Seddar Date: Sat, 8 May 2021 14:25:33 +0200 Subject: [PATCH 09/20] `custom.yaml`: add support for X-Frame-Options header and proxy_redirect off (#1954) --- management/web_update.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/management/web_update.py b/management/web_update.py index 83aa91bf..5048cbab 100644 --- a/management/web_update.py +++ b/management/web_update.py @@ -160,17 +160,27 @@ def make_domain_config(domain, templates, ssl_certificates, env): for path, url in yaml.get("proxies", {}).items(): # Parse some flags in the fragment of the URL. pass_http_host_header = False + proxy_redirect_off = False + frame_options_header_sameorigin = False m = re.search("#(.*)$", url) if m: for flag in m.group(1).split(","): if flag == "pass-http-host": pass_http_host_header = True + elif flag == "no-proxy-redirect": + proxy_redirect_off = True + elif flag == "frame-options-sameorigin": + frame_options_header_sameorigin = True url = re.sub("#(.*)$", "", url) nginx_conf_extra += "\tlocation %s {" % path nginx_conf_extra += "\n\t\tproxy_pass %s;" % url + if proxy_redirect_off: + nginx_conf_extra += "\n\t\tproxy_redirect off;" if pass_http_host_header: nginx_conf_extra += "\n\t\tproxy_set_header Host $http_host;" + if frame_options_header_sameorigin: + nginx_conf_extra += "\n\t\tproxy_set_header X-Frame-Options SAMEORIGIN;" nginx_conf_extra += "\n\t\tproxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;" nginx_conf_extra += "\n\t\tproxy_set_header X-Forwarded-Host $http_host;" nginx_conf_extra += "\n\t\tproxy_set_header X-Forwarded-Proto $scheme;" @@ -251,3 +261,4 @@ def get_web_domains_info(env): } for domain in get_web_domains(env) ] + From bc4ae51c2d19c7753d1c2e65bc26b443dd5048c8 Mon Sep 17 00:00:00 2001 From: Hala Alajlan <36444614+halaalajlan@users.noreply.github.com> Date: Sat, 8 May 2021 15:26:40 +0300 Subject: [PATCH 10/20] Handle query dns timeout unhandled error (#1950) Co-authored-by: hala alajlan --- management/status_checks.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/management/status_checks.py b/management/status_checks.py index 607fd578..1b2a16ca 100755 --- a/management/status_checks.py +++ b/management/status_checks.py @@ -664,6 +664,8 @@ def check_mail_domain(domain, env, output): if mx is None: mxhost = None + elif mx == "[timeout]": + mxhost = None else: # query_dns returns a semicolon-delimited list # of priority-host pairs. From 3701e05d925fe780e1a43e4d54b247473136f841 Mon Sep 17 00:00:00 2001 From: Thomas Urban Date: Sat, 8 May 2021 14:30:53 +0200 Subject: [PATCH 11/20] Rewrite envelope from address in sieve forwards (#1949) Fixes #1946. --- setup/mail-dovecot.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/setup/mail-dovecot.sh b/setup/mail-dovecot.sh index b569c40d..26d32895 100755 --- a/setup/mail-dovecot.sh +++ b/setup/mail-dovecot.sh @@ -183,6 +183,7 @@ plugin { sieve_after = $STORAGE_ROOT/mail/sieve/global_after sieve = $STORAGE_ROOT/mail/sieve/%d/%n.sieve sieve_dir = $STORAGE_ROOT/mail/sieve/%d/%n + sieve_redirect_envelope_from = recipient } EOF From d4c5872547ee0222759be7c195a358698c5dfa66 Mon Sep 17 00:00:00 2001 From: "John @ S4" <64874788+John-S4@users.noreply.github.com> Date: Sat, 8 May 2021 05:32:58 -0700 Subject: [PATCH 12/20] Make clear that non-AWS S3 backups are supported (#1947) Just a few wording changes to show that it is possible to make S3 backups to other services than AWS - prompted by a thread on MIAB discourse. --- management/templates/system-backup.html | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/management/templates/system-backup.html b/management/templates/system-backup.html index 7cdc3803..a63b38e6 100644 --- a/management/templates/system-backup.html +++ b/management/templates/system-backup.html @@ -5,7 +5,7 @@

Backup Status

-

The box makes an incremental backup each night. By default the backup is stored on the machine itself, but you can also have it stored on Amazon S3.

+

The box makes an incremental backup each night. By default the backup is stored on the machine itself, but you can also store in on S3-compatible services like Amazon Web Services (AWS).

Configuration

@@ -17,7 +17,7 @@ - + @@ -73,8 +73,8 @@
-

Backups are stored in an Amazon Web Services S3 bucket. You must have an AWS account already.

-

You MUST manually copy the encryption password from to a safe and secure location. You will need this file to decrypt backup files. It is NOT stored in your Amazon S3 bucket.

+

Backups are stored in an S3-compatible bucket. You must have an AWS or other S3 service account already.

+

You MUST manually copy the encryption password from to a safe and secure location. You will need this file to decrypt backup files. It is NOT stored in your S3 bucket.

@@ -84,7 +84,7 @@ {% for name, host in backup_s3_hosts %} {% endfor %} - +
@@ -343,4 +343,4 @@ function init_inputs(target_type) { set_host($('#backup-target-s3-host-select').val()); } } - \ No newline at end of file + From dbd6dae5ceda7cc0ce2c132be1f0b795f0a2c363 Mon Sep 17 00:00:00 2001 From: Joshua Tauberer Date: Sat, 8 May 2021 09:01:40 -0400 Subject: [PATCH 13/20] Fix exit status issue cased by 69fc2fdd --- setup/nextcloud.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/nextcloud.sh b/setup/nextcloud.sh index 57e5e039..af848344 100755 --- a/setup/nextcloud.sh +++ b/setup/nextcloud.sh @@ -314,7 +314,7 @@ if [ \( $? -ne 0 \) -a \( $? -ne 3 \) ]; then exit 1; fi # Disable default apps that we don't support sudo -u www-data \ php /usr/local/lib/owncloud/occ app:disable photos dashboard activity \ - | grep -v "No such app enabled" + | (grep -v "No such app enabled" || /bin/true) # Set PHP FPM values to support large file uploads # (semicolon is the comment character in this file, hashes produce deprecation warnings) From aaa81ec87979decb50a352bee30d93e3d748439d Mon Sep 17 00:00:00 2001 From: Joshua Tauberer Date: Sat, 8 May 2021 09:06:18 -0400 Subject: [PATCH 14/20] Fix indentation issue in bc4ae51c2d19c7753d1c2e65bc26b443dd5048c8 --- management/status_checks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/management/status_checks.py b/management/status_checks.py index 1b2a16ca..67b26974 100755 --- a/management/status_checks.py +++ b/management/status_checks.py @@ -665,7 +665,7 @@ def check_mail_domain(domain, env, output): if mx is None: mxhost = None elif mx == "[timeout]": - mxhost = None + mxhost = None else: # query_dns returns a semicolon-delimited list # of priority-host pairs. From 354a774989b52a6084a9610dace0539d995ceead Mon Sep 17 00:00:00 2001 From: Joshua Tauberer Date: Sun, 9 May 2021 07:34:44 -0400 Subject: [PATCH 15/20] Remove a debug line added in 8cda58fb --- management/dns_update.py | 1 - 1 file changed, 1 deletion(-) diff --git a/management/dns_update.py b/management/dns_update.py index c595bc3b..ff1e97ef 100755 --- a/management/dns_update.py +++ b/management/dns_update.py @@ -360,7 +360,6 @@ def is_domain_cert_signed_and_valid(domain, env): cert = get_ssl_certificates(env).get(domain) if not cert: return False # no certificate provisioned cert_status = check_certificate(domain, cert['certificate'], cert['private-key']) - print(domain, cert_status) return cert_status[0] == 'OK' ######################################################################## From e421addf1c13f4ba13f09b645f6d83a1772e4483 Mon Sep 17 00:00:00 2001 From: Joshua Tauberer Date: Sun, 9 May 2021 08:16:07 -0400 Subject: [PATCH 16/20] Pre-load domain purpopses when building DNS zonefiles rather than querying mail domains at each subdomain --- management/dns_update.py | 77 +++++++++++++++++++++++++++------------- management/web_update.py | 19 +++++----- 2 files changed, 62 insertions(+), 34 deletions(-) diff --git a/management/dns_update.py b/management/dns_update.py index ff1e97ef..a9a686da 100755 --- a/management/dns_update.py +++ b/management/dns_update.py @@ -9,7 +9,6 @@ import ipaddress import rtyaml import dns.resolver -from mailconfig import get_mail_domains, get_mail_aliases from utils import shell, load_env_vars_from_file, safe_domain_name, sort_domains from ssl_certificates import get_ssl_certificates, check_certificate @@ -20,10 +19,14 @@ from ssl_certificates import get_ssl_certificates, check_certificate DOMAIN_RE = "^(?!\-)(?:[*][.])?(?:[a-zA-Z\d\-_]{0,62}[a-zA-Z\d_]\.){1,126}(?!\d+)[a-zA-Z\d_]{1,63}(\.?)$" def get_dns_domains(env): - # Add all domain names in use by email users and mail aliases and ensure - # PRIMARY_HOSTNAME is in the list. + # Add all domain names in use by email users and mail aliases, any + # domains we serve web for (except www redirects because that would + # lead to infinite recursion here) and ensure PRIMARY_HOSTNAME is in the list. + from mailconfig import get_mail_domains + from web_update import get_web_domains domains = set() - domains |= get_mail_domains(env) + domains |= set(get_mail_domains(env)) + domains |= set(get_web_domains(env, include_www_redirects=False)) domains.add(env['PRIMARY_HOSTNAME']) return domains @@ -97,7 +100,8 @@ def do_dns_update(env, force=False): if len(updated_domains) > 0: shell('check_call', ["/usr/sbin/service", "nsd", "restart"]) - # Write the OpenDKIM configuration tables for all of the domains. + # Write the OpenDKIM configuration tables for all of the mail domains. + from mailconfig import get_mail_domains if write_opendkim_tables(get_mail_domains(env), env): # Settings changed. Kick opendkim. shell('check_call', ["/usr/sbin/service", "opendkim", "restart"]) @@ -122,24 +126,44 @@ def build_zones(env): domains = get_dns_domains(env) zonefiles = get_dns_zones(env) - # Custom records to add to zones. - additional_records = list(get_custom_dns_config(env)) + # Create a dictionary of domains to a set of attributes for each + # domain, such as whether there are mail users at the domain. + from mailconfig import get_mail_domains from web_update import get_web_domains - www_redirect_domains = set(get_web_domains(env)) - set(get_web_domains(env, include_www_redirects=False)) + mail_domains = set(get_mail_domains(env)) + mail_user_domains = set(get_mail_domains(env, users_only=True)) # i.e. will log in for mail, Nextcloud + web_domains = set(get_web_domains(env)) + auto_domains = web_domains - set(get_web_domains(env, include_auto=False)) + domains |= auto_domains # www redirects not included in the initial list, see above + domains = { + domain: { + "user": domain in mail_user_domains, + "mail": domain in mail_domains, + "web": domain in web_domains, + "auto": domain in auto_domains, + } + for domain in domains + } # For MTA-STS, we'll need to check if the PRIMARY_HOSTNAME certificate is # singned and valid. Check that now rather than repeatedly for each domain. - env["-primary-hostname-certificate-is-valid"] = is_domain_cert_signed_and_valid(env["PRIMARY_HOSTNAME"], env) + domains[env["PRIMARY_HOSTNAME"]]["certificate-is-valid"] = is_domain_cert_signed_and_valid(env["PRIMARY_HOSTNAME"], env) + + # Load custom records to add to zones. + additional_records = list(get_custom_dns_config(env)) # Build DNS records for each zone. for domain, zonefile in zonefiles: # Build the records to put in the zone. - records = build_zone(domain, domains, additional_records, www_redirect_domains, env) + records = build_zone(domain, domains, additional_records, env) yield (domain, zonefile, records) -def build_zone(domain, all_domains, additional_records, www_redirect_domains, env, is_zone=True): +def build_zone(domain, domain_properties, additional_records, env, is_zone=True): records = [] + # Skip www redirect and autoconfiguration domains here because they are set at the zone level directly. + if domain_properties[domain]["auto"]: return records + # For top-level zones, define the authoritative name servers. # # Normally we are our own nameservers. Some TLDs require two distinct IP addresses, @@ -188,16 +212,17 @@ def build_zone(domain, all_domains, additional_records, www_redirect_domains, en # Add DNS records for any subdomains of this domain. We should not have a zone for # both a domain and one of its subdomains. - subdomains = [d for d in all_domains if d.endswith("." + domain)] - for subdomain in subdomains: - subdomain_qname = subdomain[0:-len("." + domain)] - subzone = build_zone(subdomain, [], additional_records, www_redirect_domains, env, is_zone=False) - for child_qname, child_rtype, child_value, child_explanation in subzone: - if child_qname == None: - child_qname = subdomain_qname - else: - child_qname += "." + subdomain_qname - records.append((child_qname, child_rtype, child_value, child_explanation)) + if is_zone: # don't recurse when we're just loading data for a subdomain + subdomains = [d for d in domain_properties if d.endswith("." + domain)] + for subdomain in subdomains: + subdomain_qname = subdomain[0:-len("." + domain)] + subzone = build_zone(subdomain, domain_properties, additional_records, env, is_zone=False) + for child_qname, child_rtype, child_value, child_explanation in subzone: + if child_qname == None: + child_qname = subdomain_qname + else: + child_qname += "." + subdomain_qname + records.append((child_qname, child_rtype, child_value, child_explanation)) has_rec_base = list(records) # clone current state def has_rec(qname, rtype, prefix=None): @@ -234,7 +259,7 @@ def build_zone(domain, all_domains, additional_records, www_redirect_domains, en (None, "A", env["PUBLIC_IP"], "Required. May have a different value. Sets the IP address that %s resolves to for web hosting and other services besides mail. The A record must be present but its value does not affect mail delivery." % domain), (None, "AAAA", env.get('PUBLIC_IPV6'), "Optional. Sets the IPv6 address that %s resolves to, e.g. for web hosting. (It is not necessary for receiving mail on this domain.)" % domain), ] - if "www." + domain in www_redirect_domains: + if domain_properties.get("www." + domain, {}).get("auto"): defaults += [ ("www", "A", env["PUBLIC_IP"], "Optional. Sets the IP address that www.%s resolves to so that the box can provide a redirect to the parent domain." % domain), ("www", "AAAA", env.get('PUBLIC_IPV6'), "Optional. Sets the IPv6 address that www.%s resolves to so that the box can provide a redirect to the parent domain." % domain), @@ -288,7 +313,7 @@ def build_zone(domain, all_domains, additional_records, www_redirect_domains, en # Add CardDAV/CalDAV SRV records on the non-primary hostname that points to the primary hostname # for autoconfiguration of mail clients (so only domains hosting user accounts need it). # The SRV record format is priority (0, whatever), weight (0, whatever), port, service provider hostname (w/ trailing dot). - if domain != env["PRIMARY_HOSTNAME"] and domain in get_mail_domains(env, users_only=True): + if domain != env["PRIMARY_HOSTNAME"] and domain_properties[domain]["user"]: for dav in ("card", "cal"): qname = "_" + dav + "davs._tcp" if not has_rec(qname, "SRV"): @@ -298,7 +323,7 @@ def build_zone(domain, all_domains, additional_records, www_redirect_domains, en # This allows the following clients to automatically configure email addresses in the respective applications. # autodiscover.* - Z-Push ActiveSync Autodiscover # autoconfig.* - Thunderbird Autoconfig - if domain in get_mail_domains(env, users_only=True): + if domain_properties[domain]["user"]: autodiscover_records = [ ("autodiscover", "A", env["PUBLIC_IP"], "Provides email configuration autodiscovery support for Z-Push ActiveSync Autodiscover."), ("autodiscover", "AAAA", env["PUBLIC_IPV6"], "Provides email configuration autodiscovery support for Z-Push ActiveSync Autodiscover."), @@ -330,7 +355,9 @@ def build_zone(domain, all_domains, additional_records, www_redirect_domains, en ("mta-sts", "A", env["PUBLIC_IP"], "Optional. MTA-STS Policy Host serving /.well-known/mta-sts.txt."), ("mta-sts", "AAAA", env.get('PUBLIC_IPV6'), "Optional. MTA-STS Policy Host serving /.well-known/mta-sts.txt."), ] - if domain in get_mail_domains(env) and env["-primary-hostname-certificate-is-valid"] and is_domain_cert_signed_and_valid("mta-sts." + domain, env): + if domain_properties[domain]["mail"] \ + and domain_properties[env["PRIMARY_HOSTNAME"]]["certificate-is-valid"] \ + and is_domain_cert_signed_and_valid("mta-sts." + domain, env): # Compute an up-to-32-character hash of the policy file. We'll take a SHA-1 hash of the policy # file (20 bytes) and encode it as base-64 (28 bytes, using alphanumeric alternate characters # instead of '+' and '/' which are not allowed in an MTA-STS policy id) but then just take its diff --git a/management/web_update.py b/management/web_update.py index 5048cbab..809106e4 100644 --- a/management/web_update.py +++ b/management/web_update.py @@ -9,7 +9,7 @@ from dns_update import get_custom_dns_config, get_dns_zones from ssl_certificates import get_ssl_certificates, get_domain_ssl_files, check_certificate from utils import shell, safe_domain_name, sort_domains -def get_web_domains(env, include_www_redirects=True, exclude_dns_elsewhere=True): +def get_web_domains(env, include_www_redirects=True, include_auto=True, exclude_dns_elsewhere=True): # What domains should we serve HTTP(S) for? domains = set() @@ -18,20 +18,21 @@ def get_web_domains(env, include_www_redirects=True, exclude_dns_elsewhere=True) # if the user wants to make one. domains |= get_mail_domains(env) - if include_www_redirects: + if include_www_redirects and include_auto: # Add 'www.' subdomains that we want to provide default redirects # to the main domain for. We'll add 'www.' to any DNS zones, i.e. # the topmost of each domain we serve. domains |= set('www.' + zone for zone, zonefile in get_dns_zones(env)) - # Add Autoconfiguration domains for domains that there are user accounts at: - # 'autoconfig.' for Mozilla Thunderbird auto setup. - # 'autodiscover.' for Activesync autodiscovery. - domains |= set('autoconfig.' + maildomain for maildomain in get_mail_domains(env, users_only=True)) - domains |= set('autodiscover.' + maildomain for maildomain in get_mail_domains(env, users_only=True)) + if include_auto: + # Add Autoconfiguration domains for domains that there are user accounts at: + # 'autoconfig.' for Mozilla Thunderbird auto setup. + # 'autodiscover.' for Activesync autodiscovery. + domains |= set('autoconfig.' + maildomain for maildomain in get_mail_domains(env, users_only=True)) + domains |= set('autodiscover.' + maildomain for maildomain in get_mail_domains(env, users_only=True)) - # 'mta-sts.' for MTA-STS support for all domains that have email addresses. - domains |= set('mta-sts.' + maildomain for maildomain in get_mail_domains(env)) + # 'mta-sts.' for MTA-STS support for all domains that have email addresses. + domains |= set('mta-sts.' + maildomain for maildomain in get_mail_domains(env)) if exclude_dns_elsewhere: # ...Unless the domain has an A/AAAA record that maps it to a different From e283a1204728024c3e0cf77fdb5292fbdecde85f Mon Sep 17 00:00:00 2001 From: Joshua Tauberer Date: Sun, 9 May 2021 08:59:44 -0400 Subject: [PATCH 17/20] Add null SPF, DMARC, and MX records for automatically generated autoconfig, autodiscover, and mta-sts subdomains; add null MX records for custom A-record subdomains All A/AAAA-resolvable domains that don't send or receive mail should have these null records. This simplifies the handling of domains a bit by handling automatically generated subdomains more like other domains. --- CHANGELOG.md | 8 ++- management/dns_update.py | 149 ++++++++++++++++++--------------------- management/web_update.py | 2 +- 3 files changed, 78 insertions(+), 81 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb4c0b60..df69bbe4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,15 @@ CHANGELOG In Development -------------- -* Migrate to the ECDSAP256SHA256 DNSSEC algorithm. If a DS record is set for any of your domain names that have DNS hosted on your box, you will be prompted by status checks to update the DS record. +Mail: + * Roundcube's login cookie is updated to use a new encryption algorithm (AES-256-CBC instead of DES-EDE-CBC). +DNS: + +* The ECDSAP256SHA256 DNSSEC algorithm is now available. If a DS record is set for any of your domain names that have DNS hosted on your box, you will be prompted by status checks to update the DS record at your convenience. +* Null MX records are added for domains that do not serve mail. + v0.53a (May 8, 2021) -------------------- diff --git a/management/dns_update.py b/management/dns_update.py index a9a686da..c000f345 100755 --- a/management/dns_update.py +++ b/management/dns_update.py @@ -135,6 +135,14 @@ def build_zones(env): web_domains = set(get_web_domains(env)) auto_domains = web_domains - set(get_web_domains(env, include_auto=False)) domains |= auto_domains # www redirects not included in the initial list, see above + + # Add ns1/ns2+PRIMARY_HOSTNAME which must also have A/AAAA records + # when the box is acting as authoritative DNS server for its domains. + for ns in ("ns1", "ns2"): + d = ns + "." + env["PRIMARY_HOSTNAME"] + domains.add(d) + auto_domains.add(d) + domains = { domain: { "user": domain in mail_user_domains, @@ -161,9 +169,6 @@ def build_zones(env): def build_zone(domain, domain_properties, additional_records, env, is_zone=True): records = [] - # Skip www redirect and autoconfiguration domains here because they are set at the zone level directly. - if domain_properties[domain]["auto"]: return records - # For top-level zones, define the authoritative name servers. # # Normally we are our own nameservers. Some TLDs require two distinct IP addresses, @@ -173,10 +178,10 @@ def build_zone(domain, domain_properties, additional_records, env, is_zone=True) # 'False' in the tuple indicates these records would not be used if the zone # is managed outside of the box. if is_zone: - # Obligatory definition of ns1.PRIMARY_HOSTNAME. + # Obligatory NS record to ns1.PRIMARY_HOSTNAME. records.append((None, "NS", "ns1.%s." % env["PRIMARY_HOSTNAME"], False)) - # Define ns2.PRIMARY_HOSTNAME or whatever the user overrides. + # NS record to ns2.PRIMARY_HOSTNAME or whatever the user overrides. # User may provide one or more additional nameservers secondary_ns_list = get_secondary_dns(additional_records, mode="NS") \ or ["ns2." + env["PRIMARY_HOSTNAME"]] @@ -186,15 +191,6 @@ def build_zone(domain, domain_properties, additional_records, env, is_zone=True) # In PRIMARY_HOSTNAME... if domain == env["PRIMARY_HOSTNAME"]: - # Define ns1 and ns2. - # 'False' in the tuple indicates these records would not be used if the zone - # is managed outside of the box. - records.append(("ns1", "A", env["PUBLIC_IP"], False)) - records.append(("ns2", "A", env["PUBLIC_IP"], False)) - if env.get('PUBLIC_IPV6'): - records.append(("ns1", "AAAA", env["PUBLIC_IPV6"], False)) - records.append(("ns2", "AAAA", env["PUBLIC_IPV6"], False)) - # Set the A/AAAA records. Do this early for the PRIMARY_HOSTNAME so that the user cannot override them # and we can provide different explanatory text. records.append((None, "A", env["PUBLIC_IP"], "Required. Sets the IP address of the box.")) @@ -249,21 +245,23 @@ def build_zone(domain, domain_properties, additional_records, env, is_zone=True) continue records.append((qname, rtype, value, "(Set by user.)")) - # Add defaults if not overridden by the user's custom settings (and not otherwise configured). + # Add A/AAAA defaults if not overridden by the user's custom settings (and not otherwise configured). # Any CNAME or A record on the qname overrides A and AAAA. But when we set the default A record, # we should not cause the default AAAA record to be skipped because it thinks a custom A record # was set. So set has_rec_base to a clone of the current set of DNS settings, and don't update # during this process. has_rec_base = list(records) + a_expl = "Required. May have a different value. Sets the IP address that %s resolves to for web hosting and other services besides mail. The A record must be present but its value does not affect mail delivery." % domain + if domain_properties[domain]["auto"]: + if domain.startswith("ns1.") or domain.startswith("ns2."): a_expl = False # omit from 'External DNS' page since this only applies if box is its own DNS server + if domain.startswith("www."): a_expl = "Optional. Sets the IP address that %s resolves to so that the box can provide a redirect to the parent domain." % domain + if domain.startswith("mta-sts."): a_expl = "Optional. MTA-STS Policy Host serving /.well-known/mta-sts.txt." + if domain.startswith("autoconfig."): a_expl = "Provides email configuration autodiscovery support for Thunderbird Autoconfig." + if domain.startswith("autodiscover."): a_expl = "Provides email configuration autodiscovery support for Z-Push ActiveSync Autodiscover." defaults = [ - (None, "A", env["PUBLIC_IP"], "Required. May have a different value. Sets the IP address that %s resolves to for web hosting and other services besides mail. The A record must be present but its value does not affect mail delivery." % domain), + (None, "A", env["PUBLIC_IP"], a_expl), (None, "AAAA", env.get('PUBLIC_IPV6'), "Optional. Sets the IPv6 address that %s resolves to, e.g. for web hosting. (It is not necessary for receiving mail on this domain.)" % domain), ] - if domain_properties.get("www." + domain, {}).get("auto"): - defaults += [ - ("www", "A", env["PUBLIC_IP"], "Optional. Sets the IP address that www.%s resolves to so that the box can provide a redirect to the parent domain." % domain), - ("www", "AAAA", env.get('PUBLIC_IPV6'), "Optional. Sets the IPv6 address that www.%s resolves to so that the box can provide a redirect to the parent domain." % domain), - ] for qname, rtype, value, explanation in defaults: if value is None or value.strip() == "": continue # skip IPV6 if not set if not is_zone and qname == "www": continue # don't create any default 'www' subdomains on what are themselves subdomains @@ -277,63 +275,40 @@ def build_zone(domain, domain_properties, additional_records, env, is_zone=True) # Don't pin the list of records that has_rec checks against anymore. has_rec_base = records - # The MX record says where email for the domain should be delivered: Here! - if not has_rec(None, "MX", prefix="10 "): - records.append((None, "MX", "10 %s." % env["PRIMARY_HOSTNAME"], "Required. Specifies the hostname (and priority) of the machine that handles @%s mail." % domain)) + if domain_properties[domain]["mail"]: + # The MX record says where email for the domain should be delivered: Here! + if not has_rec(None, "MX", prefix="10 "): + records.append((None, "MX", "10 %s." % env["PRIMARY_HOSTNAME"], "Required. Specifies the hostname (and priority) of the machine that handles @%s mail." % domain)) - # SPF record: Permit the box ('mx', see above) to send mail on behalf of - # the domain, and no one else. - # Skip if the user has set a custom SPF record. - if not has_rec(None, "TXT", prefix="v=spf1 "): - records.append((None, "TXT", 'v=spf1 mx -all', "Recommended. Specifies that only the box is permitted to send @%s mail." % domain)) + # SPF record: Permit the box ('mx', see above) to send mail on behalf of + # the domain, and no one else. + # Skip if the user has set a custom SPF record. + if not has_rec(None, "TXT", prefix="v=spf1 "): + records.append((None, "TXT", 'v=spf1 mx -all', "Recommended. Specifies that only the box is permitted to send @%s mail." % domain)) - # Append the DKIM TXT record to the zone as generated by OpenDKIM. - # Skip if the user has set a DKIM record already. - opendkim_record_file = os.path.join(env['STORAGE_ROOT'], 'mail/dkim/mail.txt') - with open(opendkim_record_file) as orf: - m = re.match(r'(\S+)\s+IN\s+TXT\s+\( ((?:"[^"]+"\s+)+)\)', orf.read(), re.S) - val = "".join(re.findall(r'"([^"]+)"', m.group(2))) - if not has_rec(m.group(1), "TXT", prefix="v=DKIM1; "): - records.append((m.group(1), "TXT", val, "Recommended. Provides a way for recipients to verify that this machine sent @%s mail." % domain)) + # Append the DKIM TXT record to the zone as generated by OpenDKIM. + # Skip if the user has set a DKIM record already. + opendkim_record_file = os.path.join(env['STORAGE_ROOT'], 'mail/dkim/mail.txt') + with open(opendkim_record_file) as orf: + m = re.match(r'(\S+)\s+IN\s+TXT\s+\( ((?:"[^"]+"\s+)+)\)', orf.read(), re.S) + val = "".join(re.findall(r'"([^"]+)"', m.group(2))) + if not has_rec(m.group(1), "TXT", prefix="v=DKIM1; "): + records.append((m.group(1), "TXT", val, "Recommended. Provides a way for recipients to verify that this machine sent @%s mail." % domain)) - # Append a DMARC record. - # Skip if the user has set a DMARC record already. - if not has_rec("_dmarc", "TXT", prefix="v=DMARC1; "): - records.append(("_dmarc", "TXT", 'v=DMARC1; p=quarantine', "Recommended. Specifies that mail that does not originate from the box but claims to be from @%s or which does not have a valid DKIM signature is suspect and should be quarantined by the recipient's mail system." % domain)) + # Append a DMARC record. + # Skip if the user has set a DMARC record already. + if not has_rec("_dmarc", "TXT", prefix="v=DMARC1; "): + records.append(("_dmarc", "TXT", 'v=DMARC1; p=quarantine', "Recommended. Specifies that mail that does not originate from the box but claims to be from @%s or which does not have a valid DKIM signature is suspect and should be quarantined by the recipient's mail system." % domain)) - # For any subdomain with an A record but no SPF or DMARC record, add strict policy records. - all_resolvable_qnames = set(r[0] for r in records if r[1] in ("A", "AAAA")) - for qname in all_resolvable_qnames: - if not has_rec(qname, "TXT", prefix="v=spf1 "): - records.append((qname, "TXT", 'v=spf1 -all', "Recommended. Prevents use of this domain name for outbound mail by specifying that no servers are valid sources for mail from @%s. If you do send email from this domain name you should either override this record such that the SPF rule does allow the originating server, or, take the recommended approach and have the box handle mail for this domain (simply add any receiving alias at this domain name to make this machine treat the domain name as one of its mail domains)." % (qname + "." + domain))) - dmarc_qname = "_dmarc" + ("" if qname is None else "." + qname) - if not has_rec(dmarc_qname, "TXT", prefix="v=DMARC1; "): - records.append((dmarc_qname, "TXT", 'v=DMARC1; p=reject', "Recommended. Prevents use of this domain name for outbound mail by specifying that the SPF rule should be honoured for mail from @%s." % (qname + "." + domain))) - - # Add CardDAV/CalDAV SRV records on the non-primary hostname that points to the primary hostname - # for autoconfiguration of mail clients (so only domains hosting user accounts need it). - # The SRV record format is priority (0, whatever), weight (0, whatever), port, service provider hostname (w/ trailing dot). - if domain != env["PRIMARY_HOSTNAME"] and domain_properties[domain]["user"]: - for dav in ("card", "cal"): - qname = "_" + dav + "davs._tcp" - if not has_rec(qname, "SRV"): - records.append((qname, "SRV", "0 0 443 " + env["PRIMARY_HOSTNAME"] + ".", "Recommended. Specifies the hostname of the server that handles CardDAV/CalDAV services for email addresses on this domain.")) - - # Adds autoconfiguration A records for all domains that there are user accounts at. - # This allows the following clients to automatically configure email addresses in the respective applications. - # autodiscover.* - Z-Push ActiveSync Autodiscover - # autoconfig.* - Thunderbird Autoconfig if domain_properties[domain]["user"]: - autodiscover_records = [ - ("autodiscover", "A", env["PUBLIC_IP"], "Provides email configuration autodiscovery support for Z-Push ActiveSync Autodiscover."), - ("autodiscover", "AAAA", env["PUBLIC_IPV6"], "Provides email configuration autodiscovery support for Z-Push ActiveSync Autodiscover."), - ("autoconfig", "A", env["PUBLIC_IP"], "Provides email configuration autodiscovery support for Thunderbird Autoconfig."), - ("autoconfig", "AAAA", env["PUBLIC_IPV6"], "Provides email configuration autodiscovery support for Thunderbird Autoconfig.") - ] - for qname, rtype, value, explanation in autodiscover_records: - if value is None or value.strip() == "": continue # skip IPV6 if not set - if not has_rec(qname, rtype): - records.append((qname, rtype, value, explanation)) + # Add CardDAV/CalDAV SRV records on the non-primary hostname that points to the primary hostname + # for autoconfiguration of mail clients (so only domains hosting user accounts need it). + # The SRV record format is priority (0, whatever), weight (0, whatever), port, service provider hostname (w/ trailing dot). + if domain != env["PRIMARY_HOSTNAME"]: + for dav in ("card", "cal"): + qname = "_" + dav + "davs._tcp" + if not has_rec(qname, "SRV"): + records.append((qname, "SRV", "0 0 443 " + env["PRIMARY_HOSTNAME"] + ".", "Recommended. Specifies the hostname of the server that handles CardDAV/CalDAV services for email addresses on this domain.")) # If this is a domain name that there are email addresses configured for, i.e. "something@" # this domain name, then the domain name is a MTA-STS (https://tools.ietf.org/html/rfc8461) @@ -350,11 +325,9 @@ def build_zone(domain, domain_properties, additional_records, env, is_zone=True) # subdomain must be valid certificate for that domain. Do not set an MTA-STS policy if either # certificate in use is not valid (e.g. because it is self-signed and a valid certificate has not # yet been provisioned). Since we cannot provision a certificate without A/AAAA records, we - # always set them --- only the TXT records depend on there being valid certificates. - mta_sts_records = [ - ("mta-sts", "A", env["PUBLIC_IP"], "Optional. MTA-STS Policy Host serving /.well-known/mta-sts.txt."), - ("mta-sts", "AAAA", env.get('PUBLIC_IPV6'), "Optional. MTA-STS Policy Host serving /.well-known/mta-sts.txt."), - ] + # always set them (by including them in the www domains) --- only the TXT records depend on there + # being valid certificates. + mta_sts_records = [ ] if domain_properties[domain]["mail"] \ and domain_properties[env["PRIMARY_HOSTNAME"]]["certificate-is-valid"] \ and is_domain_cert_signed_and_valid("mta-sts." + domain, env): @@ -374,10 +347,28 @@ def build_zone(domain, domain_properties, additional_records, env, is_zone=True) if env.get("MTA_STS_TLSRPT_RUA") and not has_rec("_smtp._tls", "TXT", prefix="v=TLSRPTv1;"): mta_sts_records.append(("_smtp._tls", "TXT", "v=TLSRPTv1; rua=" + env["MTA_STS_TLSRPT_RUA"], "Optional. Enables MTA-STS reporting.")) for qname, rtype, value, explanation in mta_sts_records: - if value is None or value.strip() == "": continue # skip IPV6 if not set if not has_rec(qname, rtype): records.append((qname, rtype, value, explanation)) + # Add no-mail-here records for any qname that has an A or AAAA record + # but no MX record. This would include domain itself if domain is a + # non-mail domain and also may include qnames from custom DNS records. + # Do this once at the end of generating a zone. + if is_zone: + qnames_with_a = set(qname for (qname, rtype, value, explanation) in records if rtype in ("A", "AAAA")) + qnames_with_mx = set(qname for (qname, rtype, value, explanation) in records if rtype == "MX") + for qname in qnames_with_a - qnames_with_mx: + # Mark this domain as not sending mail with hard-fail SPF and DMARC records. + d = (qname+"." if qname else "") + domain + if not has_rec(qname, "TXT", prefix="v=spf1 "): + records.append((qname, "TXT", 'v=spf1 -all', "Recommended. Prevents use of this domain name for outbound mail by specifying that no servers are valid sources for mail from @%s. If you do send email from this domain name you should either override this record such that the SPF rule does allow the originating server, or, take the recommended approach and have the box handle mail for this domain (simply add any receiving alias at this domain name to make this machine treat the domain name as one of its mail domains)." % d)) + if not has_rec("_dmarc" + ("."+qname if qname else ""), "TXT", prefix="v=DMARC1; "): + records.append(("_dmarc" + ("."+qname if qname else ""), "TXT", 'v=DMARC1; p=reject', "Recommended. Prevents use of this domain name for outbound mail by specifying that the SPF rule should be honoured for mail from @%s." % d)) + + # And with a null MX record (https://explained-from-first-principles.com/email/#null-mx-record) + if not has_rec(qname, "MX"): + records.append((qname, "MX", '0 .', "Recommended. Prevents use of this domain name for incoming mail.")) + # Sort the records. The None records *must* go first in the nsd zone file. Otherwise it doesn't matter. records.sort(key = lambda rec : list(reversed(rec[0].split(".")) if rec[0] is not None else "")) diff --git a/management/web_update.py b/management/web_update.py index 809106e4..7230182b 100644 --- a/management/web_update.py +++ b/management/web_update.py @@ -27,7 +27,7 @@ def get_web_domains(env, include_www_redirects=True, include_auto=True, exclude_ if include_auto: # Add Autoconfiguration domains for domains that there are user accounts at: # 'autoconfig.' for Mozilla Thunderbird auto setup. - # 'autodiscover.' for Activesync autodiscovery. + # 'autodiscover.' for ActiveSync autodiscovery (Z-Push). domains |= set('autoconfig.' + maildomain for maildomain in get_mail_domains(env, users_only=True)) domains |= set('autodiscover.' + maildomain for maildomain in get_mail_domains(env, users_only=True)) From d510c8ae2a5b55ef1b22cc57c8ff8a2fe8597546 Mon Sep 17 00:00:00 2001 From: Joshua Tauberer Date: Sun, 9 May 2021 10:11:40 -0400 Subject: [PATCH 18/20] Enable and recommend port 465 for mail submission instead of port 587 (fixes #1849) Port 465 with "implicit" (i.e. always-on) TLS is a more secure approach than port 587 with explicit (i.e. optional and only on with STARTTLS). Although we reject credentials on port 587 without STARTTLS, by that point credentials have already been sent. --- CHANGELOG.md | 1 + conf/fail2ban/jails.conf | 8 +++++++ conf/ios-profile.xml | 2 +- conf/mozilla-autoconfig.xml | 4 ++-- conf/zpush/backend_imap.php | 2 +- management/status_checks.py | 1 + management/templates/mail-guide.html | 4 ++-- security.md | 4 ++-- setup/mail-postfix.sh | 33 ++++++++++++++++++---------- setup/ssl.sh | 4 ++-- tests/test_mail.py | 3 +-- 11 files changed, 42 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df69bbe4..1587097e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ In Development Mail: +* Sending mail is now possible on port 465 with the "SSL" or "TLS" option in mail clients, and this is now the recommended setting. Port 587 with STARTTLS remains available but should be avoided. * Roundcube's login cookie is updated to use a new encryption algorithm (AES-256-CBC instead of DES-EDE-CBC). DNS: diff --git a/conf/fail2ban/jails.conf b/conf/fail2ban/jails.conf index 5de4fd48..ce957f41 100644 --- a/conf/fail2ban/jails.conf +++ b/conf/fail2ban/jails.conf @@ -38,6 +38,14 @@ logpath = STORAGE_ROOT/owncloud/nextcloud.log maxretry = 20 findtime = 120 +[miab-postfix465] +enabled = true +port = 465 +filter = miab-postfix-submission +logpath = /var/log/mail.log +maxretry = 20 +findtime = 30 + [miab-postfix587] enabled = true port = 587 diff --git a/conf/ios-profile.xml b/conf/ios-profile.xml index f2011a4e..273c0bf6 100644 --- a/conf/ios-profile.xml +++ b/conf/ios-profile.xml @@ -53,7 +53,7 @@ OutgoingMailServerHostName PRIMARY_HOSTNAME OutgoingMailServerPortNumber - 587 + 465 OutgoingMailServerUseSSL OutgoingPasswordSameAsIncomingPassword diff --git a/conf/mozilla-autoconfig.xml b/conf/mozilla-autoconfig.xml index 22834622..df9cce61 100644 --- a/conf/mozilla-autoconfig.xml +++ b/conf/mozilla-autoconfig.xml @@ -16,8 +16,8 @@ PRIMARY_HOSTNAME - 587 - STARTTLS + 465 + SSL %EMAILADDRESS% password-cleartext true diff --git a/conf/zpush/backend_imap.php b/conf/zpush/backend_imap.php index a0c12335..da80c89a 100644 --- a/conf/zpush/backend_imap.php +++ b/conf/zpush/backend_imap.php @@ -49,7 +49,7 @@ define('IMAP_FROM_LDAP_FULLNAME', '#givenname #sn'); define('IMAP_SMTP_METHOD', 'sendmail'); global $imap_smtp_params; -$imap_smtp_params = array('host' => 'ssl://127.0.0.1', 'port' => 587, 'auth' => true, 'username' => 'imap_username', 'password' => 'imap_password'); +$imap_smtp_params = array('host' => 'ssl://127.0.0.1', 'port' => 465, 'auth' => true, 'username' => 'imap_username', 'password' => 'imap_password'); define('MAIL_MIMEPART_CRLF', "\r\n"); define('IMAP_MEETING_USE_CALDAV', true); diff --git a/management/status_checks.py b/management/status_checks.py index 67b26974..7e766d0f 100755 --- a/management/status_checks.py +++ b/management/status_checks.py @@ -34,6 +34,7 @@ def get_services(): { "name": "SSH Login (ssh)", "port": get_ssh_port(), "public": True, }, { "name": "Public DNS (nsd4)", "port": 53, "public": True, }, { "name": "Incoming Mail (SMTP/postfix)", "port": 25, "public": True, }, + { "name": "Outgoing Mail (SMTP 465/postfix)", "port": 465, "public": True, }, { "name": "Outgoing Mail (SMTP 587/postfix)", "port": 587, "public": True, }, #{ "name": "Postfix/master", "port": 10587, "public": True, }, { "name": "IMAPS (dovecot)", "port": 993, "public": True, }, diff --git a/management/templates/mail-guide.html b/management/templates/mail-guide.html index 0b43993b..e3db9f0c 100644 --- a/management/templates/mail-guide.html +++ b/management/templates/mail-guide.html @@ -30,8 +30,8 @@ Mail server {{hostname}} IMAP Port 993 IMAP Security SSL or TLS - SMTP Port 587 - SMTP Security STARTTLS (“always” or “required”, if prompted) + SMTP Port 465 + SMTP Security SSL or TLS Username: Your whole email address. Password: Your mail password. diff --git a/security.md b/security.md index ba3e3847..8c39437e 100644 --- a/security.md +++ b/security.md @@ -32,7 +32,7 @@ The box's administrator and its (non-administrative) mail users must sometimes c These services are protected by [TLS](https://en.wikipedia.org/wiki/Transport_Layer_Security): -* SMTP Submission (port 587). Mail users submit outbound mail through SMTP with STARTTLS on port 587. +* SMTP Submission (ports 465/587). Mail users submit outbound mail through SMTP with TLS (port 465) or STARTTLS (port 587). * IMAP/POP (ports 993, 995). Mail users check for incoming mail through IMAP or POP over TLS. * HTTPS (port 443). Webmail, the Exchange/ActiveSync protocol, the administrative control panel, and any static hosted websites are accessed over HTTPS. @@ -44,7 +44,7 @@ The services all follow these rules: Additionally: -* SMTP Submission (port 587) will not accept user credentials without STARTTLS (true also of SMTP on port 25 in case of client misconfiguration), and the submission port won't accept mail without encryption. The minimum cipher key length is 128 bits. (The box is of course configured not to be an open relay. User credentials are required to send outbound mail.) ([source](setup/mail-postfix.sh)) +* SMTP Submission on port 587 will not accept user credentials without STARTTLS (true also of SMTP on port 25 in case of client misconfiguration), and the submission port won't accept mail without encryption. The minimum cipher key length is 128 bits. (The box is of course configured not to be an open relay. User credentials are required to send outbound mail.) ([source](setup/mail-postfix.sh)) * HTTPS (port 443): The HTTPS Strict Transport Security header is set. A redirect from HTTP to HTTPS is offered. The [Qualys SSL Labs test](https://www.ssllabs.com/ssltest) should report an A+ grade. ([source 1](conf/nginx-ssl.conf), [source 2](conf/nginx.conf)) ### Password Storage diff --git a/setup/mail-postfix.sh b/setup/mail-postfix.sh index b16fd94a..dc1fff85 100755 --- a/setup/mail-postfix.sh +++ b/setup/mail-postfix.sh @@ -17,7 +17,7 @@ # LMTP. Spamassassin then passes mail over to Dovecot for # storage in the user's mailbox. # -# Postfix also listens on port 587 (SMTP+STARTLS) for +# Postfix also listens on ports 465/587 (SMTPS, SMTP+STARTLS) for # connections from users who can authenticate and then sends # their email out to the outside world. Postfix queries Dovecot # to authenticate users. @@ -71,7 +71,7 @@ tools/editconf.py /etc/postfix/main.cf \ # ### Outgoing Mail -# Enable the 'submission' port 587 smtpd server and tweak its settings. +# Enable the 'submission' ports 465 and 587 and tweak their settings. # # * Enable authentication. It's disabled globally so that it is disabled on port 25, # so we need to explicitly enable it here. @@ -80,13 +80,19 @@ tools/editconf.py /etc/postfix/main.cf \ # OpenDKIM milter only. See dkim.sh. # * Even though we dont allow auth over non-TLS connections (smtpd_tls_auth_only below, and without auth the client cant # send outbound mail), don't allow non-TLS mail submission on this port anyway to prevent accidental misconfiguration. -# Setting smtpd_tls_security_level=encrypt also triggers the use of the 'mandatory' settings below. +# Setting smtpd_tls_security_level=encrypt also triggers the use of the 'mandatory' settings below (but this is ignored with smtpd_tls_wrappermode=yes.) # * Give it a different name in syslog to distinguish it from the port 25 smtpd server. # * Add a new cleanup service specific to the submission service ('authclean') # that filters out privacy-sensitive headers on mail being sent out by # authenticated users. By default Postfix also applies this to attached # emails but we turn this off by setting nested_header_checks empty. tools/editconf.py /etc/postfix/master.cf -s -w \ + "smtps=inet n - - - - smtpd + -o smtpd_tls_wrappermode=yes + -o smtpd_sasl_auth_enable=yes + -o syslog_name=postfix/submission + -o smtpd_milters=inet:127.0.0.1:8891 + -o cleanup_service_name=authclean" \ "submission=inet n - - - - smtpd -o smtpd_sasl_auth_enable=yes -o syslog_name=postfix/submission @@ -100,14 +106,14 @@ tools/editconf.py /etc/postfix/master.cf -s -w \ # Install the `outgoing_mail_header_filters` file required by the new 'authclean' service. cp conf/postfix_outgoing_mail_header_filters /etc/postfix/outgoing_mail_header_filters -# Modify the `outgoing_mail_header_filters` file to use the local machine name and ip +# Modify the `outgoing_mail_header_filters` file to use the local machine name and ip # on the first received header line. This may help reduce the spam score of email by # removing the 127.0.0.1 reference. sed -i "s/PRIMARY_HOSTNAME/$PRIMARY_HOSTNAME/" /etc/postfix/outgoing_mail_header_filters sed -i "s/PUBLIC_IP/$PUBLIC_IP/" /etc/postfix/outgoing_mail_header_filters # Enable TLS on incoming connections. It is not required on port 25, allowing for opportunistic -# encryption. On port 587 it is mandatory (see above). Shared and non-shared settings are +# encryption. On ports 465 and 587 it is mandatory (see above). Shared and non-shared settings are # given here. Shared settings include: # * Require TLS before a user is allowed to authenticate. # * Set the path to the server TLS certificate and 2048-bit DH parameters for old DH ciphers. @@ -117,9 +123,6 @@ sed -i "s/PUBLIC_IP/$PUBLIC_IP/" /etc/postfix/outgoing_mail_header_filters # won't fall back to cleartext. So we don't disable too much. smtpd_tls_exclude_ciphers applies to # both port 25 and port 587, but because we override the cipher list for both, it probably isn't used. # Use Mozilla's "Old" recommendations at https://ssl-config.mozilla.org/#server=postfix&server-version=3.3.0&config=old&openssl-version=1.1.1 -# For port 587 (via the 'mandatory' settings): -# * Use Mozilla's "Intermediate" TLS recommendations from https://ssl-config.mozilla.org/#server=postfix&server-version=3.3.0&config=intermediate&openssl-version=1.1.1 -# using and overriding the "high" cipher list so we don't conflict with the more permissive settings for port 25. tools/editconf.py /etc/postfix/main.cf \ smtpd_tls_security_level=may\ smtpd_tls_auth_only=yes \ @@ -130,18 +133,23 @@ tools/editconf.py /etc/postfix/main.cf \ smtpd_tls_ciphers=medium \ tls_medium_cipherlist=ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA256:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA \ smtpd_tls_exclude_ciphers=aNULL,RC4 \ + tls_preempt_cipherlist=no \ + smtpd_tls_received_header=yes + +# For ports 465/587 (via the 'mandatory' settings): +# * Use Mozilla's "Intermediate" TLS recommendations from https://ssl-config.mozilla.org/#server=postfix&server-version=3.3.0&config=intermediate&openssl-version=1.1.1 +# using and overriding the "high" cipher list so we don't conflict with the more permissive settings for port 25. +tools/editconf.py /etc/postfix/main.cf \ smtpd_tls_mandatory_protocols="!SSLv2,!SSLv3,!TLSv1,!TLSv1.1" \ smtpd_tls_mandatory_ciphers=high \ tls_high_cipherlist=ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384 \ - smtpd_tls_mandatory_exclude_ciphers=aNULL,DES,3DES,MD5,DES+MD5,RC4 \ - tls_preempt_cipherlist=no \ - smtpd_tls_received_header=yes + smtpd_tls_mandatory_exclude_ciphers=aNULL,DES,3DES,MD5,DES+MD5,RC4 # Prevent non-authenticated users from sending mail that requires being # relayed elsewhere. We don't want to be an "open relay". On outbound # mail, require one of: # -# * `permit_sasl_authenticated`: Authenticated users (i.e. on port 587). +# * `permit_sasl_authenticated`: Authenticated users (i.e. on port 465/587). # * `permit_mynetworks`: Mail that originates locally. # * `reject_unauth_destination`: No one else. (Permits mail whose destination is local and rejects other mail.) tools/editconf.py /etc/postfix/main.cf \ @@ -263,6 +271,7 @@ tools/editconf.py /etc/postfix/main.cf \ # Allow the two SMTP ports in the firewall. ufw_allow smtp +ufw_allow smtps ufw_allow submission # Restart services diff --git a/setup/ssl.sh b/setup/ssl.sh index 61b0b9e5..9bd5d539 100755 --- a/setup/ssl.sh +++ b/setup/ssl.sh @@ -10,7 +10,7 @@ # # * DNSSEC DANE TLSA records # * IMAP -# * SMTP (opportunistic TLS for port 25 and submission on port 587) +# * SMTP (opportunistic TLS for port 25 and submission on ports 465/587) # * HTTPS # # The certificate is created with its CN set to the PRIMARY_HOSTNAME. It is @@ -19,7 +19,7 @@ # # The Diffie-Hellman cipher bits are used for SMTP and HTTPS, when a # Diffie-Hellman cipher is selected during TLS negotiation. Diffie-Hellman -# provides Perfect Forward Secrecy. +# provides Perfect Forward Secrecy. source setup/functions.sh # load our functions source /etc/mailinabox.conf # load global vars diff --git a/tests/test_mail.py b/tests/test_mail.py index 686d07a5..8c8838a5 100755 --- a/tests/test_mail.py +++ b/tests/test_mail.py @@ -41,9 +41,8 @@ This is a test message. It should be automatically deleted by the test script."" ) # Connect to the server on the SMTP submission TLS port. -server = smtplib.SMTP(host, 587) +server = smtplib.SMTP_SSL(host) #server.set_debuglevel(1) -server.starttls() # Verify that the EHLO name matches the server's reverse DNS. ipaddr = socket.gethostbyname(host) # IPv4 only! From 35fa3fe891574ce43705cec39c5b5e48cd4172ea Mon Sep 17 00:00:00 2001 From: Joshua Tauberer Date: Sat, 15 May 2021 16:50:19 -0400 Subject: [PATCH 19/20] Changelog entries --- CHANGELOG.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1587097e..620532a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,8 @@ In Development Mail: -* Sending mail is now possible on port 465 with the "SSL" or "TLS" option in mail clients, and this is now the recommended setting. Port 587 with STARTTLS remains available but should be avoided. +* Forwarded mail using mail filter rules (in Roundcube; "sieve" rules) stopped re-writing the envelope address at some point, causing forwarded mail to often be marked as spam by the final recipient. These forwards will now re-write the envelope as the Mail-in-a-Box user receiving the mail to comply with SPF/DMARC rules. +* Sending mail is now possible on port 465 with the "SSL" or "TLS" option in mail clients, and this is now the recommended setting. Port 587 with STARTTLS remains available but should be avoided when configuring new mail clients. * Roundcube's login cookie is updated to use a new encryption algorithm (AES-256-CBC instead of DES-EDE-CBC). DNS: @@ -14,6 +15,19 @@ DNS: * The ECDSAP256SHA256 DNSSEC algorithm is now available. If a DS record is set for any of your domain names that have DNS hosted on your box, you will be prompted by status checks to update the DS record at your convenience. * Null MX records are added for domains that do not serve mail. +Contacts/calendar: + +* Updated Nextcloud to 20.0.8, contacts to 3.5.1, calendar to 2.2.0 (#1960). + +Control panel: + +* Fixed a crash in the status checks. +* Small wording improvements. + +Setup: + +* Minor improvements to the setup scripts. + v0.53a (May 8, 2021) -------------------- From 4cb46ea4658b91240c5676c52746e48aaaba7b3f Mon Sep 17 00:00:00 2001 From: Joshua Tauberer Date: Sun, 20 Jun 2021 15:50:04 -0400 Subject: [PATCH 20/20] v0.54 --- CHANGELOG.md | 4 ++-- README.md | 2 +- setup/bootstrap.sh | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 620532a6..9338b052 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,8 @@ CHANGELOG ========= -In Development --------------- +v0.54 (June 20, 2021) +--------------------- Mail: diff --git a/README.md b/README.md index e08312fa..92fab007 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ Clone this repository and checkout the tag corresponding to the most recent rele $ git clone https://github.com/mail-in-a-box/mailinabox $ cd mailinabox - $ git checkout v0.53a + $ git checkout v0.54 Begin the installation. diff --git a/setup/bootstrap.sh b/setup/bootstrap.sh index d2117df7..90521051 100644 --- a/setup/bootstrap.sh +++ b/setup/bootstrap.sh @@ -20,7 +20,7 @@ if [ -z "$TAG" ]; then # want to display in status checks. if [ "$(lsb_release -d | sed 's/.*:\s*//' | sed 's/18\.04\.[0-9]/18.04/' )" == "Ubuntu 18.04 LTS" ]; then # This machine is running Ubuntu 18.04. - TAG=v0.53a + TAG=v0.54 elif [ "$(lsb_release -d | sed 's/.*:\s*//' | sed 's/14\.04\.[0-9]/14.04/' )" == "Ubuntu 14.04 LTS" ]; then # This machine is running Ubuntu 14.04.