Skip to content

fix(policy): let host endpoints take precedence over hostless allowed_ips rules - #5088

Draft
purp wants to merge 5 commits into
ai-openshell:mainfrom
purp:fix/4662-endpoint-host-precedence/purp
Draft

purp wants to merge 5 commits into
ai-openshell:mainfrom
purp:fix/4662-endpoint-host-precedence/purp

Conversation

@purp

@purp purp commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A hostless allowed_ips rule can coexist with a provider endpoint that pins a host inside that range. The host endpoint supplies the connection configuration. More selective endpoints must remain at least as restrictive as every broader endpoint they override, for both host and path precedence.

Related Issue

Closes #4662

Changes

  • Validate IP containment, TLS, inspection, enforcement, body limits, encoded-slash handling, MCP tool-name validation, and the uninspected-credential guard on overrides.
  • Require the same parser when the broader endpoint inspects requests, including preserving GraphQL-over-WebSocket classification. MCP versions and persisted-query modes/registries must agree. Different protocols can still use disjoint paths.
  • Require matching signing and credential rewrite settings: these transformations currently apply to every forwarded request, including requests admitted by another endpoint. Credential grants retain their existing authority checks.
  • Run the same ambiguity validation on local YAML files, strings, and reloads. Rejected reloads preserve the active generation. Diagnostics remain bounded and redact authored values.
  • Share IP/CIDR parsing between the validator and runtime, including whitespace handling.
  • Document that host precedence happens at connection time, before path selection. An uncovered path on the hosted connection is denied. Binaries filter matches but do not rank them; ambiguity validation checks pairs regardless of binaries. Allow/deny rules continue to union, with deny winning.

Release Notes

Pinned host endpoints can overlap a hostless IP allowlist when their settings preserve its restrictions. More specific paths must also preserve broader restrictions. Overlapping parser changes, signing changes, or credential rewrite changes are rejected; use disjoint paths for different protocols.

Testing

  • Regression tests added for host and path overrides in both endpoint orders, protocol-specific inspection, credential transformations, parser options, local ingress, and rejected reloads.
  • Rust syntax parsed for all six changed source files with the official tree-sitter Rust grammar (syntax only; no compilation or type checking).
  • Documentation navigation, changed TOML/lockfiles, the updated GraphQL YAML example, and git diff --check pass.
  • Current Rust unit tests, rustfmt, Clippy, and Docker e2e remain pending: this environment has neither Rust nor Docker, and the pinned Rust installation failed because distribution downloads are denied. Earlier PR test results predate this review follow-up.

Checklist

  • Conventional Commit with DCO sign-off and cryptographic signature.
  • Published docs, RFC clarification, and policy-authoring skill updated.

purp added 4 commits October 30, 2026 17:00
A hostless allowed_ips rule on the same port as a host-naming endpoint
was rejected as ambiguous. Rank endpoints by host specificity instead:
an endpoint that names a host supplies connection and request metadata
for requests it matches, and hostless rules apply otherwise. Endpoints of
equal rank must still agree. Allow and deny decisions still union over
every matching policy.

Closes ai-openshell#4662

Signed-off-by: Jim Meyer <[email protected]>
Explain that an endpoint naming a host takes precedence over a hostless
rule, and resolve RFC 0005 open question 1.

Signed-off-by: Jim Meyer <[email protected]>
…hostless rules

An endpoint that names a host takes precedence over an overlapping hostless
endpoint, so it must not loosen the hostless rule. Policy load now rejects a
host-naming endpoint whose allowed_ips fall outside the hostless list, or that
drops TLS termination, L7 inspection, or enforcement the hostless rule applies.
Parser choice, credentials, and request rewriting stay with the host endpoint.

Signed-off-by: Jim Meyer <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Oct 31, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@purp
purp requested review from johntmyers and pimlock and removed request for pimlock October 31, 2026 00:15
@purp

purp commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

Keeping this in draft while I walk through it slowly. It's my first time touching policy so I'm being a bit more cautious. Feel free to leave comments and questions now or wait for later.

@purp purp left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. Giving a host-naming endpoint precedence over a hostless allowed_ips endpoint is the right direction for #4662, and the Rego change is small and correct for validated policies. Policies without hostless endpoints behave exactly as on main. The validator's "the host endpoint is at least as restrictive" argument has gaps, though. Several pairs that main rejected now pass, and the result at runtime is looser than either endpoint says.

I found these by reading code paths end to end; I haven't run them as tests.

Blocking

1. A different L7 parser drops the hostless endpoint's protocol-specific deny rules.
looser_than_hostless_conflicts returns early when the two endpoints use different protocols (ambiguity.rs:270). The relay only parses GraphQL or JSON-RPC when the selected config uses that protocol (l7/relay.rs:1276, :1304), so request.graphql / request.jsonrpc are absent and the hostless deny rules can't match.

# hostless
port: 443
allowed_ips: [8.0.0.0/8]
protocol: mcp
enforcement: enforce
deny_rules: [{ method: tools/call }]
# hosted
host: api.example.com
port: 443
allowed_ips: [8.8.8.8]
protocol: rest
enforcement: enforce
access: full

This pair validates, and tools/call to api.example.com is forwarded, which breaks "a deny on any matching endpoint wins". A related gap: websocket_graphql_policy isn't compared on the hosted-vs-hostless path, so a hostless websocket deny on operation_type: mutation is lost behind a plain hosted websocket endpoint.

2. The host endpoint's credential settings apply to requests only the hostless rule allows.
credential_signing, request_body_credential_rewrite, and websocket_credential_rewrite come from the selected config and apply to every forwarded request (l7/relay.rs:742-749). Nothing checks that the host endpoint itself admitted the request. These fields are compared only in the equal-specificity branch (ambiguity.rs:386-404). Example: a Bedrock host with rest, credential_signing: sigv4, and rules allowing only POST /model/x/invoke, beside a hostless rest endpoint with access: full that covers AWS. Any method or path to that host then gets re-signed with real credentials. main rejects this pair as a credential_signing mismatch. Token grants already avoid this through allowed_token_grant_owners. Signing and rewrites should work the same way, or be required to match.

3. Local-file policies get the new precedence without the validator.
find_endpoint_ambiguities runs only in from_proto_with_pid (opa.rs:486). from_files*, from_strings, and reload go through preprocess_yaml_data and skip it, and the supervisor's local-override load uses that path (openshell-supervisor/src/lib.rs:2821). The new Rego shadowing applies anyway:

  • Hostless allowed_ips: [8.8.0.0/16] on 443 plus a plain internal.corp:443: the config list is now empty, validation falls back to ExactDeclaredHost (proxy/destination.rs:118), and RFC 1918 resolutions are allowed. On main the hostless list applied.
  • Hostless protocol: rest with deny_rules plus a plain api.example.com:443: no L7 config is selected, so the connection is relayed at L4 and deny_request never runs.

The missing validation predates this PR, but this PR is what makes it matter. Either run the ambiguity check in the file path too, or have Rego shadow a hostless config only when the host endpoint is contained in it.

Non-blocking

  • protocol: sql on the host endpoint counts as L7 but is passthrough (l7/relay.rs:1108). Beside an L7 hostless endpoint in audit mode (the default), it drops authority checks, path canonicalization, malformed-body hard denies, and the uninspected-credential guard. Consider rejecting it when the hostless endpoint is L7.
  • Path is ignored when choosing the winner. _hosted_endpoint_matches uses endpoint_matches_request, which compares only host and port (sandbox-policy.rego:1077). A host endpoint with path: /v1/** shadows the hostless config for every path on that host, so /v2 now gets a 403 where main served it. This fails closed, but the docs should say so, or the match should consider path.
  • Fields not compared: allow_uninspected_credentials (already missing in the equal-specificity branch too), mcp.versions, and persisted queries.
  • Parser drift: parse_allowed_ip trims whitespace, but the runtime's parse_allowed_ips (proxy.rs:4762) doesn't. That fails closed today, but a shared helper in openshell-core::net would keep the validator and the runtime in step.
  • Cross-policy shadowing: this is safe only because the validator ignores binaries and checks every pair. A note at sandbox-policy.rego:956 would stop a future binary-aware validator from quietly breaking that.

Scope

The minimal fix for #4662 is the Rego precedence rule, the host-rank split in the validator, and the allowed_ips containment check. That is about 40 lines plus focused tests. The rest of the strictness checks are reasonable hardening rather than issue scope. Given items 1 and 2, though, I'd rather see that matrix completed (same protocol when the hostless endpoint has protocol-specific denies, and credential settings either matching or scoped to admitted requests) than trimmed.

@purp purp added area:runtime Sandbox execution, isolation, supervision, policy enforcement, networking, and provider lifecycle. topic:documentation Architecture docs, READMEs, project website updates, and automated documentation generation. topic:policy Policy authoring, validation, proving, distribution, enforcement, ergonomics, and hardening. topic:security Vulnerability management, security analysis/auditing, bypass detection, and abuse prevention. labels Nov 15, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:runtime Sandbox execution, isolation, supervision, policy enforcement, networking, and provider lifecycle. topic:documentation Architecture docs, READMEs, project website updates, and automated documentation generation. topic:policy Policy authoring, validation, proving, distribution, enforcement, ergonomics, and hardening. topic:security Vulnerability management, security analysis/auditing, bypass detection, and abuse prevention.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hostless web egress conflicts with a pinned provider endpoint

1 participant