feat(net): apply scheme-less --net-allow/--net-deny rules to both TCP and UDP#139
Open
congwang-mk wants to merge 1 commit into
Open
feat(net): apply scheme-less --net-allow/--net-deny rules to both TCP and UDP#139congwang-mk wants to merge 1 commit into
congwang-mk wants to merge 1 commit into
Conversation
… and UDP 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 #132.
A
--net-allow/--net-denyspec with no scheme now applies to both TCP and UDP: it expands to one rule per protocol at parse time.tcp://,udp://, andicmp://keep pinning a single protocol, so nothing becomes inexpressible; ICMP is never implied and still requires an expliciticmp://rule.Motivation (from the #75 discussion):
--net-allow '*' --net-allow 'udp://*'collapses to--net-allow '*', and--net-allow 1.1.1.1:53now actually permits ordinary (UDP) DNS queries.--net-deny 169.254.169.254previously blocked only TCP to the metadata service, silently leaving the UDP path open when UDP was allowed. A scheme-less deny now closes both.Implementation notes:
NetRule::parse_spec, which now returnsVec<NetRule>(one rule for scheme'd specs, a TCP + UDP pair otherwise). Every rule still carries exactly one concrete protocol, so resolution, seccomp routing, the Landlock TCP fast path, and port remap are unchanged.serdedefault ofprotocol: tcponNetRuleis removed; the field is always written explicitly, and pre-1.0 policies are not kept compatible by policy.format_net_rule(profile round-trip) now always renders the scheme: a bare rendering would re-widen an explicittcp://rule on reparse.resolve_net_allowresolves each unique hostname once and shares the IP set across protocol passes; per-pass lookups could disagree under DNS round-robin and duplicated the synthetic/etc/hostslines.Verified end to end with the built CLI: UDP sendto succeeds under
--net-allow '*', stays blocked under--net-allow 'tcp://*', and a scheme-less--net-deny 127.0.0.0/8now blocks UDP to the CIDR while leaving other destinations open. Full Rust workspace suite (18 suites) and the Python suite (386 tests) pass.