Repository navigation
Description
Problem Statement
The policy engine's endpoints[].host field only supports case-insensitive exact matching (sandbox-policy.rego:98). There is no way to express "allow all subdomains of example.com" without listing every subdomain individually. This is a common need — CDNs, API gateways, and cloud services often use many subdomains under a single root.
Similarly, endpoints[].port is a single uint32 (sandbox.proto:59). Services that listen on multiple ports (e.g., HTTP + HTTPS, or a database with primary + read replica ports) require duplicating the entire endpoint block for each port.
Proposed Design
1. Host Wildcards
Add glob-style wildcard support to endpoints[].host, evaluated via glob.match in Rego (same engine already used for binary paths and L7 URL paths).
Supported patterns:
| Pattern | Matches | Does not match |
|---|---|---|
*.example.com |
api.example.com, cdn.example.com |
example.com, deep.sub.example.com |
**.example.com |
api.example.com, deep.sub.example.com |
example.com |
example.com |
example.com (exact, unchanged behavior) |
api.example.com |
Use "." as the glob delimiter (instead of "/" used for paths) so * matches a single DNS label and ** matches across labels.
Rego changes — add a third endpoint_allowed clause:
# Endpoint matching: glob host pattern + port.
endpoint_allowed(policy, network) if {
some endpoint
endpoint := policy.endpoints[_]
contains(endpoint.host, "*")
glob.match(endpoint.host, ["."], lower(network.host))
endpoint.port == network.port
}The existing exact-match clause (sandbox-policy.rego:95-100) stays unchanged — no wildcards means exact match, same as binary path matching.
Proto: No change needed — host is already a string.
2. Multi-Port Endpoints
Allow port to accept either a single integer or an array of integers in the YAML policy format while keeping the proto backwards compatible.
Option: keep proto as uint32 port + add repeated uint32 ports
message NetworkEndpoint {
string host = 1;
uint32 port = 2; // Single port (existing, backwards compat)
repeated uint32 ports = 9; // Multiple ports (new)
// ... rest unchanged
}At validation/normalization time:
- If
portis set andportsis empty → treat asports: [port] - If
portsis non-empty andportis 0 → useportsas-is - If both are set → reject with a validation error (mutually exclusive, same pattern as
accessvsrules)
YAML surface (handled by serde deserialization):
# Single port (existing syntax, still works)
endpoints:
- host: api.example.com
port: 443
# Multiple ports (new syntax)
endpoints:
- host: api.example.com
ports: [443, 8443]Rego changes — iterate over normalized ports array:
endpoint_allowed(policy, network) if {
some endpoint
endpoint := policy.endpoints[_]
lower(endpoint.host) == lower(network.host)
endpoint.ports[_] == network.port
}Normalization (port → ports array) should happen in Rust before passing data to the Rego engine, so Rego always sees ports as an array.
Alternatives Considered
Host wildcards via regex: Rejected — regex is more powerful than needed and inconsistent with the rest of the policy engine which uses globs everywhere. Glob with . delimiter maps naturally to DNS labels.
Host wildcards via a separate host_pattern field: Adds unnecessary surface area. The contains(host, "*") detection pattern is already established for binary paths and works well.
Multi-port via string port with comma syntax (e.g., "443,8443"): Fragile, requires string parsing, and doesn't compose well with proto typing. A proper repeated uint32 is cleaner.
Multi-port via port ranges (e.g., 443-8443): Over-broad — opens all intermediate ports. Explicit enumeration is safer for a security-critical field.
Agent Investigation
Current implementation references:
- Host matching (exact only):
crates/openshell-sandbox/data/sandbox-policy.rego:95-100 - Hostless endpoint matching:
sandbox-policy.rego:105-111 - Port field proto definition:
proto/sandbox.proto:59—uint32 port = 2 - Glob matching precedent (binary paths):
sandbox-policy.rego:132-141— usescontains(b.path, "*")to detect glob patterns, thenglob.match(pattern, ["/"], path) - Glob matching precedent (L7 URL paths):
sandbox-policy.rego:211-215 - Endpoint matching test coverage:
crates/openshell-sandbox/src/opa.rs:825-842(case-insensitive host),opa.rs:1823-1841(hostless endpoints) - Policy validation:
crates/openshell-policy/src/lib.rs:461-535
The glob infrastructure is already in the Rego policy — this feature extends the same pattern to a new field. The multi-port change is a normalization concern handled in Rust before Rego evaluation.
Activity
johntmyers commentedon Mar 16, 2026
Implementation Plan
Issue type:
featComplexity: Medium
Confidence: High — both features follow existing patterns (binary glob matching, access preset normalization)
Summary
Add glob-style host wildcards (
*.example.com) toendpoints[].hostusing OPA'sglob.matchwith.as delimiter, and add aportsarray field for multi-port endpoints with backwards-compatible normalization from the existingportfield. The Rego policy already demonstrates both theglob.matchandcontains(x, "*")detection patterns for binary paths — this extends those patterns to endpoint matching.Scope
proto/sandbox.proto: Addrepeated uint32 ports = 9toNetworkEndpointcrates/openshell-policy/src/lib.rs: Addportsto YAML serde types, normalization into_proto()/from_proto(), validation for ports and host wildcard patternscrates/openshell-sandbox/data/sandbox-policy.rego: Splitendpoint_allowedinto exact/glob host rules, changeendpoint.port→endpoint.ports[_]in all rules, add glob host matching toendpoint_matches_requestcrates/openshell-sandbox/src/opa.rs: Update bothproto_to_opa_data_json()(proto path) andpreprocess_yaml_data()(YAML path) to emitportsarray; deprecate or fixreload()bypass; add ~18 new testscrates/openshell-sandbox/src/l7/mod.rs: Updatevalidate_l7_policies()to readportsarray and validate wildcard hostscrates/openshell-sandbox/src/mechanistic_mapper.rs: Emitportsfield in generatedNetworkEndpointproposalsarchitecture/security-policy.md: Document new features.agents/skills/generate-sandbox-policy/SKILL.md: Update examples and schema referenceCritical: Two Independent OPA Data Conversion Paths
There is no single choke point for policy-to-OPA-JSON conversion. The
port→portsnormalization must happen in two places:Proto path —
proto_to_opa_data_json()atopa.rs:592manually constructs{"host": e.host, "port": e.port}viaserde_json::json!(). Used by the gateway (gRPC initial load viafrom_proto(), hot-reload viareload_from_proto(), disk discovery).YAML path —
preprocess_yaml_data()atopa.rs:516parses YAML viaserde_yaml::from_strintoserde_json::Value. The port value passes through as-is from the YAML. Used byfrom_files()andfrom_strings()(local dev overrides, all test helpers).Both paths converge on the shared
validate_l7_policies()andexpand_access_presets()pipeline before loading into regorus. The normalization for each path:proto_to_opa_data_json()to emit"ports": [e.port](ore.portsif populated) instead of"port": e.port.preprocess_yaml_data()after serde_yaml parse and before validation — walk each endpoint and convert"port": N→"ports": [N].There is also a raw bypass —
OpaEngine::reload()atopa.rs:278loads YAML directly into regorus viaregorus::Value::from_yaml_str(), skipping all preprocessing, L7 validation, and preset expansion. Currently only called from one test (reload_replaces_policyatopa.rs:926). This must be updated to route throughpreprocess_yaml_data()or be removed to prevent future divergence.Implementation Steps
repeated uint32 ports = 9to proto, addportsto YAML serde type, implementport↔portsnormalization into_proto()/from_proto(), add validation. Existing tests should not break (proto default forrepeatedis[]).proto_to_opa_data_json()to emitportsarray. Addport→portsnormalization step topreprocess_yaml_data(). Fix or removereload()bypass. These changes and Step 3 must land together since Rego will referenceendpoint.ports[_].endpoint.port == network.port→endpoint.ports[_] == network.portin allendpoint_allowedandendpoint_matches_requestrules. Coordinated with Step 2 (same commit). Add multi-port tests.endpoint_allowedandendpoint_matches_requestclauses usingcontains(endpoint.host, "*")guard +glob.match(lower(endpoint.host), ["."], lower(network.host)). Add host wildcard tests.validate_l7_policies()forportsarray and wildcard host validation (reject bare*, require*.prefix, warn on shallow patterns like*.com). Update mechanistic mapper.architecture/security-policy.mdandgenerate-sandbox-policyskill.Test Plan
crates/openshell-sandbox/src/opa.rs):multi_port_endpoint_matches_first_port,multi_port_endpoint_matches_second_port,multi_port_endpoint_rejects_unlisted_port,single_port_backwards_compat,l7_multi_port_request_evaluation,hostless_endpoint_multi_portwildcard_host_matches_subdomain,wildcard_host_rejects_deep_subdomain,wildcard_host_rejects_exact_domain,wildcard_host_case_insensitive,wildcard_host_plus_port,wildcard_host_l7_rules_apply,wildcard_host_l7_endpoint_config_returnedwildcard_host_multi_portcrates/openshell-policy/src/lib.rs):parse_ports_array,parse_single_port_normalized_to_ports,round_trip_preserves_multi_port,validate_rejects_bare_wildcard_host,validate_accepts_valid_wildcardcrates/openshell-sandbox/src/l7/mod.rs):validate_ports_array_rest_443_warns,validate_wildcard_host_star_only_errorregorus)e2e/expected; proxy behavior is unchanged at the transport layerRisks & Open Questions
regorusglob.match delimiter behavior — Must verify thatglob.match("*.example.com", ["."], "api.example.com")works correctly inregorus. Theglob.matchbuilt-in is already used for binary paths with"/"but has not been tested with".". Highest-risk item — mitigated by comprehensive tests in Step 4.portsarray + Rego readingendpoint.ports[_]) must land in the same commit. If only one side changes, all policy evaluation breaks.proto_to_opa_data_json()andpreprocess_yaml_data()must both produce the sameportsarray format. The sharedvalidate_l7_policies()downstream will catch structural mismatches, but a normalization bug in one path could slip through if tests only exercise the other.reload()bypass — Currently test-only, but a latent divergence risk. Must be fixed as part of this work.*.comor*.*are dangerous. Validation rejects bare*and requires*.prefix; warns on patterns with ≤2 labels.allowed_ips+ wildcards interaction — Works naturally: OPA grants the CONNECT based on wildcard host match, then the proxy validates resolved IPs againstallowed_ips. No special handling needed.Documentation Impact
architecture/security-policy.md: Document host wildcard syntax, delimiter semantics, multi-port syntax, backwards compat behavior.agents/skills/generate-sandbox-policy/SKILL.md: Update examples and schema referenceRevision 2 — clarified two independent OPA data conversion paths (proto vs YAML), reload() bypass risk, coordinated landing requirement for Steps 2+3
Revision 1 — initial plan
feat(policy): support host wildcards and multi-port endpoints
johntmyers commentedon Mar 16, 2026
Implementation Complete
PR: #366
What was built
Host wildcard support (
*.example.com) forendpoints[].hostusing glob matching with.as delimiter, and multi-port endpoints via aportsarray field — backwards compatible with existing single-port policies.Tests
Docs updated
architecture/security-policy.mdThe issue will auto-close when the PR is merged.
feat(policy): support host wildcards and multi-port endpoints (ai-ope…