Skip to content

net-allow: support * in port position for any-port wildcard#37

Merged
congwang-mk merged 2 commits intomainfrom
net-allow-wildcard
May 5, 2026
Merged

net-allow: support * in port position for any-port wildcard#37
congwang-mk merged 2 commits intomainfrom
net-allow-wildcard

Conversation

@congwang-mk
Copy link
Copy Markdown
Contributor

Summary

  • Adds * wildcard in port position of --net-allow specs: :* / *:* (any host, any port), host:* (any port to host)
  • Mixing * with concrete ports (host:80,*) is rejected with a clear error
  • When any rule uses the all-ports wildcard, Landlock drops CONNECT_TCP from handled_access_net (kernel cannot express "every port" without enumerating 65535 rules); the on-behalf seccomp path becomes the sole enforcer, and for :* it short-circuits to allow-all
  • README updated: syntax block, defaults, wildcards subsection, two new CLI examples, Python Policy reference comment

Issue #32 (closed) follow-up — the reporter asked for "a simple command-line option to allow unrestricted network access." --net-allow :* is the answer; --allow-udp is still required separately for UDP egress to keep the syscall surface explicit.

Test plan

  • 11 new NetAllow::parse unit tests covering :port, *:port, host:*, :*, *:*, mixed-rejection, port-zero rejection, no-colon rejection, repeated-wildcard idempotence
  • 3 new resolver tests: any_ip_all_ports, host:* populates per_ip_all_ports, mixed wildcard + concrete
  • 2 new integration tests: :* end-to-end (sandbox connects to a localhost listener on a random port nothing else mentions); host:* permits localhost, denies 1.1.1.1:80
  • CLI smoke test: sandlock run --net-allow ':*' -- echo runs; sandlock run --net-allow 'host:80,*' -- errors with "cannot mix"
  • Full workspace test suite: 467 tests pass

🤖 Generated with Claude Code

Issue #32 asked for a way to allow unrestricted outbound network
access without enumerating every port. This adds a `*` wildcard in
the port position of `--net-allow` specs, with three useful forms:

  *:*  /  :*       any host, any port (fully unrestricted egress)
  host:*           any port to host (other hosts still blocked)
  host:80,*        rejected (no mixing wildcard with concrete ports)

NetAllow gains an `all_ports: bool` field; the parser sets it when it
sees the `*` token and rejects mixed specs. ResolvedNetAllow exposes
`per_ip_all_ports` (IPs from `host:*` rules after DNS resolution) and
`any_ip_all_ports` (true when any rule is `:*`).

Signed-off-by: Cong Wang <cwang@multikernel.io>
…param

Signed-off-by: Cong Wang <cwang@multikernel.io>
@congwang-mk congwang-mk merged commit a719f89 into main May 5, 2026
8 checks passed
@congwang-mk congwang-mk deleted the net-allow-wildcard branch May 5, 2026 01:35
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.

1 participant