Skip to content

Security hardening

Exposure summary

Port Exposure Notes
/tcp Public, allowed-region IPs + Tailscale + home IP only fail2ban, root key-only, login alerts
80, 443/tcp Public worldwide nginx sites; Let's Encrypt validation needs worldwide reach
8090/tcp 127.0.0.1 (app) + tailscale0 only (tailscale serve) Prompts library UI/API; not in ufw, not in nginx
9100, 9113/tcp tailscale0 only node/nginx exporters for linux-01
11434/tcp 127.0.0.1 only Ollama (no auth by design)
others (Grafana 3000, Nautobot 8001, Postgres, Redis) 127.0.0.1 only behind nginx where published

ufw (unchanged by today's work): default deny incoming, allow outgoing; <SSH_PORT>/tcp ALLOW Anywhere; 80,443/tcp ALLOW Anywhere; 9100,9113/tcp on tailscale0 ALLOW; same for IPv6.

SSH

  • PermitRootLogin prohibit-password: root only with a key.
  • Root is key-only (PermitRootLogin prohibit-password). Confirm the current PasswordAuthentication / KbdInteractiveAuthentication values in the sshd drop-in rather than assuming they are off. Recommendation: switch to key-only when convenient.
  • Admin access currently arrives over the public IP from <HOME_IP>, not over Tailscale. Restricting to tailscale0 would need the SSH clients pointed at <VPS_TAILSCALE_IP> first.

SSH login alerts (ntfy)

  • Mechanism: a PAM session hook (session optional pam_exec.so quiet /usr/local/sbin/ssh-login-ntfy.sh in /etc/pam.d/sshd).
  • On every SSH session open, it posts to ntfy: user, source IP, auth method (publickey/password, read from the sshd journal line), TTY, time in ET. Title: "SSH login on goc-vps (user from IP)", priority high.
  • Uses the same ntfy.sh topic as the linux-01 Alertmanager bridge, stored in /etc/goc-alerting/ntfy.env (0600). The topic name is effectively a password; it is not in these docs.
  • Free alternative to SMS: true text messages need a paid or carrier gateway; ntfy push to the phone app is the free equivalent.
  • Every session alerts, including automation/agent sessions.
  • Test, mute and removal: see operations.md#ssh-login-alerts-ntfy.
  • Tripwire-style file integrity (AIDE) was considered and skipped: daily unattended upgrades would cause daily alerts.

fail2ban

Jail Source Trigger Ban
sshd systemd journal (sshd), mode = aggressive 5 failures in 10 min 1 h, increasing on repeat (bantime.increment), max 1 week
recidive /var/log/fail2ban.log 5 bans in 1 day 1 week
  • Ban action: iptables-ipset-proto6-allports (an ipset per jail + a REJECT rule at the top of INPUT). Bans block all ports for that IP and do not show in ufw status.
  • ignoreip (never banned): 127.0.0.1/8, ::1, 100.64.0.0/10 and fd7a:115c:a1e0::/48 (Tailscale ranges), <HOME_IP>. linux-01 egresses from the same home IP.
  • No nginx jails: a web ban would block all ports for that IP, which is not low-risk for public sites.
  • Unban: fail2ban-client set sshd unbanip <IP>. More in the runbook.
  • Caveat: <HOME_IP> is a dynamic residential IP. If it changes, 5 bad passwords from home would ban it for an hour.

SSH geo-block

  • Scope: tcp/ only. Web ports stay worldwide.
  • Rule (in /etc/ufw/before.rules and before6.rules, after the "established" accept so existing sessions survive): -A ufw-before-input -p tcp --dport <SSH_PORT> ! -i tailscale0 -m set ! --match-set geo-ssh-allow4 src -j DROP (and the ufw6- / geo-ssh-allow6 twin).
  • Allowed: anything on tailscale0; ipset geo-ssh-allow4 (allowed-region IPv4 + 127.0.0.0/8, 100.64.0.0/10, <HOME_IP>) and geo-ssh-allow6 (allowed-region IPv6 + ::1, fd7a:115c:a1e0::/48). Loopback is accepted earlier by ufw.
  • Source: the configured country zone feeds (IPv4 and IPv6). At install the allow-sets contained tens of thousands of prefixes (counts change as the zone feed updates).
  • Boot: geoip-ssh-sets.service (Before=ufw.service) loads the sets from the cache in /var/lib/geoip-ssh/ with no network needed, so ufw never references a missing set.
  • Refresh: geoip-ssh-update.timer, weekly, Sundays 04:30 UTC (Saturday 11:30 PM ET) + up to 30 min, Persistent=true. Downloads are validated (minimum 10,000 v4 / 3,000 v6 lines, strict CIDR format); new data is loaded into a temp set and swapped in atomically. A failed download keeps the cached copy, so the set is never emptied. Even an empty set would still admit Tailscale, loopback and the home IP.
  • Revert: /root/geo-ssh-revert.sh. Add an IP: see the runbook.
  • Limits: geo databases are approximate (some VPN/cloud ranges are mislabelled). Abroad, use Tailscale or the Hostinger web console.
  • Applied with a 6-minute auto-revert armed, tested with fresh public and Tailscale connections and a simulated boot (systemctl restart geoip-ssh-sets ufw), then the revert was cancelled.

Accounts and keys

  • Root authorized_keys holds the owner's admin keys (not listed here).
  • Removed: jconover (never logged in, had passwordless sudo, held one external user's key and a self-generated keypair). Archive kept root-only on the VPS.

Open items / recommendations

  1. Turn SSH password login off (key-only) once convenient.
  2. Optionally restrict to tailscale0 after moving SSH clients to Tailscale; install Tailscale on the admin desktop as a second path in.
  3. Review Tailscale ACLs and enable MFA on the Tailscale identity provider (guide Step 11).
  4. Enable Hostinger VPS snapshots/backups (guide Step 9).
  5. Confirm the phone is subscribed to the ntfy topic.

Prompts library (prompts.chat)

  • Tailnet-only exposure (never public): app.py listens exclusively on 127.0.0.1:8090, and tailscale serve proxies http://goc-vps:8090 / http://goc-vps.<TAILNET>.ts.net:8090 on tailscale0 (<VPS_TAILSCALE_IP>:8090 and the Tailscale IPv6 address) only. ufw does not open port 8090, and public nginx (80/443) was not modified. Verified from outside (linux-01 over public hostname): port 8090 times out, while tailnet requests with Host: goc-vps:8090 return 200 OK.
  • Service isolation: Runs under dedicated unprivileged user/group promptschat with IPAddressDeny=any and IPAddressAllow=localhost (the app cannot make outbound internet connections; weekly prompts.csv fetches run in a separate oneshot unit prompts-chat-update.service). Also enforces NoNewPrivileges=yes, CapabilityBoundingSet=, ProtectSystem=strict, ProtectHome=yes, PrivateTmp=yes, PrivateDevices=yes, MemoryDenyWriteExecute=yes, RestrictNamespaces=yes, SystemCallFilter=@system-service, and UMask=0077.
  • HTTP headers: Responses set X-Content-Type-Options: nosniff, X-Frame-Options: DENY, Referrer-Policy: no-referrer, Cache-Control: no-store, and a strict Content-Security-Policy (default-src 'self'; frame-ancestors 'none').
  • Auth model: Tailnet membership + Tailscale ACLs gate access (no separate app login needed because it is unreachable outside the tailnet). Request body size is capped at 512 KiB (MAX_BODY_BYTES) and system prompts at 16,000 chars.