Refuse a `CapabilityCreation` run when `directory` is below `'operator'` authority

Merged
DO
1mo ago
+514-12

CapabilityCreation imports and runs the Python in its directory as the operator's. The check before a run only asked for a writable local workspace, so a directory in a cloned repository or a user's upload passed it. A run now also refuses to start unless Workspace.authority_of(directory) is 'operator'.

[!WARNING]
Compatibility impact: A directory outside the workspace's working directory, such as LocalWorkspace('./project') with CapabilityCreation(Path('.authored')), now raises UserError at the start of a run, because authority_of gives a path outside the workspace 'none'.

Why this can ship in a minor release: It's a security hardening of an opt-in capability, and it fails closed with an error that says what to do. The docs did allow this placement (directory is "not a workspace path"), and they now state the requirement.

Migration: Name the directory: LocalWorkspace('./project', path_authority={'/abs/path/.authored': 'operator'}).

Store directoryBeforeNow
In an operator workspacerunsruns
In a workspace at 'user' or 'none'runsrefused
Under path_authority={'vendor': 'none'} in an operator workspace, or a link to such a pathrunsrefused
Named 'operator' in a workspace at 'none'runsruns
Outside the working directory, not namedrunsrefused
Outside the working directory, named 'operator'runsruns

Notes for review:

  • Deferred loading. A capability loaded mid-run with load_capability skips before_run, so without another check author_capability ran its code in any workspace, and the writable local workspace check was skipped the same way. The checks now also run before each authoring tool, which fails the run. Under Temporal, a deferred CapabilityCreation is already refused when it loads, because its toolset can't be added at runtime.
  • The directory is read against the process's directory. directory is not a workspace path, so a relative one is made absolute first; passed as is, authority_of would ask about the wrong location. Reading it blocks and can't happen in workflow code, so it's a durable operation. tests/harness/capability_creation/test_temporal.py runs the check on a real sandboxed worker.
  • store.load_active() isn't covered. It's called before the run and has no workspace to ask, so it runs what it finds. The docs say so, along with that directory must hold only operator-written or authored code. #12484 stays open for a workspace argument on it.
  • A wrapper overriding the authority property isn't seen. authority_of reads the wrapper layers, as its docstring says, so such a wrapper passes this check. Setting authority goes through AuthorityWorkspace, and this PR doesn't change that.
  • Under durable execution, the check adds units at the start of each run and before each authoring tool call (the directory read, plus realpath calls), which changes the event history of a workflow in flight during an upgrade.

Checklist

  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
  • PR title is fit for the release changelog.

šŸ¤– Generated with Claude Code