cam fix bk to use recursive resolver
authorIan Kelling <ian@iankelling.org>
Tue, 17 Nov 2020 22:14:51 +0000 (17:14 -0500)
committerIan Kelling <ian@iankelling.org>
Wed, 18 Nov 2020 00:40:10 +0000 (19:40 -0500)
a/site.yml
distro-begin
distro-end
filesystem/etc/letsencrypt/renewal-hooks/deploy/certbot-renew-hook
machine_specific/vps/filesystem/etc/bind/named.conf.options [new file with mode: 0644]
mail-setup
mailtest-check

index e1a2777ecbd8c03cfe650bb140f0967b7833970d..e9e48edadccccb190966910703e8a880737bb247 100644 (file)
@@ -14,9 +14,9 @@
             - targets:
                 - "{{ ansible_fqdn }}:9090"
         - job_name: "node"
-          basic_auth:
-            username: prom
-            password_file: /etc/prometheus-pass
+          basic_auth:
+            username: prom
+            password_file: /etc/prometheus-pass
           #scheme: "https"
           file_sd_configs:
             - files:
 
 
     - role: node-exporter
+      tags: a
+      # node_exporter_tls_server_config:
+      #   cert_file: /etc/node_exporter/fullchain.pem
+      #   key_file: /etc/node_exporter/privkey.pem
       node_exporter_web_listen_address: "127.0.1.1:9100"
+      node_exporter_basic_auth_users:
+        prom: incarnadine.bloodied.maker
 
     - role: alertmanager
       alertmanager_smtp:
index df11e9383e69ea6597a7286e640aa6e9c372dbb3..47103e7f3ca0f254d11a2ab2db356e2c970d8159 100755 (executable)
@@ -293,6 +293,13 @@ if [[ ! -L /etc/nsswitch.conf ]]; then
   sudo ln -sf /etc/nsswitch/nsswitch.conf /etc
 fi
 
+f=/etc/nn-resolv/nsswitch.conf
+if [[ ! -e $f ]]; then
+  sudo mkdir -p ${f%/*}
+  sudo cp /etc/nsswitch.conf $f
+  sudo sed -i --follow-symlinks 's/^ *hosts:.*/hosts: files dns myhostname/' $f
+fi
+
 f=/etc/apparmor.d/abstractions/nameservice
 if ! grep -q /etc/nsswitch/nsswitch.conf $f; then
   sudo sed -i '/\/etc\/nsswitch.conf/a /etc/nsswitch/nsswitch.conf r,' $f
@@ -307,7 +314,15 @@ pi libnss-resolve
 # seems more important than some potential use case.
 # Interestingly, t9/t10 man page says use files before resolve, debian 10 says the opposite.
 # removing files makes hostname -f not actually give the fully qualified domain name.
-sudo sed -i --follow-symlinks 's/^ *hosts:.*/hosts: files resolve [!UNAVAIL=return] mdns4_minimal [NOTFOUND=return] myhostname/' /etc/nsswitch.conf
+case $HOSTNAME in
+  bk)
+    sudo sed -i --follow-symlinks 's/^ *hosts:.*/hosts: files dns myhostname/' /etc/nsswitch.conf
+    ;;
+  *)
+    sudo sed -i --follow-symlinks 's/^ *hosts:.*/hosts: files resolve [!UNAVAIL=return] mdns4_minimal [NOTFOUND=return] myhostname/' /etc/nsswitch.conf
+    ;;
+esac
+
 if dpkg -s -- nscd &>/dev/null; then
   sudo apt-get -y remove --purge --auto-remove nscd
   sudo systemctl stop nscd ||: # fails if already stopped
index 390bf55d23b8dcf46a13a6f657822e2a715dff77..0e34b6ed8e2126cf03a205ea20b3875e1965f640 100755 (executable)
@@ -1188,14 +1188,6 @@ EOF
 ####### end transmission
 
 
-f=/etc/nn-resolv/nsswitch.conf
-if [[ ! -e $f ]]; then
-  s mkdir -p ${f%/*}
-  s cp /etc/nsswitch.conf $f
-  s sed -i --follow-symlinks 's/^ *hosts:.*/hosts: files dns myhostname/' $f
-  s chattr +i $f
-fi
-
 
 case $HOSTNAME in
   kd|rp)
index f10f8187a8ba47960a0be8eb22ca0aabc421e73c..0ee609d56582e6593fa16e8e54e6806e204c3ae1 100755 (executable)
@@ -19,6 +19,10 @@ trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
 dir=$RENEWED_LINEAGE # long caps vars just bother me
 
 case $dir in
+  /etc/letsencrypt/live/je.b8.nz)
+    install -m 644 $dir/fullchain.pem /etc/node_exporter/fullchain.pem
+    install -m 640 -g node-exp $dir/privkey.pem /etc/node_exporter/privkey.pem
+    ;;
   /etc/letsencrypt/live/iankelling.org)
     cat $dir/{privkey,cert,chain}.pem > /var/lib/znc/znc.pem
     ;;
diff --git a/machine_specific/vps/filesystem/etc/bind/named.conf.options b/machine_specific/vps/filesystem/etc/bind/named.conf.options
new file mode 100644 (file)
index 0000000..157e295
--- /dev/null
@@ -0,0 +1,38 @@
+// this is the default for t10, plus my commented additions
+options {
+        directory "/var/cache/bind";
+
+        // If there is a firewall between you and nameservers you want
+        // to talk to, you may need to fix the firewall to allow multiple
+        // ports to talk.  See http://www.kb.cert.org/vuls/id/800113
+
+        // If your ISP provided one or more IP addresses for stable
+        // nameservers, you probably want to use them as forwarders.
+        // Uncomment the following block, and insert the addresses replacing
+        // the all-0's placeholder.
+
+        // forwarders {
+        //      0.0.0.0;
+        // };
+
+        //========================================================================
+        // If BIND logs error messages about the root key being expired,
+        // you will need to update your keys.  See https://www.isc.org/bind-keys
+        //========================================================================
+        dnssec-validation auto;
+
+        listen-on-v6 { any; };
+
+// iank, allow queries from network namespace
+// even if the interface doesnt exist when bind starts.
+allow-recursion {
+ 10.173.8.0/24;
+ localhost;
+};
+allow-query-cache {
+ 10.173.8.0/24;
+ localhost;
+};
+
+// end options
+};
index ea7ee4683ea2ba61ec1677ffe6c2f2f7759781ab..9efd5696720f3ef0bd2a8c8e6fb21105d6a58048 100755 (executable)
@@ -3,6 +3,8 @@
 # Copyright (C) 2019 Ian Kelling
 # SPDX-License-Identifier: AGPL-3.0-or-later
 
+# todo: on bk, dont send email if mailvpn is not up
+
 # todo: disable postgrey
 
 # todo: in testforward-check, we should also look
@@ -418,8 +420,6 @@ EOF
 
 # * mail vpn config
 
-# todo: figure out a reverse dns lookup for 10.173.8.1 in the nn.
-# perhaps adding files in nsswitch should fix it?
 
 i /etc/systemd/system/mailnn.service <<'EOF'
 [Unit]
@@ -494,11 +494,16 @@ EOF
 # use our own ip against dnsbl rate limits.
 #
 # If we ever notice this change, chattr +i on it
+# trust-ad is used in t10+, glibc 2.31
 i /etc/nn-resolv/stub-resolv.conf <<'EOF'
 nameserver 127.0.0.1
-options edns0
+options edns0 trust-ad
 EOF
 
+i /etc/bk-resolv/stub-resolv.conf <<'EOF'
+nameserver 10.173.8.1
+options edns0 trust-ad
+EOF
 
 # this is just a bug fix for trisquel.
 f=/etc/apparmor.d/usr.sbin.unbound
@@ -512,32 +517,37 @@ if ! grep -qFx "$line" $f; then
   m ser reload apparmor
 fi
 
-nn_progs=(exim4 unbound)
+nn_progs=(exim4)
 if mailhost; then
   # Note dovecots lmtp doesnt need to be in the same nn to accept delivery.
   # Its in the nn so remote clients can connect to it.
-  nn_progs+=(spamassassin dovecot)
+  nn_progs+=(spamassassin dovecot unbound)
 fi
 
 case $HOSTNAME in
+  $MAIL_HOST)
+    r=/etc/nn-resolv:/run/systemd/resolve
+    ;;&
+  bk)
+    r=/etc/bk-resolv:/etc/nn-resolv
+    ;;&
   $MAIL_HOST|bk)
     for unit in ${nn_progs[@]}; do
-      i /etc/systemd/system/$unit.service.d/nn.conf <<'EOF'
+      i /etc/systemd/system/$unit.service.d/nn.conf <<EOF
 [Unit]
 After=network.target
 Requires=mailvpn.service
 After=mailvpn.service
 JoinsNamespaceOf=mailnn.service
-
-# needed to continually restart
 StartLimitIntervalSec=0
 
 [Service]
 PrivateNetwork=true
-BindPaths=/etc/nn-resolv:/run/systemd/resolve:norbind /etc/nn-resolv:/etc/nsswitch:norbind
+# note the nsswitch bind is actually not needed for bk, but
+# its the same file so it does no harm.
+BindPaths=${r}:norbind /etc/nn-resolv:/etc/nsswitch:norbind
 
 Restart=always
-# time to sleep before restarting a service
 RestartSec=1
 EOF
     done
@@ -584,8 +594,8 @@ EOF
 rm -fv /etc/systemd/system/spamddnsfix.{timer,service}
 
 i /etc/default/spamassassin <<'EOF'
-# defaults
-OPTIONS="--create-prefs --max-children 5 --helper-home-dir"
+# defaults plus debugging flags for an issue im having
+OPTIONS="--create-prefs --max-children 5 --helper-home-dir -D dkim,dns"
 PIDFILE="/var/run/spamd.pid"
 # my additions
 NICE="--nicelevel 15"
@@ -1096,7 +1106,7 @@ EOF
 
     ;;&
 
-# **  $MAIL_HOST)
+  # **  $MAIL_HOST)
   $MAIL_HOST)
     # If we changed 90-sieve.conf and removed the active part of the
     # sieve option, we wouldn\'t need this, but I\'d rather not modify a
@@ -1148,7 +1158,7 @@ protocol lmtp {
 }
 EOF
     ;;&
-# **  bk|je)
+  # **  bk|je)
   bk|je)
     chown -R mail.mail /m/md
 
@@ -1287,7 +1297,7 @@ EOF
     # this should be at the end since it requires a valid dovecot config
     m sievec /etc/dovecot/sieve-spam.sieve
     ;;&
-# **  bk)
+  # **  bk)
   bk)
     # roundcube uses this
     mkdir -p /m/sieve
@@ -1977,6 +1987,7 @@ EOF
   # ** bk
   ## we use this host to monitor MAIL_HOST and host a mail server for someone
   bk)
+
     echo amnimal.ninja > /etc/mailname
 
     /a/exe/cedit nn /etc/hosts <<'EOF' || [[ $? == 1 ]]
@@ -2175,22 +2186,34 @@ m /a/bin/ds/mail-cert-cron -1
 sre mailcert.timer
 
 case $HOSTNAME in
+  bk)
+    soff systemd-resolved
+    ln -sf nn-resolv/stub-resolv.conf /etc/resolv.conf
+    ;;&
   $MAIL_HOST|bk)
     sstart mailnn
+    # If these have changes, id rather manually restart it, id rather
+    # not restart and cause temporary errors
+    if $reload; then
+      sre mailvpn
+    else
+      sstart mailvpn
+    fi
+    ;;&
+  $MAIL_HOST)
+    if $reload; then
+      sre unbound
+    else
+      sstart unbound
+    fi
+    ;;&
+  $MAIL_HOST|bk)
     if ! systemctl is-active clamav-daemon >/dev/null; then
       sstart clamav-daemon
       # checking a log, clamav took 27 seconds to start.
       # we get paniclog entries if its not available
       m sleep 30
     fi
-
-    if $reload; then
-      sre mailvpn unbound
-    else
-      # If these have changes, id rather manually restart it, id rather
-      # not restart and lose connectivity
-      sstart mailvpn unbound
-    fi
     ;;&
   $MAIL_HOST|bk|je)
     # start spamassassin/dovecot before exim.
index 38cfc91f41a12519c6b08da194c529626a1ca3d5..1adec42d2953769a3474e43c103f158d8eb443cc 100755 (executable)
@@ -118,7 +118,7 @@ for folder in ${folders[@]}; do
               printf "missing %s" "${missing[*]}"
             fi
             echo
-            spamassassin -D <"$latest"
+            cat $folder/$latest
           fi
         else
           echo $HOSTNAME mailtest spamd pid not found