User/dahoehna/honoring inbound rule#627
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to make the LXC backend honor the cross-platform allowLocalNetwork network policy knob when installing iptables rules, and updates documentation/examples to surface the field.
Changes:
- Updated LXC iptables rule emission to conditionally ACCEPT/DROP traffic based on
allowLocalNetwork. - Documented
allowLocalNetworkin the main config schema example and LXC backend docs. - Added
allowLocalNetworkto the sandbox policy v1 JSON example.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/backends/lxc/common/src/network_iptables.rs | Adds allowLocalNetwork-driven ACCEPT/DROP behavior in the iptables chain. |
| docs/schema.md | Documents allowLocalNetwork in the example config. |
| docs/sandbox-policy/v1/policy.md | Adds allowLocalNetwork to the policy example payload. |
| docs/lxc-support/lxc-backend.md | Documents how allowLocalNetwork affects LXC network policy enforcement. |
| &self.chain_name, | ||
| "-i", | ||
| "lo", | ||
| "-j", | ||
| allow_local_network_verb, |
There was a problem hiding this comment.
@SohamDas2021 can you validate this comment? The roadmap said to add this to the FORWARD chain. I don't know who is correct. Your roadmap, or copilot.
|
Are your changes addressing all the requirements in https://microsoft.visualstudio.com/OS/_workitems/edit/62864412/?view=edit? "When ingress.hostLoopback is "allow", accept connections from host loopback only" My understanding was that we would need the new config json schema changes to go in first and you will have a subsequent PR to address that? { |
My changes are against the current schema. I can make a second PR to read If I change the code to read |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Adds a manual end-to-end test for the LXC backend's allowLocalNetwork
schema field:
- tests/helpers/netcheck/netcheck.rs: std-only TCP probe (serve/connect)
- tests/configs/lxc_local_network_{allow,deny}.json: Alpine 3.23 configs
- tests/scripts/run_lxc_local_network_test.sh: root-gated orchestrator that
builds netcheck (static musl), runs each config through lxc-exec, and
asserts the emitted iptables loopback verb (ACCEPT for allow, DROP for deny)
- docs/lxc-support/testing-allowlocalnetwork.md: runbook
Verified on WSL2 Ubuntu-24.04 + LXC 5.0.3: [RULE] pass=2 fail=0.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 3b78bec0-e139-4cfd-9c10-092ef986d4f4
📖 Description
LXC will now DROP or ACCEPT local packets depending on the value of
allowLocalNetwork.🔗 References
62864412
🔍 Validation
Verified end-to-end on a real Linux host - WSL2 Ubuntu-24.04 (systemd enabled) with LXC 5.0.3 - using the manual harness added in this PR (
tests/scripts/run_lxc_local_network_test.sh).How it was run:
For each config the harness launches
lxc-exec <config>, waits for the container IP, then dumps the emitted host-side iptables chainMXC-<containerId>and asserts the loopback verb.Result -
[RULE] pass=2 fail=0:allowLocalNetwork: trueMXC-lxc-localnet-allow-i lo -j ACCEPTallowLocalNetworkomitted (default)MXC-lxc-localnet-deny-i lo -j DROPThis confirms the LXC backend maps
allowLocalNetworkto the correct iptables verb. The harness also reports an informational[BEHAVIOR]connect layer: with the current code the rule is emitted into the hostFORWARDchain (hooked-o <veth>), which a host→container connect does not traverse, so it reports reachable for both configs today and will begin distinguishing allow vs deny automatically once the inboundINPUT-path rule lands. Full runbook:docs/lxc-support/testing-allowlocalnetwork.md.✅ Checklist
Cargo.lock, thedependency-feed-checkcheck passes (see docs/pull-requests.md)📋 Issue Type
GitHub Actions runs the PR validation build automatically. The ADO pipeline
(
MXC-PR-Build) is the Azure version of the PR pipeline, kept in parity with the GitHubActions build; it runs on merge to
main, and Microsoft reviewers with write access can trigger iton a PR with
/azp run. See docs/pull-requests.md.If the
dependency-feed-checkcheck fails on a new dependency, the crate must be added tothe feed before the PR can pass. See docs/pull-requests.md
for the steps.
Microsoft Reviewers: Open in CodeFlow