Repository navigation
Conversation
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]>
Signed-off-by: Jim Meyer <[email protected]>
|
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. |
|
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
left a comment
There was a problem hiding this comment.
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: fullThis 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 plaininternal.corp:443: the config list is now empty, validation falls back toExactDeclaredHost(proxy/destination.rs:118), and RFC 1918 resolutions are allowed. Onmainthe hostless list applied. - Hostless
protocol: restwithdeny_rulesplus a plainapi.example.com:443: no L7 config is selected, so the connection is relayed at L4 anddeny_requestnever 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: sqlon 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_matchesusesendpoint_matches_request, which compares only host and port (sandbox-policy.rego:1077). A host endpoint withpath: /v1/**shadows the hostless config for every path on that host, so/v2now gets a 403 wheremainserved 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_iptrims whitespace, but the runtime'sparse_allowed_ips(proxy.rs:4762) doesn't. That fails closed today, but a shared helper inopenshell-core::netwould 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:956would 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.
Signed-off-by: Jim Meyer <[email protected]>
Summary
A hostless
allowed_ipsrule 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
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
git diff --checkpass.Checklist