security: harden server with firewall, fail2ban, and SSH protections #30

Closed
Hermes wants to merge 9 commits from feature/server-hardening into master
Collaborator

Summary

Adds comprehensive server hardening for internet-facing NixOS host.

Changes

Firewall (default deny)

  • Only essential ports exposed: SSH (2424), Gitea (2222), HTTP/HTTPS (80/443)
  • Rate limiting: SSH (4 conn/min), HTTP/HTTPS (25/min)
  • Invalid packet dropping + logging

Fail2ban

  • SSH jail: 3 strikes → 1 hour ban
  • HTTP auth jail: 5 failures → 1 hour ban
  • Bot search jail: 2 hits → 2 hour ban
  • Recidive jail: repeat offenders → 1 week ban
  • Custom Traefik filters for HTTP jails

SSH Hardening

  • Root login disabled
  • Max 3 auth tries, 5 sessions
  • 30s login grace time
  • Verbose logging
  • X11/TCP/Agent forwarding disabled

Kernel Hardening

  • SYN flood protection
  • IP spoofing protection
  • Source routing disabled
  • ICMP redirects disabled

Dependencies

Merge compose PR first, then this one.

Deployment

# 1. Deploy compose changes first
cd ~/infra/assets/compose/network
docker compose up -d traefik

# 2. Deploy NixOS config
nh os switch .#lazyworkhorse

# 3. Verify hardening
/opt/data/scripts/security-audit.sh

Verification

# Check firewall
sudo iptables -L -n -v

# Check fail2ban
sudo fail2ban-client status
sudo fail2ban-client status sshd
sudo fail2ban-client status http-auth
sudo fail2ban-client status http-botsearch

# Check SSH config
sudo sshd -T | grep -E "^(permitrootlogin|maxauthtries|loglevel)"
  • Skill: nixos-server-hardening
  • Based on PR #27 reference implementation
## Summary Adds comprehensive server hardening for internet-facing NixOS host. ## Changes ### Firewall (default deny) - Only essential ports exposed: SSH (2424), Gitea (2222), HTTP/HTTPS (80/443) - Rate limiting: SSH (4 conn/min), HTTP/HTTPS (25/min) - Invalid packet dropping + logging ### Fail2ban - SSH jail: 3 strikes → 1 hour ban - HTTP auth jail: 5 failures → 1 hour ban - Bot search jail: 2 hits → 2 hour ban - Recidive jail: repeat offenders → 1 week ban - Custom Traefik filters for HTTP jails ### SSH Hardening - Root login disabled - Max 3 auth tries, 5 sessions - 30s login grace time - Verbose logging - X11/TCP/Agent forwarding disabled ### Kernel Hardening - SYN flood protection - IP spoofing protection - Source routing disabled - ICMP redirects disabled ## Dependencies - **Requires:** [compose PR #15](https://code.lazyworkhorse.net/gortium/compose/pulls/15) (Traefik access logs) Merge compose PR first, then this one. ## Deployment ```bash # 1. Deploy compose changes first cd ~/infra/assets/compose/network docker compose up -d traefik # 2. Deploy NixOS config nh os switch .#lazyworkhorse # 3. Verify hardening /opt/data/scripts/security-audit.sh ``` ## Verification ```bash # Check firewall sudo iptables -L -n -v # Check fail2ban sudo fail2ban-client status sudo fail2ban-client status sshd sudo fail2ban-client status http-auth sudo fail2ban-client status http-botsearch # Check SSH config sudo sshd -T | grep -E "^(permitrootlogin|maxauthtries|loglevel)" ``` ## Related - Skill: `nixos-server-hardening` - Based on PR #27 reference implementation
Hermes added 6 commits 2026-05-01 03:07:46 +00:00
- Firewall (default deny):
  - Allow only essential ports: SSH(2424), Gitea(2222), HTTP(80), HTTPS(443)
  - Rate limit SSH (max 4 new connections/60s)
  - Rate limit HTTP/HTTPS (25/minute)
  - Drop invalid packets, log dropped packets

- Fail2ban (auto-ban attackers):
  - SSH jail: 3 strikes = 1 hour ban
  - HTTP auth failures: 5 strikes = 1 hour ban
  - HTTP scanning: 2 strikes = 2 hour ban
  - Recidive jail: repeat offenders = 1 week ban

- SSH hardening:
  - No root login
  - Max 3 auth tries, 5 sessions
  - 30s login grace time
  - No X11/TCP/agent forwarding
  - Verbose logging

- Kernel network hardening:
  - SYN flood protection (syncookies)
  - IP spoofing protection (rp_filter)
  - Disable source routing, redirects
  - Log martian packets
  - Connection tuning for high load

- Audit logging enabled

Ports commented for review (likely internal-only):
- 8000 (Portainer), 4242 (Coms), 5000/8087/8089 (TAK)
- Deployment: nh os switch, nixos-rebuild switch (flake path locked)
- Firewall checks: iptables -L, iptables -S
- Fail2ban: status, banned IPs
- Logs: journalctl for kernel and fail2ban
- SSH config: sshd -T for verification
- Docker: ps, inspect (service health)
- Network: ss -tlnp, /proc/net/tcp

All commands are whitelisted with NOPASSWD.
No shell access, no ALL command - principle of least privilege.
ai-worker only needs security audit commands, not deployment access.

Removed:
- nh os switch
- nixos-rebuild switch

Kept:
- Firewall checks (iptables)
- Fail2ban status
- Log inspection (journalctl)
- SSH config (sshd -T)
- Docker service checks
- Network diagnostics
Hermes added 3 commits 2026-05-01 03:08:38 +00:00
- Updated roadmap phase status (Phase 4 complete)
- Added merge priority table with PR #28 (security) at top
- Documented that security must merge before new services exposed
- Added deployment command reference
Hermes closed this pull request 2026-05-01 03:34:18 +00:00

Pull request closed

Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: gortium/infra#30
No description provided.