feat(policy): support host wildcards and multi-port endpoints#366
Merged
johntmyers merged 2 commits intomainfrom Mar 16, 2026
Merged
feat(policy): support host wildcards and multi-port endpoints#366johntmyers merged 2 commits intomainfrom
johntmyers merged 2 commits intomainfrom
Conversation
Add glob-style host wildcards to endpoints[].host using OPA's glob.match with "." as delimiter — *.example.com matches a single DNS label, **.example.com matches across labels. Validation rejects bare * and requires *. prefix; warns on broad patterns like *.com. Add repeated uint32 ports field to NetworkEndpoint for multi-port support. Backwards compatible: existing port scalar is normalized to ports array. Both the proto-to-JSON and YAML-to-JSON conversion paths emit a ports array; Rego always references endpoint.ports[_]. Fix OpaEngine::reload() to route through the full preprocessing pipeline instead of bypassing L7 validation and port normalization. Closes #359
drew
approved these changes
Mar 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add glob-style host wildcards (
*.example.com) toendpoints[].hostand multi-port support via aportsarray field onNetworkEndpoint. Both features follow existing patterns in the policy engine and are backwards compatible with existing policies.Related Issue
Closes #359
UX Changes
Host Wildcards
You can now use glob patterns in
endpoints[].hostinstead of listing every subdomain individually:Pattern semantics use
.as the delimiter:*.example.comapi.example.com,cdn.example.comexample.com,deep.sub.example.com**.example.comapi.example.com,deep.sub.example.comexample.comexample.comexample.com(exact, unchanged)api.example.comValidation rejects overly broad patterns:
*or**→ error (matches all hosts)*com→ error (must start with*.or**.)*.com→ warning (very broad, covers all subdomains of a TLD)Multi-Port Endpoints
You can now specify multiple ports on a single endpoint instead of duplicating the block:
Backwards compatible — existing
port: 443syntax still works unchanged. Internally it normalizes toports: [443].Combined
Both features compose naturally:
Changes
proto/sandbox.proto: Addedrepeated uint32 ports = 9toNetworkEndpoint, documented host wildcard support onhostfieldcrates/openshell-policy/src/lib.rs: Addedportsfield to YAML serde type,port↔portsnormalization into_proto()/from_proto(), compact serialization (single port uses scalar form)crates/openshell-sandbox/data/sandbox-policy.rego: Splitendpoint_allowedinto exact/glob host clauses, changedendpoint.port→endpoint.ports[_]in all rules, added glob host matching toendpoint_matches_requestcrates/openshell-sandbox/src/opa.rs: Updatedproto_to_opa_data_json()to emitportsarray, addednormalize_endpoint_ports()topreprocess_yaml_data(), fixedreload()to route through full preprocessing pipeline instead of bypassing validationcrates/openshell-sandbox/src/l7/mod.rs: Updatedvalidate_l7_policies()forportsarray and wildcard host validation (rejects bare*, requires*.prefix, warns on broad patterns)crates/openshell-sandbox/src/mechanistic_mapper.rs: Emitportsfield in generated proposalsarchitecture/security-policy.md: Documented host wildcard syntax, delimiter semantics, multi-port syntax, backwards compat, validation rulese2e/python/test_sandbox_policy.py: Added 6 e2e tests (MP-1 through MP-3 for multi-port, HW-1 through HW-3 for host wildcards)Deviations from Plan
None — implemented as planned.
Testing
mise run pre-commitpassesTests added:
Checklist
Documentation updated:
architecture/security-policy.md: Host wildcard and multi-port sections with syntax, validation rules, examples, and field mapping table updates