Skip to content

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
mainfrom
feat/net-rule-any-proto
Open

feat(net): apply scheme-less --net-allow/--net-deny rules to both TCP and UDP#139
congwang-mk wants to merge 1 commit into
mainfrom
feat/net-rule-any-proto

Conversation

@congwang-mk

Copy link
Copy Markdown
Contributor

Closes #132.

A --net-allow / --net-deny spec with no scheme now applies to both TCP and UDP: it expands to one rule per protocol at parse time. tcp://, udp://, and icmp:// keep pinning a single protocol, so nothing becomes inexpressible; ICMP is never implied and still requires an explicit icmp:// rule.

Motivation (from the #75 discussion):

  • --net-allow '*' --net-allow 'udp://*' collapses to --net-allow '*', and --net-allow 1.1.1.1:53 now actually permits ordinary (UDP) DNS queries.
  • The deny side is the security-relevant half: --net-deny 169.254.169.254 previously 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:

  • Expansion happens in NetRule::parse_spec, which now returns Vec<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.
  • The serde default of protocol: tcp on NetRule is 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 explicit tcp:// rule on reparse.
  • resolve_net_allow resolves 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/hosts lines.
  • README, sandbox-reference, and the Python SDK docstrings are updated to the new default.

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/8 now blocks UDP to the CIDR while leaving other destinations open. Full Rust workspace suite (18 suites) and the Python suite (386 tests) pass.

… and UDP

Signed-off-by: Cong Wang <cwang@multikernel.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Simplify --net-allow syntax for UDP

1 participant