threat-defense-pipeline
Layered defense system: fail2ban jails + nginx IP blocking + daily auto-deploy pipeline. How to add blocked IPs, check jails, and deploy.
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 4
- Forks
- 1
01 前言 Front Matter
- name
- threat-defense-pipeline
- author
- Steadfaste Fleet (steadfaste-fleet)
- trigger
- when adding blocked IPs, checking threat activity, or troubleshooting blocked connections
- version
- 1.0.0
- platforms
- [ "linux", "macos" ]
- description
- Layered defense system: fail2ban jails + nginx IP blocking + daily auto-deploy pipeline. How to add blocked IPs, check jails, and deploy.
03 SKILL.md 正文
Threat Defense Pipeline
Overview
Steadfaste Fleet runs a three-layer defense against port scanning and brute force:
Layer 1: fail2ban (sshd + nginx-badbots jails) → auto-bans at OS/nginx level
Layer 2: nginx-security-scanner (fail2ban ban collector) → adds CONFIRMED abusers only
Layer 3: threat-pipeline cron (daily 5AM) → deploys + commits blocked IPs
How to Add a Blocked IP
The single source of truth is ops/install/deploy/nginx/blocked_ips.add in the steadfaste-fleet repo. One IP per line.
Quick add (for agents with repo access):
cd ~/steadfaste-fleet
echo "1.2.3.4" >> ops/install/deploy/nginx/blocked_ips.add
Commit and deploy immediately:
cd ~/steadfaste-fleet
git add ops/install/deploy/nginx/blocked_ips.add
# SKIP_SCORE=1 has been REMOVED. Use _create_gov_lock instead
# (see nginx-threat-pipeline.sh for the temp lock pattern)
git commit -m "auto: block <reason> [pipeline]"
# No SKIP_PRE_PUSH needed — the pipeline scripts create a temp
# governance lock before pushing (see nginx-threat-pipeline.sh)
git push origin main
Then deploy live:
# Deploy blocked IPs (minimal-root)
bash ~/.hermes/scripts/deploy-blocked-ips.sh
OR let the daily pipeline handle it:
The pipeline runs at 05:00 KST daily. It automatically:
- Collects fail2ban-confirmed bans (sole source since 2026-08-08 — the old ≥10 req/60min volume threshold was removed because legit dashboard users trip it: one SPA refresh = 15-30 parallel requests)
- Adds new IPs to
blocked_ips.add(skipping allow-listed IPs) - Commits and pushes to GitHub
- Deploys to nginx (reloads config)
- Reloads fail2ban nginx-badbots jail
If the pipeline finds no new IPs, it stays silent (watchdog pattern).
⚠ Private IP Filtering (RFC 1918)
All three IP collection paths in the pipeline reject private/reserved IPs:
| Path | File | Filter |
|---|---|---|
| nginx log scanner | ops/scripts/manage/nginx-security-scanner.sh |
^127.|10.|172.(16-31).|192.168.|0.|169.254.|224.|240. |
| fail2ban extraction (scanner) | ops/scripts/manage/nginx-security-scanner.sh |
Same regex — added 2026-07-07 |
| fail2ban extraction (pipeline) | ops/scripts/manage/nginx-threat-pipeline.sh |
grep -vE on private ranges — added 2026-07-07 |
| agent-submitted IPs | ops/scripts/manage/nginx-threat-pipeline.sh step 0 |
Same grep -vE — added 2026-07-07 |
| Config generator | ops/install/deploy/nginx/fix-blocked-ips.py |
PRIVATE_RANGES regex in is_valid_public_ip() |
Why this matters: fail2ban can ban a LAN IP (your gateway/router) when attackers hit your server through its NAT. Without filtering, the pipeline blindly adds gateway IPs to the blocklist. These filters prevent that.
If you ever need to add a private IP to the blocklist (unusual — only if nginx is behind an internal reverse proxy), add it to /etc/nginx/allow-ips-manual.conf instead to ensure it's never blocked.
fail2ban Jails
| Jail | Target | Ban Action |
|---|---|---|
sshd |
SSH brute force | iptables ban |
nginx-badbots |
Bad bot HTTP traffic | iptables ban |
Check jail status:
sudo fail2ban-client status # list all jails
sudo fail2ban-client status sshd # sshd ban list
Pipeline Self-Healing
The threat-pipeline script (ops/scripts/manage/nginx-threat-pipeline.sh) uses deploy-blocked-ips.sh for minimal-root deploy:
- Generates
blocked_ips.conffromblocked_ips.addusingfix-blocked-ips.py(no root) - Deploys with a single tight
sudo cprule (one specific path only) - Validates with
sudo nginx -t, reloads withsudo nginx -s reload - Git commits use a temp governance lock (see nginx-threat-pipeline.sh
_create_gov_lockpattern) — no bypass flags needed - Git pushes (SKIP_PRE_PUSH=1 has been removed — pre-push hook is mandatory)
Blocklist Classification & Cleanup (2026-08-08)
Only true abusers belong in blocked_ips.add (Luke directive). The list
was polluted with legit users by the old volume threshold — see runbook
docs/runbooks/blocklist-cleanup-ddos-relax.md for the full story.
Allow-list (manual, agent-tamper-proof): /etc/nginx/allow-ips-manual.conf
is the ONLY surface that protects a legit IP from the blocklist. Agents may
READ it (the scanner skips allow-listed IPs) but never EDIT it — that's a
human action. Templates are manually installed for the same reason.
Classifier tool: classify-blocked-ips.sh (deployed by fleet-update)
splits the list into STRONG (fail2ban-banned, keep) vs WEAK (volume-only,
review) vs stale vs allow-listed. Run it on the host with the ban evidence
(Joseph is primary discovery host):
bash ~/.steadfaste-fleet/scripts/classify-blocked-ips.sh
Review-only — never edits or deploys. The safety net: fail2ban stays armed, so any IP removed that is genuinely attacking gets re-banned automatically.
Manual Deploy (for agents with sudo access)
# Deploy blocked IPs (minimal-root — only needs sudo cp)
bash ~/.hermes/scripts/deploy-blocked-ips.sh
# Or from the repo directly:
bash ~/steadfaste-fleet/ops/scripts/manage/deploy-blocked-ips.sh
Generates blocked_ips.conf from blocked_ips.add, deploys with sudo cp,
validates with nginx -t, and reloads nginx. No broad sudo script needed.
Architecture
fail2ban ──> iptables ban (immediate)
│
nginx scanner ──> blocked_ips.add ──> pipeline ──> git commit/push
│
install-nginx-full.sh
│
nginx reload
fail2ban reload
04 同仓库更多 Skills
macbook-linux-maintenance
Legacy MacBook Linux fixes: GPU wedge, reboot hang, thermal.
governance-regression-triage
Triage a host's governance issues: what changed.
enforcement-immutability
Use when enforcement files lose their immutable flag.
steadfaste-fleet-repo-deploy
Use when committing to the steadfaste-fleet repo.
steadfaste-fleet-maintenance
Maintain an installed Steadfaste Fleet instance — update both the upstream Hermes Agent and the fleet repo layer, merge diverged histories, sync skills safely, and troubleshoot common issues. Covers the dual-update workflow (hermes update + fleet-update.sh), encrypted brain data backup, mycortex import, and recovery techniques.
fleet-preflight
DEPRECATED alias — merged into survey-before-action (2026-08-20). Load survey-before-action instead; its "Repo-Specific Pre-Flight" section covers git search, Hermes boundary, and deployment verification.