feat(hub): Controls page switches MCP servers, plugins and Artifacts

The Firewall page becomes Controls with three tabs: Tools lists every MCP server, plugin and feature switch of ~/.claude/settings.json with each other settings file that sets it differently, Rules keeps the settings lists and the hub rule form, Groups the groups and sets. A flip stages a change in one shared Apply bar; Apply shows the diff and signs it with the passkey as before. The signer writes deniedMcpServers rules, enabledPlugins entries and switches only in the own file and refuses wrong types and no-op flips; switching, the capability views and the per-item checks are one function each.

🎯 Fix: 88 %
💥 Break: 6 %
💸 Tokens: –
⏱️ Velocity: –
🛡️ Security: 100 %
🏆 Score: 83
🚦 Gate: ⛔ fix 88 % < 90, break 6 % > 5

Created-with: https://s.veen.world/skills
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kevin Veen-BirkenbachandClaude Opus 5.5 committed 2026-11-18 20:39:10 +00:00
1 parent 78f2fec339
commit 50363b1a33
16 files changed
+645 -78

No files matched your search

+68 -13
View File
@@ -7,7 +7,9 @@
--results: the directory each job's result goes to as <id>.json.
--view: the file the Firewall reads, e.g.
~/.local/state/kvb-orchestrator/firewall/view.json: per listed file
its path, sha256 and only its permissions and sandbox sections.
its path, sha256, whether it is ~/.claude/settings.json and only the
part signing.settings_view() keeps, and the names of the MCP servers
and plugins known() finds.
--approvers: the pinned passkeys, e.g. ~/.config/kvb-orchestrator/approvers.json.
--replay: this writer's replay store, outside the hub's reach, e.g.
~/.local/state/kvb-orchestrator-approvals/firewall.json.
@@ -21,7 +23,8 @@ Returns:
every job in --jobs: verifies the operator's passkey signature over
file, base and changes with the replay store; refuses a file outside the
fixed list (~/.claude/settings.json and <repository>/.claude/settings.json
of every repository the tree file knows), a link or non-directory on its
of every repository the tree file knows), an MCP server, plugin or switch
change outside ~/.claude/settings.json, a link or non-directory on its
path, a file of another uid, a non-regular file and a file whose sha256
is no longer the signed base; then applies exactly the signed changes to
the parsed file, keeps every other key, copies the old bytes to
@@ -57,18 +60,23 @@ DIRECTORY = os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW | os.O_CLOEXEC
FILE = os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK | os.O_CLOEXEC
CREATE = os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_NOFOLLOW | os.O_CLOEXEC
READ_LIMIT = 1 << 20
CONFIG_LIMIT = 16 << 20
NEW_MODE = 0o600
BACKUP = "before-firewall"
OUTSIDE = "an agent or its sandbox runs this: the settings writer runs only from the kvb-orchestrator-firewall unit"
MISSING_DIRECTORY = "no directory: create it first"
def own_file(home: Path) -> str:
return str(home / ".claude" / "settings.json")
def listed(home: Path, tree: Path) -> list[str]:
"""Returns:
The fixed list of settings files: the operator's own and those of
every repository the tree file knows.
"""
own = str(home / ".claude" / "settings.json")
own = own_file(home)
projects = sorted(f"{repository.rstrip('/')}{signing.SETTINGS_FILE}" for repository in tree_facts(tree)[0])
return [own, *(path for path in projects if path != own)]
@@ -90,13 +98,18 @@ def parent_of(path: str) -> int:
return fd
def read_settings(parent: int, name: str) -> tuple[bytes | None, os.stat_result | None]:
"""Returns:
def read_settings(parent: int, name: str, limit: int) -> tuple[bytes | None, os.stat_result | None]:
"""Args:
parent: the open directory holding the file.
name: the file's name in it.
limit: the most bytes the file may hold.
Returns:
The file's bytes and status, None and None while it is missing.
Raises:
signing.Refused for a link, a non-regular file or one over
READ_LIMIT bytes.
signing.Refused for a link, a non-regular file or one over limit
bytes.
"""
try:
fd = os.open(name, FILE, dir_fd=parent)
@@ -108,9 +121,9 @@ def read_settings(parent: int, name: str) -> tuple[bytes | None, os.stat_result
found = os.fstat(fd)
if not stat.S_ISREG(found.st_mode):
raise signing.Refused("the file is no regular file")
data = handle.read(READ_LIMIT + 1)
if len(data) > READ_LIMIT:
raise signing.Refused(f"the file is larger than {READ_LIMIT} bytes")
data = handle.read(limit + 1)
if len(data) > limit:
raise signing.Refused(f"the file is larger than {limit} bytes")
return data, found
@@ -216,7 +229,7 @@ def read_view(path: str, entry: dict) -> dict:
except OSError as error:
return {**entry, "error": f"a link or no directory on the path: {error.strerror}"}
try:
data, _ = read_settings(parent, Path(path).name)
data, _ = read_settings(parent, Path(path).name, READ_LIMIT)
return {**entry, "exists": data is not None, "sha256": digest(data), "settings": signing.settings_view(parsed(data))}
except (OSError, Unsafe, signing.Refused) as error:
return {**entry, "error": str(error)[:300]}
@@ -224,6 +237,45 @@ def read_view(path: str, entry: dict) -> dict:
os.close(parent)
def loaded(path: Path) -> dict:
"""Returns:
The JSON object in path, read as read_settings() reads a settings
file but up to CONFIG_LIMIT bytes; {} for a file that is missing,
linked, no regular file, too large, unreadable or no object.
"""
try:
parent = parent_of(str(path))
except OSError:
return {}
try:
data, _ = read_settings(parent, path.name, CONFIG_LIMIT)
value = json.loads(data) if data else {}
except (OSError, ValueError, RecursionError, signing.Refused):
return {}
finally:
os.close(parent)
return value if isinstance(value, dict) else {}
def known(home: Path) -> dict:
"""Returns:
{"servers", "plugins"}: the names of the MCP servers ~/.claude.json
configures for the user or a project or that claude.ai connected
once, and the ids of the installed plugins; names only, never a
value, and nothing from a file that is missing or unreadable.
"""
config = loaded(home / ".claude.json")
projects = config.get("projects")
scopes = [config, *(projects.values() if isinstance(projects, dict) else [])]
servers = [name for scope in scopes if isinstance(scope, dict) and isinstance(scope.get("mcpServers"), dict) for name in scope["mcpServers"]]
connected = config.get("claudeAiMcpEverConnected")
plugins = loaded(home / ".claude" / "plugins" / "installed_plugins.json").get("plugins")
return {
"servers": signing.names_of([*servers, *(connected if isinstance(connected, list) else [])], signing.MCP_NAME),
"plugins": signing.names_of(plugins, signing.PLUGIN_ID),
}
class Writer:
def __init__(self, trust: verifier.Trust, home: Path, tree: Path) -> None:
self.trust = trust
@@ -231,7 +283,8 @@ class Writer:
self.tree = tree
def view(self) -> dict:
return {"written": time.time(), "files": [view_of(path) for path in listed(self.home, self.tree)]}
own = own_file(self.home)
return {"written": time.time(), "files": [view_of(path) | {"own": path == own} for path in listed(self.home, self.tree)], "known": known(self.home)}
def apply(self, item: dict, job_id: str) -> dict:
"""Args:
@@ -252,7 +305,7 @@ class Writer:
except OSError as error:
raise signing.Refused(f"a link or no directory on the path: {error.strerror}") from None
try:
data, found = read_settings(parent, name)
data, found = read_settings(parent, name, READ_LIMIT)
if found is not None and found.st_uid != os.getuid():
raise signing.Refused(f"the file belongs to uid {found.st_uid}, not {os.getuid()}")
if digest(data) != item["base"]:
@@ -295,6 +348,8 @@ class Writer:
return "refused", f"no valid operator signature: {error}", {}
if item["file"] not in listed(self.home, self.tree):
return "refused", "unlisted file: only ~/.claude/settings.json and the .claude/settings.json of a repository pkgmgr knows", {}
if item["file"] != own_file(self.home) and any(change["list"] in signing.CAPABILITIES for change in item["changes"]):
return "refused", "MCP servers, plugins and switches change only in ~/.claude/settings.json", {}
try:
written = self.apply(item, job_id)
except signing.Refused as error:
+119 -20
View File
@@ -46,6 +46,10 @@ SETTINGS_KEYS = ("file", "base", "changes")
SETTINGS_SECTIONS = ("permissions", "sandbox")
SETTINGS_LISTS = ("permissions.allow", "permissions.ask", "permissions.deny", "sandbox.filesystem.allowWrite", "sandbox.filesystem.denyRead", "sandbox.network.allowedDomains")
SETTINGS_OPS = ("add", "remove")
MCP_NAME = re.compile(r"(?=.{1,128}\Z)[A-Za-z0-9]+(?:[ ._:-][A-Za-z0-9]+)*")
PLUGIN_ID = re.compile(r"[A-Za-z0-9][A-Za-z0-9._-]{0,127}@[A-Za-z0-9][A-Za-z0-9._-]{0,127}")
SWITCHES = ("enableArtifact",)
CAPABILITIES = {"deniedMcpServers": MCP_NAME, "enabledPlugins": PLUGIN_ID, "switches": re.compile("|".join(SWITCHES))}
CHANGE_KEYS = ("list", "op", "entry")
CHANGE_LIMIT = 50
ENTRY = re.compile(r"(?=[^\x00-\x1f\x7f\ud800-\udfff]*\S)[^\x00-\x1f\x7f\ud800-\udfff]{1,500}")
@@ -516,8 +520,11 @@ def settings_file_problem(file: object) -> str | None:
def change_problem(change: object) -> str | None:
if not isinstance(change, dict) or set(change) != set(CHANGE_KEYS) or not all(isinstance(change[name], str) for name in CHANGE_KEYS):
return "a change holds exactly list, op and entry as text"
if change["list"] not in SETTINGS_LISTS or change["op"] not in SETTINGS_OPS:
return f"list must be one of {', '.join(SETTINGS_LISTS)} and op one of {', '.join(SETTINGS_OPS)}"
lists = (*SETTINGS_LISTS, *CAPABILITIES)
if change["list"] not in lists or change["op"] not in SETTINGS_OPS:
return f"list must be one of {', '.join(lists)} and op one of {', '.join(SETTINGS_OPS)}"
if change["list"] in CAPABILITIES:
return None if CAPABILITIES[change["list"]].fullmatch(change["entry"]) else f"entry is no valid {change['list']} name"
return hidden_problem(change, "change") if ENTRY.fullmatch(change["entry"]) else "entry must be one line of 1 to 500 characters"
@@ -551,10 +558,39 @@ def changes_problem(changes: object) -> str | None:
def settings_view(settings: dict) -> dict:
"""Returns:
The permissions and sandbox sections of a settings object, the only
part of the file the Agent Orchestrator receives.
The only part of a settings object the Agent Orchestrator receives:
the permissions and sandbox sections, the deniedMcpServers rules that
name a server and nothing else, the enabledPlugins entries of a
PLUGIN_ID and the SWITCHES. A capability key of the wrong type and a
plugin or switch value that is no boolean show as null, so the hub
refuses a change to it as switch_capability() refuses it in the file.
"""
return {name: settings[name] for name in SETTINGS_SECTIONS if isinstance(settings.get(name), dict)}
view = {name: settings[name] for name in SETTINGS_SECTIONS if isinstance(settings.get(name), dict)}
if "deniedMcpServers" in settings:
view["deniedMcpServers"] = denied_view(settings["deniedMcpServers"])
if "enabledPlugins" in settings:
view["enabledPlugins"] = plugins_view(settings["enabledPlugins"])
return view | {name: settings[name] if isinstance(settings[name], bool) else None for name in SWITCHES if name in settings}
def denied_view(denied: object) -> list[dict] | None:
if not isinstance(denied, list):
return None
return [rule for rule in denied if isinstance(rule, dict) and list(rule) == ["serverName"] and isinstance(rule["serverName"], str) and MCP_NAME.fullmatch(rule["serverName"])]
def plugins_view(plugins: object) -> dict | None:
if not isinstance(plugins, dict):
return None
return {name: on if isinstance(on, bool) else None for name, on in plugins.items() if PLUGIN_ID.fullmatch(name)}
def names_of(found: object, pattern: re.Pattern) -> list[str]:
"""Returns:
The texts among found (a list, or a dict's keys) that pattern fully
matches, sorted and each once; anything else is dropped.
"""
return sorted({name for name in found if isinstance(name, str) and pattern.fullmatch(name)}) if isinstance(found, (list, dict)) else []
def plain_problem(value: object, depth: int) -> str | None:
@@ -604,25 +640,88 @@ def apply_changes(settings: dict, changes: list[dict]) -> dict:
"""
result = plain_copy(settings)
for change in changes:
*path, leaf = change["list"].split(".")
node = result
for name in path:
node = node.setdefault(name, {})
if not isinstance(node, dict):
raise Refused(f"{name} is no object")
entries = node.setdefault(leaf, [])
if not isinstance(entries, list) or not all(isinstance(entry, str) for entry in entries):
raise Refused(f"{change['list']} is no list of texts")
listed = change["entry"] in entries
if listed == (change["op"] == "add"):
raise Refused(f"{change['list']} {'lists' if listed else 'does not list'} {change['entry']}")
if listed:
entries.remove(change["entry"])
if change["list"] in CAPABILITIES:
switch_capability(result, change["list"], change["entry"], change["op"] == "add")
else:
entries.append(change["entry"])
change_list(result, change)
return result
def change_list(settings: dict, change: dict) -> None:
*path, leaf = change["list"].split(".")
node = settings
for name in path:
node = node.setdefault(name, {})
if not isinstance(node, dict):
raise Refused(f"{name} is no object")
entries = node.setdefault(leaf, [])
if not isinstance(entries, list) or not all(isinstance(entry, str) for entry in entries):
raise Refused(f"{change['list']} is no list of texts")
listed = change["entry"] in entries
if listed == (change["op"] == "add"):
raise Refused(f"{change['list']} {'lists' if listed else 'does not list'} {change['entry']}")
if listed:
entries.remove(change["entry"])
else:
entries.append(change["entry"])
def switch_capability(settings: dict, name: str, entry: str, add: bool) -> None:
"""Args:
settings: the settings copy, changed in place.
name: a CAPABILITIES key; add lists entry in it: a deniedMcpServers
rule {"serverName": entry} blocks the server before it loads, an
enabledPlugins entry turns true, a switch drops its false and
falls back to its default, on.
entry: the server name, plugin id or switch.
add: True for op add, False for op remove.
Raises:
Refused when the key or entry holds the wrong type or entry is in
the state already; removing a blocked server drops every copy of its
rule.
"""
if name == "switches":
switch_feature(settings, entry, add)
return
blocked = name == "deniedMcpServers"
held = settings.setdefault(name, [] if blocked else {})
if not isinstance(held, list if blocked else dict):
raise Refused(f"{name} holds the wrong type")
(block_server if blocked else switch_plugin)(held, entry, add)
def switch_feature(settings: dict, entry: str, add: bool) -> None:
held = entry in settings
if held and not isinstance(settings[entry], bool):
raise Refused(f"{entry} holds the wrong type")
if (not held or settings[entry]) == add:
raise Refused(f"{entry} is {'on' if add else 'off'} already")
if add:
del settings[entry]
else:
settings[entry] = False
def switch_plugin(held: dict, entry: str, add: bool) -> None:
enabled = held.get(entry, False)
if not isinstance(enabled, bool):
raise Refused(f"{entry} holds the wrong type")
if enabled == add:
raise Refused(f"{entry} is {'enabled' if add else 'disabled'} already")
held[entry] = add
def block_server(held: list, entry: str, add: bool) -> None:
rule = {"serverName": entry}
if (rule in held) == add:
raise Refused(f"{entry} is {'blocked' if add else 'not blocked'} already")
if add:
held.append(rule)
else:
held[:] = [kept for kept in held if kept != rule]
def warnings(command: str) -> list[str]:
return [label for label, pattern in WARNINGS if pattern.search(command)]