feat(orchestrator): show firewall and hub rules in one table with hits
One rule table replaces the two lists: each allow, ask and deny rule shows its hits from the extracted dry-run matcher, ask patterns the matcher never grants read never granted instead of unused, and the table scrolls in its own container below 600 px. Tests run once on unify/skills-20261114 after the merge (operator order 2026-11-14). 🎯 Fix: 85 % 💥 Break: 10 % 💸 Tokens: 100 % ⏱️ Velocity: 103 % 🛡️ Security: 100 % 🏆 Score: 74 🚦 Gate: ⛔ fix 85 % < 90, break 10 % > 5; velocity 103 % > 100: ask the operator before the commit Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
48f26b678a
commit
23a7d2dc1d
9 files changed
+377
-85
No files matched your search
@@ -10,6 +10,7 @@ from .errors import Conflict, Missing, ToolError
|
||||
from .fields import decode, expect, visible
|
||||
from .ledger import Ledger
|
||||
from .records import read_json, stamp
|
||||
from .requesting import RECENT_DAYS, matched
|
||||
from .rules import EVERY_AGENT, RULE_KINDS
|
||||
from .signed import signing
|
||||
|
||||
@@ -25,21 +26,86 @@ HASH = re.compile(r"[0-9a-f]{64}")
|
||||
PERMISSION_LISTS = ("allow", "ask", "deny")
|
||||
SET_KEYS = ("kind", "tool", "pattern", "scope")
|
||||
CHAINED = "chains, pipes, redirects or substitutions"
|
||||
COUNT_ID = "0" * 16
|
||||
UNSEEN = {"hits": None, "never": ""}
|
||||
|
||||
|
||||
def settings_request(raw: object) -> bool:
|
||||
return isinstance(raw, list) and bool(raw) and all(isinstance(entry, dict) and entry.get("kind") == "settings" for entry in raw)
|
||||
|
||||
|
||||
def tool_and_spec(entry: str) -> tuple[str, str]:
|
||||
"""Returns:
|
||||
The tool of a permission rule such as Bash(git push:*) and its
|
||||
specifier, git push:*; "" without specifier.
|
||||
"""
|
||||
found = RULE_TEXT.fullmatch(entry)
|
||||
if found is None:
|
||||
return entry.strip(), ""
|
||||
return found.group("tool").strip(), (found.group("spec") or "").strip()
|
||||
|
||||
|
||||
def tool_and_prefix(entry: str) -> tuple[str, str]:
|
||||
"""Returns:
|
||||
The tool of a permission rule such as Bash(git push:*) and the first
|
||||
word of its specifier, for Bash the command; "" without specifier.
|
||||
"""
|
||||
found = RULE_TEXT.fullmatch(entry)
|
||||
if found is None:
|
||||
return entry.strip(), ""
|
||||
return found.group("tool").strip(), WORD.split((found.group("spec") or "").strip(), maxsplit=1)[0]
|
||||
tool, spec = tool_and_spec(entry)
|
||||
return tool, WORD.split(spec, maxsplit=1)[0]
|
||||
|
||||
|
||||
def entry_rule(entry: str) -> dict:
|
||||
"""Returns:
|
||||
A permissions.ask entry as the fields of an ask rule for every agent
|
||||
in every directory: its tool, and its specifier as pattern, where a
|
||||
trailing :* or no specifier matches any rest.
|
||||
"""
|
||||
tool, spec = tool_and_spec(entry)
|
||||
pattern = f"{spec.removesuffix(':*')}*" if spec.endswith(":*") or not spec else spec
|
||||
return {"kind": "ask", "tool": tool, "pattern": pattern, "scope": "*"}
|
||||
|
||||
|
||||
def hits(rule: dict, asks: list[dict], now: float) -> dict:
|
||||
"""Args:
|
||||
rule: kind ask, tool, pattern and scope of a rule, with agents when
|
||||
it applies to one agent or group only.
|
||||
asks: the asks of the last RECENT_DAYS as recent_subjects() lists
|
||||
them.
|
||||
now: the current time in epoch seconds.
|
||||
|
||||
Returns:
|
||||
{"hits": how many of the asks the rule matches, on or off, expired or
|
||||
not, "never": ""}; hits None and never the warning when the pattern
|
||||
itself names a command the matcher never grants.
|
||||
"""
|
||||
pattern = rule["pattern"]
|
||||
never = [*signing.warnings(pattern), *([CHAINED] if signing.CHAINED.search(pattern) else [])]
|
||||
if never:
|
||||
return {"hits": None, "never": never[0]}
|
||||
return {"hits": matched({**rule, "id": COUNT_ID, "expires": now + RECENT_DAYS * 86400}, asks, now), "never": ""}
|
||||
|
||||
|
||||
def counted(groups: list[dict], asks: list[dict], now: float) -> list[dict]:
|
||||
"""Returns:
|
||||
groups with each entry's specifier and hits: counted for an ask
|
||||
entry, UNSEEN for an allow or deny entry.
|
||||
"""
|
||||
def shown(entry: dict) -> dict:
|
||||
found = hits(entry_rule(entry["entry"]), asks, now) if entry["list"] == "ask" else UNSEEN
|
||||
return {**entry, "spec": tool_and_spec(entry["entry"])[1], **found}
|
||||
|
||||
return [{**group, "entries": [shown(entry) for entry in group["entries"]]} for group in groups]
|
||||
|
||||
|
||||
def stored_hits(rule: dict, asks: list[dict], now: float) -> dict:
|
||||
"""Returns:
|
||||
hits() of a stored ask rule for the agents it is signed for, UNSEEN
|
||||
for a review or decision rule.
|
||||
"""
|
||||
if rule["kind"] != "ask":
|
||||
return UNSEEN
|
||||
fields = {key: rule[key] for key in ("kind", "tool", "pattern", "scope")}
|
||||
return hits({**fields, "agents": rule["agents"]} if "agents" in rule else fields, asks, now)
|
||||
|
||||
|
||||
def grouped(permissions: object) -> list[dict]:
|
||||
@@ -130,8 +196,11 @@ class Firewall:
|
||||
|
||||
def firewall(self) -> dict:
|
||||
files, meta = self.settings_files()
|
||||
listed = [{key: entry[key] for key in ("path", "exists", "sha256", "error")} | {"groups": grouped(entry["settings"].get("permissions")), "sandbox": sandbox_entries(entry["settings"].get("sandbox"), "sandbox")} for entry in files]
|
||||
return {**meta, "files": listed, "lists": list(signing.SETTINGS_LISTS), "patterns": deny_patterns(), "groups": self.groups.listed(), "sets": self.rule_sets.listed()}
|
||||
now = time.time()
|
||||
asks = self.recent_subjects("ask", now)
|
||||
listed = [{key: entry[key] for key in ("path", "exists", "sha256", "error")} | {"groups": counted(grouped(entry["settings"].get("permissions")), asks, now), "sandbox": sandbox_entries(entry["settings"].get("sandbox"), "sandbox")} for entry in files]
|
||||
rules = {rule["id"]: stored_hits(rule, asks, now) for rule in self.rules.listed()}
|
||||
return {**meta, "files": listed, "lists": list(signing.SETTINGS_LISTS), "patterns": deny_patterns(), "groups": self.groups.listed(), "sets": self.rule_sets.listed(), "days": RECENT_DAYS, "rules": rules}
|
||||
|
||||
def settings_changes(self, raw: object) -> list[dict]:
|
||||
"""Args:
|
||||
|
||||
Reference in new issue
Block a user