Access control
Deny-by-default tool grants. Module: mechaharness.core.access.
Stability: evolving.
Surface
Item |
Value |
|---|---|
Module |
|
Event |
|
Stability |
evolving |
Grants
Grant is a class hierarchy, not an enum. Intermediate classes set
namespace; leaves set name. The wire form is namespace:name. Unknown
namespaced keys round-trip; bare names (fs.write) are rejected.
Built-in CoreGrant leaves (FsRead, FsWrite, NetHttp, MediaImage,
MediaVideo, MediaAudio, GraphExecute, GraphEscalate,
ExtensionObserve, ExtensionRewrite, ExtensionBlock, ExtensionReplace)
are conveniences. Hosts add types without editing this package:
from mechaharness.core.access import Grant
class Widget(Grant):
namespace = "acme"
name = "widget"
assert Widget.key() == "acme:widget"
Grant.parse("core:fs.write") returns the registered class. Unregistered keys
still store on AccessPolicy.grants; parse raises KeyError for those.
Policy and checks
AccessPolicy is a grant list. A tool may run only when every grant it
declares is held (set(required) <= set(granted)). Tools that declare no
grants always pass.
CompoundPolicy unions several AccessPolicy layers into one grant set
(first-seen order; overlaps are idempotent). There is no deny grant — only
allow-list membership. Use it to compose reusable profiles (read-only,
media-allowed, …) without rewriting lists. It is unrelated to
JudgementPolicy (signals → verdict).
InMemoryAccessControl holds the flattened list, records each check, and emits
core:access_check when agent_id and run_id are set.
Bind grants through Config:
from mechaharness.core.access import AccessPolicy, CompoundPolicy, FsRead, FsWrite, MediaImage
from mechaharness.di import MechaHarnessConfig
class AppConfig(MechaHarnessConfig):
def get_access_policy(self):
read_only = AccessPolicy(grants=[FsRead])
media = AccessPolicy(grants=[MediaImage])
return CompoundPolicy.of(read_only, media)
# Or simply:
# def get_grants(self):
# return [FsWrite]
get_access_control() uses get_access_policy() (default: AccessPolicy from
get_grants()) and requires an EventLog. Bind access only through Config —
do not hand-wire AbstractHarness(..., access=...). Denied tools return an
error ToolResult and are not priced.
GraphExecutor checks core:graph.execute before walking a plan and
core:graph.escalate before calling GraphEscalation. Node runners may declare
extra grants via GraphNodeRunner.required_grants().
Host recipe-run pattern
Hosts choose one of these surfaces (omit → host-kit defaults:
GraphExecute + GraphEscalate on host_graph_executor; Config
get_grants() defaults to []):
Config DI — override
get_grants()/get_access_policy()/get_capability_envelope()on aMechaHarnessConfigsubclass.Per-run kwargs —
run_recipe(..., grants=|access_policy=, envelope=?)(and optionalbudget_policy=— see Budget).Story / fixture YAML —
environment.grants/environment.access_policy/environment.capability_envelope/environment.authorization_epochonuser_storyscenarios bind (1)/(2).
access_policy YAML shapes (parsed by
mechaharness.host_run_policies.access_policy_from_mapping):
grants: [core:fs.read, core:fs.write]
# or compound layers
access_policy:
layers:
- [core:fs.read]
- [core:fs.write]
Product verbs for walks: access_check, capability_envelope,
authority_gate, auth_epoch_resume, approval_interrupt. Verb-scoped
grants: on tool_lifecycle / judge is not the Config/environment
bridge.
When environment.grants / access_policy is set it replaces Config
grants for that story (empty list = deny-all). Omit the field to keep
defaults. Host-kit stays permissive until a host passes a tighter pack.
Tools
Tool / ToolRegistry.tool() accept grants= (classes or namespace:name
strings) and ability= (Ability, default simple). Demo echo / add
tools declare none.