Skip to content

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.

The sources, in order:

  1. built-in defaults;
  2. global;
  3. project;
  4. repository configuration (with config_trust);
  5. session approvals.

wb policy explain shows the effective value and its source.

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.

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:

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.

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 enforce on a host and port, from any source, puts that host and port in enforce.
  • An endpoint with no enforcement field counts as enforce.
  • An endpoint counts on every host its host pattern matches. So a wildcard endpoint in enforce keeps a matching exact host in enforce, which fails closed.
  • A host and port resolves to audit only when every endpoint on it is in audit.

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”).

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.

wb policy explain shows, for each rule and each credential binding:

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”

Status: Draft