Skip to content

Risk levels, auto-confirm of safe changes, apply --wait, machine-enforced guard (#12, #38) - #61

Merged
Cd1s merged 1 commit into
mainfrom
feat/risk-guard
Sep 25, 2026
Merged

Cd1s merged 1 commit into
mainfrom
feat/risk-guard

Conversation

@Cd1s

@Cd1s Cd1s commented Sep 25, 2026

Copy link
Copy Markdown
Owner

What

Risk levels (mr/risk.go). Every plan is rated:

level when web UI
low no service restarts (files, an atomic firewall reload) kept automatically after apply + verify
medium services restart, none on the administrator's own path kept automatically after apply + verify
high the administrator's own path; LAN addresses; WANs; the router's inbound rules, SSH / web UI / tailscale settings; the guard waits for 保留 (reasons shown in red)

The administrator's path comes from their address (web: REMOTE_ADDR, CLI: SSH_CLIENT): ip route get gives the netdev; for a bridge, the neighbour's MAC and the bridge fdb give the member port. So "you are on WiFi phy1-ap0 and hostapd restarts", "you are on tailscale and tailscale restarts", "you come in over this PPPoE link and it redials", "you are in SSH and dropbear restarts" are high. mr plan / mr apply end with risk: …; --explain (or -v) says what each action does in plain words (WiFi drops for a few seconds, the WAN redials for ~5–10 s, DNS blips for ~1 s, …).

"Kept automatically" means: the browser confirms the change itself once the job is applied and verified and the page can still reach the router — the confirm window keeps doing its job for changes that cut the administrator off.

mr apply --confirm N --wait: asks on the terminal; y keeps the change; Ctrl-C, a dropped SSH session (SIGHUP / EOF on stdin) or the end of the countdown roll it back at once (the detached timer stays as a backstop if the process is killed).

Guard (mr/guard.go, from #38) — the owner's baselines, checked by Config.Validate after every module, so no path (web UI, CLI, restore, a future API token or agent) can apply a config that breaks them:

guard:
  never_expose: [ssh, panel, dns]   # no firewall.open / forward to the router reaches these ports from the WAN
  always_bypass: [desktop]          # never proxied (proxy.bypass name, or a dhcp.hosts name whose MAC is bypassed)
  offload: hardware                 # firewall.offload may not drop below this
  ssh_lan_only: true                # SSH (when on) listens on LAN-zone addresses only

Changing guard itself is a high-risk change. mr schema (for #37's tool schemas) comes with #17; max_risk_without_touch with #37.

Why

#12: automatic confirmation for changes that cannot lock the administrator out, clear warnings for those that can, and a terminal flow that rolls back as soon as the SSH session drops. #38: baselines enforced by the machine rather than by discipline — including against a prompt-injected agent.

Verification

  • Tests: risk level for every rule including each administrator-path case; plain-word effects; --wait keeping the change on y; every guard rule (ranges, forwards to the router, a moved SSH port, offload order, unknown names) and the allowed cases (the same port forwarded to another host, a disabled entry, proxy off). The lab config carries a guard and CI validates / renders it.
  • tools/ci.sh passes (private and public trees).

Closes #12 · Part of #38

https://claude.ai/code/session_01HWeUjo1dmS7gBkCYHrVjCr

… machine-enforced guard

Part 2 of #12, with the guard and risk levels of #38.

- Every plan gets low / medium / high with reasons (the administrator's own path via ip route +
  bridge fdb, LAN addresses, WANs, inbound rules, SSH / web UI / tailscale, the guard);
  `--explain` says what each action does.
- Web UI: level, reasons and effects in the apply dialog; low / medium changes are kept by the page
  once applied, verified and reachable; high ones wait for 保留.
- `mr apply --confirm N --wait`: y keeps; Ctrl-C / a dropped SSH session / the countdown roll back.
- `guard:` (never_expose, always_bypass, offload, ssh_lan_only) enforced by `mr validate` for every
  path. Lab config carries one; tests for every rule.

Closes #12
@Cd1s
Cd1s merged commit 4e3e5a4 into main Sep 25, 2026
2 checks passed
@Cd1s
Cd1s deleted the feat/risk-guard branch September 25, 2026 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

提议:变更安全与可追溯(语义 diff、快照历史对比、自动确认与风险分级)

1 participant