network: replace net_allow_hosts/net_connect with unified net_allow (#32)#34
Merged
congwang-mk merged 4 commits intomainfrom May 2, 2026
Merged
network: replace net_allow_hosts/net_connect with unified net_allow (#32)#34congwang-mk merged 4 commits intomainfrom
congwang-mk merged 4 commits intomainfrom
Conversation
8ede71b to
0007562
Compare
679dee7 to
dc2da57
Compare
dc2da57 to
40c837f
Compare
…,icmp} Signed-off-by: Cong Wang <cwang@multikernel.io>
cf052aa to
98a9474
Compare
…h positive flags Signed-off-by: Cong Wang <cwang@multikernel.io>
Signed-off-by: Cong Wang <cwang@multikernel.io>
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.
Closes #32.
Summary
Pre-1.0 breaking redesign of the network policy surface. Two commits:
1. Unify
--net-allow-hostand--net-connectinto--net-allow(40c837f)```
--net-allow repeatable; no rules = deny all outbound TCP
= host:port[,port,...] (IP-restricted)
| :port | *:port (any IP)
```
A connection is permitted iff the destination
(IP, port)matches at least one rule. Endpoints are first-class — there is no silent over-permissive mode.2. Default-deny UDP; collapse
--net-*-prototo--allow-{udp,icmp}(cf052aa)UDP previously defaulted to allowed, which conflicted with deny-by-default elsewhere. Now denied; opt in via
--allow-udp. The string-matched--net-allow-proto/--net-deny-protoflags are replaced with scalar booleans--allow-udpand--allow-icmp.Why
Issue #32 surfaced two real problems with the old surface:
connect(), so--net-allow-host github.com(without--net-connect) silently permitted SSH, SMTP, and any other port to the resolved IPs.--net-allow-hostwith--net-connectto fix that produced an awkward back-compat hatch where single-flag use was still permissive.Unifying the two into one endpoint primitive makes invalid configurations unrepresentable. Hosts and ports always travel as a pair. The proto flags were a parallel cleanup that fell out naturally — UDP is now consistent with TCP's deny-by-default.
Behavior
--net-allow api.openai.com:443--net-allow github.com:22,443--net-allow :8080--net-allow api.openai.com:443 --net-allow redis.local:6379--http-allow "GET api.example.com/*"api.example.com:80,443--http-allow "GET *.foo.com/*":80,443(wildcard host)--allow-udp)--allow-udp--net-allow--allow-icmpCAP_NET_RAWfrom kernel)What changed
Commit 1 — net-allow unification:
policy.rs,seccomp/notif.rs,seccomp/state.rs): newNetAllow { host: Option<String>, ports: Vec<u16> }.Policy::net_allow: Vec<NetAllow>replaces bothnet_allow_hostsandnet_connect.NetworkPolicyis nowAllowList { per_ip, any_ip_ports }with.allows(ip, port).network.rs):connect_on_behalf,sendto_on_behalf,sendmsg_on_behalfall check(ip, port)against the resolved allowlist.policy.rs::build()): each HTTP rule with a concrete host auto-addshost:80(andhost:443with--https-ca); wildcards add:80/:443.main.rs): new--net-allowgrammar; old--net-allow-host/--net-connectremoved.sandlock_policy_builder_net_allow(b, spec)replaces three old setters.net_allow: list[str]replaces both old fields.Commit 2 — proto-flag redesign:
Policy::no_udpdefault flipped fromFalse→True.--allow-udp/--allow-icmpboolean flags replace--net-allow-proto/--net-deny-proto.Tests
Migration
--net-allow-host api.example.com --net-connect 443--net-allow api.example.com:443--net-allow-host api.example.com(any port)--net-allow api.example.com:80,443,...(list each port)--net-connect 443(any IP)--net-allow :443--net-allow icmp--allow-icmp--net-deny udp(and the previous default that allowed UDP)--allow-udpto opt in (UDP now denied by default)--net-deny raw🤖 Generated with Claude Code