
OPNsense Guard
io.github.d3ltasecurity由 GitHub 帳號 d3ltasecurity 發布v0.1.1更新於 Oct 29, 2026
Safety-first OPNsense firewall MCP: read-only by default, planned and auto-reverting writes.
概覽
以安全為先的 OPNsense 防火牆 MCP 伺服器:預設唯讀,寫入須先規劃、經政策檢查並自動回復。
- 可以做什麼
- 檢視防火牆狀態:規則、別名、即時狀態、防火牆與系統日誌、介面、ARP 與路由表、DHCP 租約。
- 檢查系統健康:韌體狀態、系統資訊與資源、服務、IDS/Suricata 狀態與告警、態勢與安全稽核。
- 對白名單端點執行原始 GET 請求,並顯示目前政策。
- 以差異形式規劃規則與別名變更,並列出政策拒絕原因,不動到防火牆。
- 在啟用寫入模式並設定獨立寫入 API 使用者後,套用、確認或回復已規劃的變更。
- 檢視記錄規劃與啟動事件的雜湊鏈稽核日誌。
- 適用情境
- 適合讓助理讀取並說明 OPNsense 防火牆的規則、日誌與健康狀況,或草擬經政策檢查、未確認即自動回復的規則與別名變更。適用於謹慎、可稽核的管理情境,而非批次或無人看管的變更。
- 執行需求
- 以 pipx 或 Docker 安裝的本機 Python 套件,透過 stdio 或需驗證的 HTTPS 執行。需要 OPNSENSE_URL,以及最小權限唯讀使用者的 OPNSENSE_API_KEY 與 OPNSENSE_API_SECRET;自簽憑證需 OPNSENSE_CA_BUNDLE。寫入另需政策檔、OPNSENSE_WRITE_API_KEY 與 OPNSENSE_WRITE_API_SECRET,HTTP 模式下還需 write 範圍的權杖。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 OPNsense Guard,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
opnsense-guard-mcp
A safety-first MCP server for OPNsense 26.7+.
Read-only by default. Every write is planned, policy-checked, logged, and auto-reverted unless you confirm it.
Status: alpha. Tested against a live OPNsense 26.7.4 with least-privilege API users: read tools, policy file, change planning with diffs, applying changes with verification and automatic revert, crash recovery, and a hash-chained audit log, over stdio or authenticated HTTPS. See DESIGN.md.
Not affiliated with Deciso B.V. "OPNsense" is a trademark of Deciso B.V.
What makes it different
Quick start (read-only)
-
In OPNsense (System → Access → Users), create a user with a scrambled password, no group (not
admins) and these privileges, then create an API key for it. Skip any that aren't installed; the matching tool just reports "forbidden".Most OPNsense privileges are not view-only (Firewall: Aliases is an exception): several of these also allow edits through the API. The server only sends GET requests with this key, except a search POST to two exact endpoints (
diagnostics/firewall/query_states,firewall/filter/searchRule) with a body it builds itself (current,rowCount,searchPhrase); OPNsense answers those lists properly only over POST. Still keep the list short: the privileges are what OPNsense itself enforces. -
Install:
-
Configure (copy
.env.exampleto.env, or set env vars): -
Check the config (does not contact the firewall):
-
Add to your MCP client, e.g. Claude Code:
HTTP mode (shared server)
HTTP never runs without authentication. The server refuses to start if:
- there are no tokens, or
- it binds to a non-loopback address without TLS
(override with
MCP_ALLOW_PLAINTEXT=trueonly behind a TLS proxy).
-
Create a token per client. It is printed once; only its SHA-256 is stored:
token listshows names and scopes;token revoke --name laptoptakes effect on the next request, no restart needed. -
Start the server:
-
Point the client at
https://<host>:8848/mcpwith headerAuthorization: Bearer <token>.
Repeated failed logins from one IP (10 a minute) are throttled with HTTP 429.
Claude Code and a private CA: Claude Code (Node) ignores the Windows/macOS
certificate store for MCP servers. Point NODE_EXTRA_CA_CERTS at your CA file
in the env block of ~/.claude/settings.json, then fully quit and reopen
Claude, or the connection fails with UNABLE_TO_VERIFY_LEAF_SIGNATURE.
Running in Docker
The image runs as a non-root user and keeps its audit log, change journal and
tokens in /data.
Mount a policy file and set OPNSENSE_GUARD_POLICY to enable writes. Stop the
container with docker stop (not kill) so unconfirmed changes are reverted.
Policy and planning
Without a policy.yaml the server is read-only. To enable planning, copy
policy.example.yaml to policy.yaml (or point
OPNSENSE_GUARD_POLICY at it) and edit it. Unknown keys are an error.
Planning tools (rule_plan, alias_plan) read the current state, apply every
policy check, and return a diff plus the reasons for any refusal. They never
change the firewall. Example result for a refused rule:
Built-in guardrails: only listed interfaces/actions/directions; every IP inside
allow_networks; no any→any pass, WAN inbound pass, floating rules or rules
without logging; edit only rules tagged [mcp] (unless only_modify_own: false);
anti-lockout (no block rule that matches this server's own IP, and only new
pass rules on the interface it reaches the API through). A new block or reject
rule there is allowed when the same plan adds a pass rule with a lower
sequence that provably lets every MCP host reach the API (source covers the
host IP, destination any/(self)/the API IP, TCP, port covers the API port);
both rules need a sequence.
Applying changes
Change tools appear only when both the policy is in write mode and a second, write-capable API user is configured:
Give that user exactly two privileges: Firewall: Rules [new] and
Firewall: Alias: Edit, no group. (Plain Firewall: Aliases is view-only:
it allows search/get but not addItem/setItem/delItem/reconfigure.) Over HTTP, the
change tools need a token with --scope write.
The flow:
rule_plan/alias_plan→ diff +plan_id(changes nothing).change_apply(plan_id)→ asks the human to approve the diff (MCP elicitation where the client supports it; otherwise the tool returns the diff and must be called again withuser_confirmed=true). Then it re-reads the firewall (refuses if anything drifted since planning), stores the before-state, writes, applies, reads everything back to verify, and checks the API is still reachable. Any failure → everything is reverted.- The change is pending: it is reverted automatically after
confirm_timeout_s(default 60 s) unlesschange_confirmis called. change_rollbackundoes a pending or confirmed change. A revert never overwrites an object someone else edited meanwhile (statusconflict).
Unconfirmed changes are also reverted when the server stops and, after a
crash, when it starts again. Only one change can be open at a time, and
max_changes_per_hour is enforced.
Limits, stated plainly
- The revert timer runs on the MCP host. If a change cuts that host off from the firewall API, the revert cannot reach it. The anti-lockout policy and the health probe right after apply exist to prevent and catch this, but they are not the same as the firewall-side savepoint older OPNsense versions had.
- Without elicitation,
user_confirmed=trueis the model's word that the user agreed. The audit log records which method was used.
Audit log
Every plan (allowed or refused) and server start is written to
$OPNSENSE_GUARD_DATA_DIR/audit.jsonl (default ./data). Each line holds the
hash of the previous one, so edits, deletions and reordering are detectable:
Credentials are never written to it.
Tools (read-only)
system_status, system_information, system_resources, service_list,
posture_check, suricata_status, suricata_settings, suricata_alert_status,
firewall_rules, firewall_rule_get, firewall_aliases, firewall_log,
firewall_states, system_log, interfaces, arp_table, routing_table,
dhcp_leases, raw_get, policy_show, security_audit.
In write mode also: rule_plan, alias_plan, plan_get, audit_tail.
With write credentials also: change_apply, change_confirm, change_rollback,
change_list, change_get.
firewall_rules returns one line per rule (50 by default) so a full ruleset
fits in a chat; pass detail=true for the raw OPNsense rows, or use
firewall_rule_get for one rule.
Over HTTP, a read token still sees the change tools in the tool list, but
calling one is refused (needs a token with scope 'write').
Development
Security
See SECURITY.md. Please report vulnerabilities privately.
Licence
MIT. See LICENSE.
來源:README.md,提交 138fb61
工具
0版本歷史
2- v0.1.1最新Oct 29, 2026
- v0.1.0Oct 26, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分