S09-02 - Precedence
Purpose: How 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.
Design
Section titled “Design”Precedence
Section titled “Precedence”The sources, in order:
- built-in defaults;
- global;
- project;
- repository configuration (with
config_trust); - session approvals.
wb policy explain shows the effective value and its source.
Network rules merge as a union
Section titled “Network rules merge as a union”Rules are keyed by source and rule name. So a later source adds rules, and never replaces one. A rule in user or repository policy with the name of a built-in profile’s rule is a load error.
Built-in denies apply whatever the source of the allow. They are evaluated before any allow.
User and repository policy can’t change a built-in host’s kind, mode or rules. A user or repository rule on a built-in host is a load error when its method and path pattern can match a request to that host’s GraphQL path after normalization. That covers:
- a path prefix or glob that covers it;
- a wildcard method;
- a trailing slash;
- percent-encoding;
- the letter case of the path, as in
/GraphQL. A host may route it to the same handler, and the request-time match is case-sensitive.
The built-in GraphQL operation filter applies whatever the source of the allow.
The global and project policy can make one change to a built-in profile: turn a part of it off (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”). This lock holds whatever parts are on. So does the removal of guest credentials in the places a profile names.
The OAuth token paths
Section titled “The OAuth token paths”A user or repository rule is a load error when the wb-proxyd matcher
would let it allow a canonical POST on a model API host
(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., “model API”) to a path that starts with the
string /v1/oauth/token. Examples are /v1/oauth/token and
/v1/oauth/token/revoke. It covers rules in the global and project policy, and in
repository configuration with config_trust. The check counts, for
example:
- a path prefix or glob that covers such a path;
- a wildcard method, and the method compared without regard to case;
- an access preset, or an endpoint without method and path rules, that allows a write method;
- a trailing slash;
- percent-encoding;
- the letter case of the path, as in
/V1/OAuth/Token; - a host pattern that matches a model API host in canonical form, lowercase and without a trailing dot (S07-06-name-mappingS07-06-name-mapping: Name MappingHow wb-proxyd keeps its own checked copy of the names wb-netd gave synthetic addresses: name reports, releases, replay, lifetime, the second count of the wildcard budget, and the copy wb-hostd keeps.), a wildcard included;
- any port.
POST is the method that matters. OAuth 2 requires POST for a token
request (RFC 6749, section 3.2). The code exchange, the refresh, and
the revocation that X01-model-credentialX01-model-credential: Model credential via the proxyDoes Claude Code work with a placeholder credential while wb-proxyd injects the real one, for each supported authentication mode, including token refresh? saw were all POST. So a rule that allows only
GET /v1/oauth/token still loads, and so does a rule that allows
POST /v1/oauth/hello.
The refusal names the rule model-token-path, the policy file, and the
rule’s name (NFR06-explained-refusalsNFR06-explained-refusals: OperabilityEvery refusal names the rule that caused it and how to change it.). It tells the user that the model
credential comes from claude setup-token on the host and is stored
with wb cred set (S09-05-credentialsS09-05-credentials: CredentialsHow credentials are stored and bound to requests, and how the model credential reaches the model API without entering the guest., “Long-lived token”).
The model API profile doesn’t allow these paths, so a login started in
the guest fails at its token request (S14-04-commands-and-endpointsS14-04-commands-and-endpoints: Commands and EndpointsWhich permission mode Claude Code runs in, the commands that don't work in a guest, the guest instructions that explain the guest's limits to Claude Code, and the endpoints Claude Code in the guest may reach.,
“Browser login”). Without this check a policy rule could allow them. The
guest’s login would then complete and leave the OAuth tokens in the
guest. With no unlocked Keychain, Claude Code writes them in plaintext
to ~/.claude/.credentials.json (X01-model-credentialX01-model-credential: Model credential via the proxyDoes Claude Code work with a placeholder credential while wb-proxyd injects the real one, for each supported authentication mode, including token refresh?, “Without a
Keychain”). This check enforces
SEC04-no-guest-secretsSEC04-no-guest-secrets: No secrets in the guestThis includes the model credential. for the model credential’s OAuth tokens. Like the
GraphQL lock, it holds whatever profile parts are on.
Other Anthropic hosts, such as claude.ai and console.anthropic.com,
aren’t model API hosts. A rule on a token path there still loads.
Mode per host and port
Section titled “Mode per host and port”enforcement is resolved for each host and port over the whole union,
not per endpoint. The union is:
- the built-in profiles;
- the global, project and repository policy;
- the approved rules;
- every endpoint within one file;
- every project with a session in the VM (“Per VM”).
The rules of the resolution:
- Any endpoint in
enforceon a host and port, from any source, puts that host and port inenforce. - An endpoint with no
enforcementfield counts asenforce. - An endpoint counts on every host its host pattern matches. So a
wildcard endpoint in
enforcekeeps a matching exact host inenforce, which fails closed. - A host and port resolves to
auditonly when every endpoint on it is inaudit.
wb-proxyd applies the resolved mode to every request on that host
and port. It never applies the enforcement field of the endpoint
whose rule matched. The boundary check projects the same mode
(S09-01-policy-filesS09-01-policy-files: Policy FilesWhere policy is written, the network policy schema Wraith Box accepts, how the prover sees it, and narrowing by program and project., “Audit as the whole host”).
A change that moves a host and port from enforce to audit widens,
whatever removal caused 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., “Policy changes while
sessions run”, “Session end”).
Per VM
Section titled “Per VM”The host enforces the merge for a VM, not for a project. The project sources are those of every project with a session in the VM.
- Limits take the strictest value among them.
- The mode of a host and port resolves over every source. So
enforcewins overaudit(“Mode per host and port”). - A conflict between projects refuses the joining session (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.). Examples are a host in pass mode for one project and inspected or bound for another, or two bindings for one host and path.
- The extension check (S09-01-policy-filesS09-01-policy-files: Policy FilesWhere policy is written, the network policy schema Wraith Box accepts, how the prover sees it, and narrowing by program and project., “What the prover sees”) runs over the union at each recompute.
wb policy explain shows, for each rule and each credential binding:
- the project it comes from;
- the projects whose sessions can reach it now. Those are all the projects with a session in the same VM (T11-shared-vm-grantsT11-shared-vm-grants: Projects in one VM share network grantsThe host sees one guest address per VM, and can't tell which project user, session or program opened a connection.).
Decisions
Section titled “Decisions”The mode resolves per host and port, over the whole union
Section titled “The mode resolves per host and port, over the whole union”Policy can’t allow the OAuth token paths
Section titled “Policy can’t allow the OAuth token paths”- Decided: I259I259 (closed): S09-policy-credentials-audit: user and repository rules can allow the OAuth token pathsFollow-up from the review of PR #258 (#256), finding 1.. A built-in deny on these paths, evaluated before any allow, can be added on top later.
Status: Draft