Skip to content

[LXC] Address network policy gaps - model 2 (deny-all-except-proxy)#632

Open
dhoehna wants to merge 2 commits into
microsoft:mainfrom
dhoehna:user/dahoehna/lxc-net-model2-deny-all-except-proxy
Open

[LXC] Address network policy gaps - model 2 (deny-all-except-proxy)#632
dhoehna wants to merge 2 commits into
microsoft:mainfrom
dhoehna:user/dahoehna/lxc-net-model2-deny-all-except-proxy

Conversation

@dhoehna

@dhoehna dhoehna commented Jul 10, 2026

Copy link
Copy Markdown

Linked work item: AB#62830341 — [LXC] Address network policy gaps - model 2 (deny-all-except-proxy)

Summary

Implements the deny-all-except-proxy network model for LXC.

  • Fail-fast: when firewall mode is active but no veth interface is available, enforcement now returns an error instead of silently skipping the FORWARD hook (which previously left rules built but unenforced).
  • Deny-wins precedence: deny rules are now emitted before allow rules; rule construction refactored into a pure, ordered builder with a unit test asserting the order.
  • Proxy enforcement + env: when a proxy is configured, injects HTTP_PROXY / HTTPS_PROXY (+ lowercase) into the container and restricts egress to the proxy address:port (DROP other outbound).
  • Proxy env hygiene: scrubs inherited HTTP_PROXY / HTTPS_PROXY / ALL_PROXY / FTP_PROXY / NO_PROXY (+ lowercase) before setting configured values, via a pure proxy_env helper with unit tests.

Validation

  • cargo fmt --all -- --check; cargo clippy --target x86_64-unknown-linux-gnu -p lxc_common -D warnings — clean
  • cargo test -p wxc_common — 399 passed
  • cargo check --target x86_64-unknown-linux-gnu -p lxc_common --tests — pass

Independent of the sibling LXC branches.

Microsoft Reviewers: Open in CodeFlow

- Fail-fast when no veth in firewall mode (no more silent skip of the FORWARD hook).
- Emit deny rules before allow rules (deny-wins); pure ordered rule-builder + tests.
- Inject HTTP(S)_PROXY + iptables proxy-only egress; scrub all inherited proxy env vars first.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 3b78bec0-e139-4cfd-9c10-092ef986d4f4
Copilot AI review requested due to automatic review settings July 10, 2026 22:56
@dhoehna dhoehna requested a review from a team as a code owner July 10, 2026 22:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements a “deny-all-except-proxy” network model for the LXC backend, aiming to close enforcement gaps by failing fast when the FORWARD hook can’t be safely scoped, enforcing deny-wins rule ordering, and adding proxy-based egress restrictions plus proxy environment-variable hygiene for LXC executions.

Changes:

  • Refactors LXC iptables rule construction into an ordered rule builder (deny before allow) and fails fast when a veth interface is unavailable for scoping.
  • Adds LXC proxy enforcement that allows egress only to the configured proxy endpoint(s) and injects/scrubs proxy env vars for the container process.
  • Extends LXC attach-run environment handling with a “force clear env” control to prevent inherited proxy variables from leaking when the caller env becomes empty after scrubbing.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/core/wxc_common/src/proxy_env.rs New helper + unit tests for scrubbing and applying proxy-related env vars.
src/core/wxc_common/src/lib.rs Exposes the new proxy_env module.
src/core/wxc_common/src/config_parser.rs Allows network.proxy for lxc, adds LXC-specific validation and updates/extends tests.
src/backends/lxc/common/src/network_iptables.rs Implements proxy-only egress rules, deny-wins ordering, and fail-fast veth scoping; adds tests.
src/backends/lxc/common/src/lxc_runner.rs Uses apply_proxy_env and passes a force-clear-env flag into attach_run; includes proxy in “needs network” detection.
src/backends/lxc/common/src/lxc_bindings.rs Adds force_clear_env support to attach_run argument building and tests it.

Comment thread src/core/wxc_common/src/config_parser.rs
Comment thread src/core/wxc_common/src/config_parser.rs
Comment thread src/backends/lxc/common/src/network_iptables.rs
Comment thread src/backends/lxc/common/src/lxc_bindings.rs Outdated
…NS in proxy mode

Addresses Copilot reviewer feedback on the deny-all-except-proxy model:

- Reject network.proxy.localhost for LXC (127.0.0.1 is the container
  loopback, unreachable from the container netns); require network.proxy.url
  with a routable host. Update the LXC proxy test to use a url and add a
  rejection test.
- In proxy mode, only open outbound DNS when the proxy is addressed by
  hostname; when it is an IP literal keep the sandbox fully closed. Fix the
  misleading log line and add a host_is_ip_literal helper + unit test.
- Correct the build_attach_args doc comment: it is #[cfg(test)]-only; move
  the 'Linux + test builds' note onto build_attach_args_with_env_control.
- Note in docs/schema.md that LXC requires a url proxy (not loopback).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

2 participants