Skip to content

User/dahoehna/honoring inbound rule#627

Open
dhoehna wants to merge 4 commits into
microsoft:mainfrom
dhoehna:user/dahoehna/HonoringInboundRule
Open

User/dahoehna/honoring inbound rule#627
dhoehna wants to merge 4 commits into
microsoft:mainfrom
dhoehna:user/dahoehna/HonoringInboundRule

Conversation

@dhoehna

@dhoehna dhoehna commented Jul 9, 2026

Copy link
Copy Markdown

📖 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:

# Linux host (WSL2 Ubuntu-24.04, systemd on): install LXC + bring up the bridge
sudo apt install -y lxc lxc-utils iptables bridge-utils
sudo systemctl enable --now lxc-net          # lxcbr0 (10.0.3.1/24)

# build the LXC backend executable (pinned Rust 1.93)
cd src && cargo build --release -p lxc        # -> src/target/release/lxc-exec

# run the harness as root (builds netcheck static-musl, runs both configs)
sudo ./tests/scripts/run_lxc_local_network_test.sh

For each config the harness launches lxc-exec <config>, waits for the container IP, then dumps the emitted host-side iptables chain MXC-<containerId> and asserts the loopback verb.

Result - [RULE] pass=2 fail=0:

Config iptables chain Loopback rule Expected Result
allowLocalNetwork: true MXC-lxc-localnet-allow -i lo -j ACCEPT ACCEPT ✅ PASS
allowLocalNetwork omitted (default) MXC-lxc-localnet-deny -i lo -j DROP DROP ✅ PASS

This confirms the LXC backend maps allowLocalNetwork to the correct iptables verb. The harness also reports an informational [BEHAVIOR] connect layer: with the current code the rule is emitted into the host FORWARD chain (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 inbound INPUT-path rule lands. Full runbook: docs/lxc-support/testing-allowlocalnetwork.md.

✅ Checklist

📋 Issue Type

  • Bug fix
  • Feature
  • Task

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 GitHub
Actions build; it runs on merge to main, and Microsoft reviewers with write access can trigger it
on a PR with /azp run. See docs/pull-requests.md.

If the dependency-feed-check check fails on a new dependency, the crate must be added to
the feed before the PR can pass. See docs/pull-requests.md
for the steps.

Microsoft Reviewers: Open in CodeFlow

@dhoehna dhoehna requested a review from a team as a code owner July 9, 2026 21:21
Copilot AI review requested due to automatic review settings July 9, 2026 21:21

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 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 allowLocalNetwork in the main config schema example and LXC backend docs.
  • Added allowLocalNetwork to 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.

Comment on lines +166 to +170
&self.chain_name,
"-i",
"lo",
"-j",
allow_local_network_verb,

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@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.

Comment thread docs/lxc-support/lxc-backend.md Outdated
Comment thread docs/schema.md
@SohamDas2021

SohamDas2021 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

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?

{
"network": {
"egress": {
"default": "deny",
"allow": [{ "to": [{ "cidr": "140.82.112.0/20" }], "ports": [{ "protocol": "tcp", "port": 443 }] }],
"deny": [{ "to": [{ "cidr": "10.0.0.0/8" }] }]
},
"ingress": { "hostLoopback": "deny" },
"proxy": { "http": "127.0.0.1:8080" }
}
}

@dhoehna

dhoehna commented Jul 10, 2026

Copy link
Copy Markdown
Author

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?

{ "network": { "egress": { "default": "deny", "allow": [{ "to": [{ "cidr": "140.82.112.0/20" }], "ports": [{ "protocol": "tcp", "port": 443 }] }], "deny": [{ "to": [{ "cidr": "10.0.0.0/8" }] }] }, "ingress": { "hostLoopback": "deny" }, "proxy": { "http": "127.0.0.1:8080" } } }

My changes are against the current schema. I can make a second PR to read ingress.hostloopback when the schema change is merged into main.

If I change the code to read ingress then I can't test this change until the schema goes in.

dhoehna and others added 2 commits July 10, 2026 12:26
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
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.

3 participants