S09-01 - Policy Files
Purpose: Where policy is written, the network policy schema Wraith Box accepts, how the prover sees it, and narrowing by program and project.
Design
Section titled “Design”Policy is in two kinds of files. Both are on the host, outside every repository and every guest. Both are the same on every host OS (FR17-same-everywhereFR17-same-everywhere: Same on every hostThe same wb commands, flags, policy files, and behavior on every host OS.).
- Settings in TOML:
<config>/config.tomland<config>/projects/<project-id>.toml. - Network policy in YAML:
<config>/policy.yamland<config>/projects/<project-id>.policy.yaml.
<config> is per OS in S12-platformsS12-platforms: PlatformsWhich host and guest operating systems Wraith Box targets, how platform-specific code is isolated, what each platform uses, and how wb works inside WSL. (~/.config/wraithbox on
macOS).
Network policy schema
Section titled “Network policy schema”Network policy uses the network_policies part of OpenShell’s policy
schema (version 1). It holds named rules of endpoints and binaries.
An endpoint has a host, port, path, protocol, an access preset or
method and path rules, and enforce or audit.
Wraith Box parses and validates the schema in Go, with its own code.
Extension keys
Section titled “Extension keys”Wraith Box’s extensions go under one top-level key, wraithbox:
pass (host, reason), raw_tcp (host, port, reason),
wildcard_budget (S07-03-dnsS07-03-dns: DNSHow wb-netd answers the guest's DNS queries: synthetic addresses, the name form, negative answers and the wildcard budget.) and parts_off (profile, kind, part:
S07-11-http-policyS07-11-http-policy: HTTP PolicyThe HTTP rules of inspected hosts, the built-in profiles, and the parts a user can turn off., “Profile parts”). credential_bindings,
dependency_gate and git_hosts aren’t built yet, so they are refused
with policy-key-unsupported. Repository configuration can’t hold
wraithbox (policy-source, S09-03-project-settingsS09-03-project-settings: Project SettingsWhat a project's settings hold, and what a repository's own .wraithbox/ configuration may add., “Closed keys”).
Pinned release
Section titled “Pinned release”OpenShell adds fields to the schema without changing version: 1. So
the pin is an OpenShell release: v0.1.2 (X24-openshell-artifactsX24-openshell-artifacts: OpenShell artifactsDo the OpenShell parts that S07-egress-gateway, S09-policy-credentials-audit and S10-tech-stack build on exist in the assumed form, under a permissive license, at a version that can be pinned: the networkpolicies sche…,
S10-tech-stackS10-tech-stack: Technology ChoicesFix languages, libraries, packaging, and repository layout, with the reason for each choice.). Wraith Box accepts the keys of that release only.
Closed keys
Section titled “Closed keys”OpenShell rejects a policy with an unknown key at any level. So a file with Wraith Box’s extension keys isn’t a valid OpenShell policy (X24-openshell-artifactsX24-openshell-artifacts: OpenShell artifactsDo the OpenShell parts that S07-egress-gateway, S09-policy-credentials-audit and S10-tech-stack build on exist in the assumed form, under a permissive license, at a version that can be pinned: the networkpolicies sche…).
Wraith Box keeps the extensions in the same file. When it hands policy
to OpenShell’s tooling, it writes a new document with only version
and network_policies. It never hands over the user’s file.
Implemented keys
Section titled “Implemented keys”Per endpoint, Wraith Box implements host, port or ports, path,
protocol, enforcement, access, rules and deny_rules.
protocolisrestor absent. An endpoint without one is L4: it allows every method and path on its host and port, still inspected. Any other protocol, OpenShell’stcpincluded, is refused withpolicy-protocol-unsupported(I489I489 (closed): policy: load network policy YAML with a bounded decoder, closed keys and the load-time refusalsPackage M3.3 of docs/implementation-plan.md, part 2 of 3 (M3.3b)., maintainer decision 1).- An endpoint sets
portorports, not both. OpenShell takesportswhen both are set, so both is refused withpolicy-port. - A rule’s name is OpenShell’s effective name: its
namewhen it has one, and its key otherwise. A name that another rule in the file has, and a name of the built-in profiles’ rules, are refused withpolicy-rule-name. The built-in names are the profile names and every name that starts withbuiltin, in any case. - A rule that names the method
CONNECT, inrulesordeny_rules, is refused withhttp-tunnel(S07-16-tls-and-tunnelsS07-16-tls-and-tunnels: TLS and TunnelsWhat wb-proxyd does with client certificates, encrypted ClientHello and tunnels, and which refusals no mode or approval relaxes.).
The built-in profiles need deny_rules, for denies such as the git
hosting profile’s archive deny. The prover’s handling of deny_rules
wasn’t tested (X24-openshell-artifactsX24-openshell-artifacts: OpenShell artifactsDo the OpenShell parts that S07-egress-gateway, S09-policy-credentials-audit and S10-tech-stack build on exist in the assumed form, under a permissive license, at a version that can be pinned: the networkpolicies sche…). It is tested before the
boundary check relies on it.
Refused keys
Section titled “Refused keys”Any other OpenShell key is refused at load, with an error that names it (NFR06-explained-refusalsNFR06-explained-refusals: OperabilityEvery refusal names the rule that caused it and how to change it.). It is never ignored, so no rule is weaker than written. Examples:
- the other top-level keys,
filesystem_policyandnetwork_middlewares; - the endpoint fields
credential_binding,mcpandallowed_ips.
allowed_ips would allow destinations by raw IP address
(SEC05-default-denySEC05-default-deny: Default-deny egress, enforced on the hostOnly allowlisted hostnames are reachable.).
Strings
Section titled “Strings”Every rule name, host, path and method must:
- be ASCII;
- have no control bytes;
- be within a length cap fixed in code.
Otherwise the file is refused at load. The prover models ASCII values only, and its output repeats these strings (X24-openshell-artifactsX24-openshell-artifacts: OpenShell artifactsDo the OpenShell parts that S07-egress-gateway, S09-policy-credentials-audit and S10-tech-stack build on exist in the assumed form, under a permissive license, at a version that can be pinned: the networkpolicies sche…).
Loading
Section titled “Loading”wb-hostd loads each file with its own Go code
(internal/policy/policyfile). A repository’s file is repository
data, so every byte is treated as hostile. The prover runs confined
because it parses the same bytes (S09-04-boundary-checkS09-04-boundary-check: Boundary CheckThe check of a project's policy against the boundary policy with OpenShell's prover, and which policy it checks when.). The loader
stays in wb-hostd because it is Go, bounded and fuzzed
(FuzzLoadPolicy, C03-policy-and-approvalsC03-policy-and-approvals: Policy and ApprovalsThe test cases for network policy: loading it, combining the policies of the projects in one VM, modes per host, profile parts, learn mode, and the approval flow.).
- A file past OpenShell’s own bounds is refused with
policy-yaml-bound: 4 MiB, checked before parsing, depth 64 and 100,000 nodes (X24-openshell-artifactsX24-openshell-artifacts: OpenShell artifactsDo the OpenShell parts that S07-egress-gateway, S09-policy-credentials-audit and S10-tech-stack build on exist in the assumed form, under a permissive license, at a version that can be pinned: the networkpolicies sche…). The depth and nodes are counted on the node tree, so the decoder builds the whole tree of a file within 4 MiB first. - An integer is decimal with no leading zero, because YAML reads
0443as octal. A panic in the loader refuses the file withpolicy-loader-panic. - The YAML is decoded into a node tree first, which keeps an alias as
a pointer and expands nothing. An anchor, an alias, a merge key, a
tag outside YAML’s core schema, a duplicate key, a key that isn’t a
string and a second document are refused with
policy-yaml-form. - Every level is then checked against its closed key list before any
value is read:
policy-key-unknown,policy-key-refusedandpolicy-key-unsupported.versionis 1 (policy-version). - Each refusal names its rule, the file, the line and key path, and the value at fault, escaped (NFR06-explained-refusalsNFR06-explained-refusals: OperabilityEvery refusal names the rule that caused it and how to change it.). One load reports the first refusal of each rule, at most 16.
Pass, raw TCP, and audit entries
Section titled “Pass, raw TCP, and audit entries”Pass hosts
Section titled “Pass hosts”Only the global and project network policy files can put a host in pass mode, never repository configuration. Each pass entry names one exact host, and needs a reason. The reason follows the string rules (“Strings”).
These are refused at load:
- a wildcard entry;
- an entry for a host with a credential binding;
- an entry for a host a built-in profile covers.
Adding a pass host is a Device Config State Change (5019) event. S07-07-hosts-and-modesS07-07-hosts-and-modes: Hosts and ModesHow wb-proxyd binds a stream to its name, which upstream addresses it refuses, and the inspect, pass and audit modes., “Modes, per host”, has the rules.
Raw TCP entries
Section titled “Raw TCP entries”A raw TCP entry names one exact host and one port, for a stream that is neither TLS nor HTTP. The rules of a pass host apply to it, on its host and port. S07-15-non-http-streamsS07-15-non-http-streams: Non-HTTP StreamsHow wb-proxyd checks the protocol of each stream, and what it does with SSH, other protocols and raw TCP. has the rules.
Audit hosts
Section titled “Audit hosts”Only the global and project network policy files can put a host and
port in audit.
An audit endpoint on a host with a credential binding, or on a host a
built-in profile covers, is refused (SEC06-repo-writesSEC06-repo-writes: Repository-scoped writesGit pushes and repository-mutating API calls are allowed only for the repositories of the projects that have a session in the VM.):
- at load;
- at every recompute;
- when a binding is added later.
S07-07-hosts-and-modesS07-07-hosts-and-modes: Hosts and ModesHow wb-proxyd binds a stream to its name, which upstream addresses it refuses, and the inspect, pass and audit modes., “Modes, per host”, has the rules.
Policy as the prover sees it
Section titled “Policy as the prover sees it”What the prover sees
Section titled “What the prover sees”The document Wraith Box writes for the prover allows at least what
wb-proxyd enforces, never less.
- A built-in GraphQL rule is written as a REST rule. It allows
POSTto its GraphQL path on its host, which is wider than the rule (S09-04-boundary-checkS09-04-boundary-check: Boundary CheckThe check of a project's policy against the boundary policy with OpenShell's prover, and which policy it checks when., “Built-in profiles in the check”). - A host in pass mode is written as an L4 endpoint, with no
protocoland no rules, whatever rules the file gives it. So the boundary must allow L4 to that host. - A raw TCP entry is written as an L4 endpoint for its host and port. So the boundary must allow L4 to that host and port.
The prover can’t see the extension keys. Wraith Box’s own Go check compares them with the boundary’s extension part:
- each pass host must be a pass host in the boundary;
- each raw TCP entry must be a raw TCP entry in the boundary;
- dependency-gate thresholds can’t be looser;
- the wildcard budget can’t be larger.
Any mismatch refuses the policy.
Audit as the whole host
Section titled “Audit as the whole host”audit lets every request through, and only logs a violation
(S07-07-hosts-and-modesS07-07-hosts-and-modes: Hosts and ModesHow wb-proxyd binds a stream to its name, which upstream addresses it refuses, and the inspect, pass and audit modes., “Modes, per host”). So a host and port whose
mode resolves to audit (S09-02-precedenceS09-02-precedence: PrecedenceHow the policy sources merge, how the mode of each host and port resolves, and how the merge works for a VM with more than one project., “Mode per host and port”) is written as the whole host on that port.
The projected endpoint is built from the host and the port only:
protocol: restandenforcement: enforce;- one rule,
allow: { method: "*", path: "/**" }; - in an entry whose
binariesispath: "/**".
These are dropped: the endpoint-level path, access and rules, the
entry’s binaries, and the deny_rules of every endpoint on that host
and port.
An endpoint with ports is written once for each port, each in the
mode its host and port resolves to. A host and port that resolves to
enforce is written with its rules.
The boundary must then allow every method and path on that host and port. A boundary that allows less refuses the policy, with a counterexample that names the host.
The prover’s reading of method: "*" wasn’t tested
(X24-openshell-artifactsX24-openshell-artifacts: OpenShell artifactsDo the OpenShell parts that S07-egress-gateway, S09-policy-credentials-audit and S10-tech-stack build on exist in the assumed form, under a permissive license, at a version that can be pinned: the networkpolicies sche…). It is tested before the boundary check
relies on it.
Program narrowing
Section titled “Program narrowing”binaries entries match the program label from the guest
(S13-guest-confinementS13-guest-confinement: Guest ConfinementControls inside the guest that narrow what a project user's processes can do, and tell the host which program opened each connection.). Until spike X14-flow-attributionX14-flow-attribution: Guest flow attributionA Network Extension transparent proxy in a macOS guest (S13-guest-confinement): can it be approved during the image build without MDM? has delivered
labels, binaries does not narrow a rule.
- Each rule lists the universal entry
path: "/**". - Policy that names programs is rejected at load, with an error saying why (NFR06-explained-refusalsNFR06-explained-refusals: OperabilityEvery refusal names the rule that caused it and how to change it.). So no rule is silently weaker than written.
OpenShell’s policy engine has the same mode, switched by its
require_binary_identity setting. Its isolation backends must resolve
binary identity, though (X24-openshell-artifactsX24-openshell-artifacts: OpenShell artifactsDo the OpenShell parts that S07-egress-gateway, S09-policy-credentials-audit and S10-tech-stack build on exist in the assumed form, under a permissive license, at a version that can be pinned: the networkpolicies sche…).
The prover checks each policy both with and without binary identity.
With it, the prover reads /** as every program
(X24-openshell-artifactsX24-openshell-artifacts: OpenShell artifactsDo the OpenShell parts that S07-egress-gateway, S09-policy-credentials-audit and S10-tech-stack build on exist in the assumed form, under a permissive license, at a version that can be pinned: the networkpolicies sche…).
Project narrowing
Section titled “Project narrowing”A project’s rules and bindings apply to the whole VM while the project has a session in it (S07-01-per-vm-policyS07-01-per-vm-policy: Enforced per VMWhy the VM is the unit the gateway enforces, how the policies of its projects combine, and what happens when they conflict or change.).
X14-flow-attributionX14-flow-attribution: Guest flow attributionA Network Extension transparent proxy in a macOS guest (S13-guest-confinement): can it be approved during the image build without MDM? may deliver labels that name the project user (S13-guest-confinementS13-guest-confinement: Guest ConfinementControls inside the guest that narrow what a project user's processes can do, and tell the host which program opened each connection.). Once it does, those labels may narrow a project’s rules to its own flows. The rules of program narrowing then apply: a missing or malformed label matches no narrowed rule.
Until then nothing is narrowed by project.
The effective policy on the wire
Section titled “The effective policy on the wire”wb-hostd merges the files into one effective policy per VM
(S09-02-precedenceS09-02-precedence: PrecedenceHow the policy sources merge, how the mode of each host and port resolves, and how the merge works for a VM with more than one project.). It reaches wb-netd and wb-proxyd as a
wraithbox.policy.v1.EffectivePolicy message
(proto/wraithbox/policy/v1/policy.proto).
- Each rule names its source: built-in, global, project, repository or approval.
- Hosts are in canonical form, and path patterns as written.
- The proto file names a bound for every list and string.
- The receiver checks the message before it uses it. A message past a bound, or one that breaks a rule of this page, is refused whole and never repaired. The refusal is logged with its rule (NFR06-explained-refusalsNFR06-explained-refusals: OperabilityEvery refusal names the rule that caused it and how to change it.).
Decisions
Section titled “Decisions”Reuse OpenShell’s network policy schema
Section titled “Reuse OpenShell’s network policy schema”- Why: OpenShell’s prover can then check Wraith Box policy, and users get one policy language for both tools.
Only global and project files set pass hosts
Section titled “Only global and project files set pass hosts”- Decided: I40I40 (closed): S03-requirements, S07-egress-gateway: record learn mode and pass mode as SEC05-default-deny exceptionsSEC05-default-deny is "default-deny egress", and AGENTS.md says an S control is never weakened. (B40-learn-pass-modesB40-learn-pass-modes: May learn mode and pass mode open holes in default-deny egress?Learn mode should collect unknown names and refuse them, so SEC05-default-deny is unchanged.).
Raw TCP entries follow the pass-host rules
Section titled “Raw TCP entries follow the pass-host rules”- Decided: I47I47 (closed): S07-egress-gateway: non-HTTP streams, SSH remotes and ECHS07-egress-gateway describes TLS and HTTP. (B47-non-http-streamsB47-non-http-streams: What does the gateway do with a connection that isn't TLS or HTTP?Reset it and audit the rule, unless policy names that host and port for raw TCP.).
audit only from global and project files, never on guarded hosts
Section titled “audit only from global and project files, never on guarded hosts”audit is projected as the whole host
Section titled “audit is projected as the whole host”Status: Draft