feat(substrate): install an egress policy on the session actor before it starts #265
Wrapping the raw protojson error can expose policy contents in startup diagnostics: for example, a hostname supplied as a string instead of an array can be quoted in the decoder error. Startup errors may be collected in container logs, so they are not necessarily an operator-only channel. Omit the raw decoder message (or retain only a sanitized location) and add a malformed-input case with a private hostname to the startup checks.
<!-- ccr-overview-v2 -->
🟡 Changes recommended
Raw protojson errors can expose private policy contents in collected startup logs, requiring sanitized diagnostics and a malformed-input regression check with a private hostname.
<details open>
<summary><strong>1 open issue</strong></summary>
</details>
<details>
<summary><strong>What changed in this PR</strong></summary>
Adds pre-start egress policy installation to the Substrate backend, advancing #251 while keeping Substrate API dependencies in the integration module. Live gateway enforcement and credential injection remain unverified.
Changes:
-substrate-egress-policy-file flag.| File | Description |
| ---- | ----------- |
| spec.md | Defines policy configuration semantics and remaining verification gaps. |
| session/egress_policy_error_test.go | Tests public error codes and sanitized policy refusals. |
| runtime/substrate/substrate.go | Installs policies at actor lifecycle transitions. |
| runtime/substrate/substrate_test.go | Allows backend options in the memory-tier test helper. |
| runtime/substrate/egress.go | Defines neutral policy types, optional interface, and installation logic. |
| runtime/substrate/egress_test.go | Tests ordering, failures, existing policies, and logging. |
| integrations/substrate/egress.go | Implements policy RPCs and neutral-to-protobuf conversion. |
| integrations/substrate/egress_test.go | Tests conversion, validation, and error mapping. |
| integrations/substrate/e2e/egress_test.go | Adds lifecycle policy readback and failed-install checks. |
| integrations/substrate/cmd/agentsessionsd/substrate.go | Loads and configures a static policy file. |
| integrations/substrate/cmd/agentsessionsd/main_test.go | Checks adapter support for the optional interface. |
| integrations/substrate/cmd/agentsessionsd/egress_test.go | Tests startup checks and daemon policy installation. |
| hack/provision-e2e-access.sh | Provisions access for egress tests. |
| docs/substrate-conformance.md | Documents configuration, lifecycle behavior, and test scope. |
| docs/security.md | Explains policy security guarantees and limitations. |
| changelog/unreleased/egress-policy.md | Records the new backend option and daemon flag. |
| changelog/unreleased/egress-policy-compat.md | Records compatibility and failure behavior. |
| .github/workflows/substrate-e2e.yml | Includes egress tests in the existing e2e job. |
</details>
<sub>Review effort: Balanced</sub>
Keeping this as is: the egress policy file is operator-supplied config, not a secret, and the error goes only to the operator starting the daemon. Quoting the bad value makes the misconfiguration easier to find.
Approved these changes.
gambtho
aramase
Part of #251.
A harness that reaches the network without going through a mediating proxy needs its actor's egress policy in place before the actor's compute first runs. Substrate denies all egress for an actor that has no policy, so installing it late means the first turn runs with nothing allowed.
substrate.WithEgressPolicytakes a function of the session spec and returns the rules for that session's actor. The rule type is neutral and lives inruntime/substrate(http,httpsandtls_passthroughrules, including credential-header effects from a credential URI or an actor JWT), so the root module does not import the Substrate API. Theintegrations/substrateadapter converts it to the Substratedefaultpolicy.CreateActorand before the firstResumeActor, before any later resume of a suspended actor, and on a fork child's clone before it resumes. If the install fails the call fails and the actor stays suspended (a fork clone is torn down).EgressPolicyClientinterface, checked by type assertion likeSnapshotCloner;ControlClientis unchanged. With a policy configured and a client that lacks the interface, the call is refused before any actor is created. That refusal, and a policy Substrate rejects as invalid, reach callers asFAILED_PRECONDITIONwith reasonCOMPUTE_CONFIG_INVALID; the text does not include Substrate's message.agentsessionsd(substrate build) gets-substrate-egress-policy-file, a protojsonEgressPolicyread once at startup.Tested with fake
ControlClienttests for install order, the fork child (stateful and stateless), a failed install leaving the actor suspended, no policy leaving the call sequence unchanged, the missing-interface refusal and the already-exists keep path. The public status code and reason are checked over gRPC for Exec, Resume and Fork. Adapter conversion and daemon flag tests are included, andgo test -racepasses in the root module and inintegrations/substrate.The new e2e tests (
TestEgressPolicy*, run by the substrate e2e workflow) read back the installed policy at create, resume and fork. I have not run them against a live Substrate, and nothing here exercises gateway enforcement or credential injection end to end, so this isPart ofrather than closing the issue.