Skip to content

Commit a091e23

Browse files
itcmsgrclaude
andcommitted
feat(rebuild): v1.96 PR-05 — module restore truth + post-restore verification
Add post-module-restore verification step between steps 8-12 and POST validation. Closes the silent daemon-dependent module restoration gap. Verification checks (Level 1+2 per contract): - DDoS: nft list chain ip nftban nftban_ddos_filter - Portscan: nft list chain ip nftban nftban_portscan - BotGuard: nft list chain ip nftban nftban_botguard If a module reported RESTORE_OK but its chain is missing from kernel, result is downgraded to RESTORE_INCOMPLETE. This prevents false PROTECTED when module enable command returned 0 but the chain was not actually created (daemon dependency failure). Level 3 (activation evidence) is not checked here — requires traffic and produces WARNING only, not DEGRADED (per contract tightening #3). Contract: V196_REBUILD_RECOVERY_CONTRACT.md §8 INV-RR-007: Module restore failure is surfaced, not silent Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 789045d commit a091e23

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

cli/lib/nftban/cli/cmd_firewall.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,6 +1496,48 @@ _firewall_rebuild_core() {
14961496
[[ "$quiet" == "false" ]] && echo " Consumed .rpmnew and rendered into live config" || true
14971497
fi
14981498

1499+
# ─────────────────────────────────────────────────────────────────────────
1500+
# v1.96: Post-module-restore verification (INV-RR-007)
1501+
# Level 1: Structure presence (chains + sets exist in kernel)
1502+
# Level 2: Wiring correctness (jumps in correct anchor positions)
1503+
# Level 3 deferred — requires traffic (WARNING only if missing)
1504+
# ─────────────────────────────────────────────────────────────────────────
1505+
if declare -f _rebuild_classify_module_result &>/dev/null; then
1506+
[[ "$quiet" == "false" ]] && echo ""
1507+
[[ "$quiet" == "false" ]] && echo " [VERIFY] Module restore verification..."
1508+
1509+
# DDoS: check for ddos helper chain in ip nftban
1510+
if [[ "$_ddos_enabled" == "true" && "$_REBUILD_MODULE_DDOS" == "$MR_OK" ]]; then
1511+
if nft list chain ip nftban nftban_ddos_filter &>/dev/null; then
1512+
# Level 1+2: chain exists and is reachable (nft validates jump targets)
1513+
[[ "$quiet" == "false" ]] && echo " DDoS: chain verified (Level 1+2)"
1514+
else
1515+
_rebuild_classify_module_result "ddos" "$MR_INCOMPLETE"
1516+
[[ "$quiet" == "false" ]] && echo " DDoS: chain MISSING after enable (downgraded to INCOMPLETE)"
1517+
fi
1518+
fi
1519+
1520+
# Portscan: check for portscan helper chain
1521+
if [[ "$_portscan_enabled" == "true" && "$_REBUILD_MODULE_PORTSCAN" == "$MR_OK" ]]; then
1522+
if nft list chain ip nftban nftban_portscan &>/dev/null; then
1523+
[[ "$quiet" == "false" ]] && echo " Portscan: chain verified (Level 1+2)"
1524+
else
1525+
_rebuild_classify_module_result "portscan" "$MR_INCOMPLETE"
1526+
[[ "$quiet" == "false" ]] && echo " Portscan: chain MISSING after enable (downgraded to INCOMPLETE)"
1527+
fi
1528+
fi
1529+
1530+
# BotGuard: check for botguard helper chain
1531+
if _firewall_botguard_is_enabled 2>/dev/null && [[ "$_REBUILD_MODULE_BOTGUARD" == "$MR_OK" ]]; then
1532+
if nft list chain ip nftban nftban_botguard &>/dev/null; then
1533+
[[ "$quiet" == "false" ]] && echo " BotGuard: chain verified (Level 1+2)"
1534+
else
1535+
_rebuild_classify_module_result "botguard" "$MR_INCOMPLETE"
1536+
[[ "$quiet" == "false" ]] && echo " BotGuard: chain MISSING after enable (downgraded to INCOMPLETE)"
1537+
fi
1538+
fi
1539+
fi
1540+
14991541
# v1.78.0: POST-REBUILD VALIDATION — Compare with PRE state
15001542
[[ "$quiet" == "false" ]] && echo ""
15011543
[[ "$quiet" == "false" ]] && echo " [POST] Validating post-rebuild state..."

0 commit comments

Comments
 (0)