Skip to content

Do not run privileged LXC containers. - #1688

Open
Darren Hoehna (dhoehna) wants to merge 32 commits into
mainfrom
user/dahoehna/lxc-unprivileged-check
Open

Darren Hoehna (dhoehna) wants to merge 32 commits into
mainfrom
user/dahoehna/lxc-unprivileged-check

Conversation

@dhoehna

@dhoehna Darren Hoehna (dhoehna) commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Problem

LXC can report a container as unprivileged while its user or group mappings still expose root outside the container.

Fix

MXC checks the complete live UID and GID maps before running the requested command. Unreadable or empty maps, malformed rows, invalid ranges, or any mapping to outside ID 0 reject the workload and trigger a container stop. Stop failures are returned to the caller.

Networking is configured for container startup, using reserved addresses when the container needs one.

Unprivileged LXC requires Linux 3.12 or later.

✅ Checklist

  • Signed the Contributor License Agreement
  • Linked to an issue
  • For features or changes requiring a spec: linked the issue with maintainer-applied feature-accepted
  • For implementation: linked the required approved and merged design/API spec, or explained why no spec is required
  • Feature issue remains open unless this PR completes all agreed implementation, validation, and documentation
  • Updated documentation (if applicable)
  • Updated Copilot instructions (if build, architecture, or conventions changed)
  • If this PR changes Cargo.lock, the dependency-feed-check check passes (see pull request builds)

📋 Issue Type

  • Bug fix
  • Feature
  • Task
Microsoft Reviewers: Open in CodeFlow

Darren Hoehna (dhoehna) and others added 11 commits November 4, 2026 13:22
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ee956a7c-701c-4e30-ba23-88ed75d298fc
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ee956a7c-701c-4e30-ba23-88ed75d298fc
LXC's reported classification replaces MXC-specific ID-map requirements.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ee956a7c-701c-4e30-ba23-88ed75d298fc
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ee956a7c-701c-4e30-ba23-88ed75d298fc
Remove the helper-specific tests instead of keeping a helper solely for testing.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ee956a7c-701c-4e30-ba23-88ed75d298fc
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ee956a7c-701c-4e30-ba23-88ed75d298fc
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ee956a7c-701c-4e30-ba23-88ed75d298fc
Configured status can report an unprivileged container even when it retains the host user namespace.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ee956a7c-701c-4e30-ba23-88ed75d298fc
Use complete command output instead of the bounded helper; inspection now waits for lxc-attach to finish.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ee956a7c-701c-4e30-ba23-88ed75d298fc
A readable shifted-root range is sufficient; unreadable or nonmatching rows do not veto admission.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ee956a7c-701c-4e30-ba23-88ed75d298fc
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ee956a7c-701c-4e30-ba23-88ed75d298fc
@dhoehna
Darren Hoehna (dhoehna) requested a review from a team as a code owner November 5, 2026 22:20
Copilot AI balanced review requested due to automatic review settings November 5, 2026 22:20
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

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.

🟡 Changes recommended

The LXC admission check trusts forgeable guest output, exposes host environment variables, and breaks existing SDK and CI flows without the required unprivileged provisioning and migration support.

5 open issues
What changed in this PR

This PR adds an unprivileged-container admission check to MXC’s LXC backend, intended to reject privileged containers before executing the requested workload.

Changes:

  • Inspect the live UID mapping after startup and stop containers that fail validation.
  • Add a regression scenario for misleading LXC privilege metadata and include it in the LXC suite.
  • Document unprivileged-container requirements and raise the minimum Linux kernel version to 3.12.
File Description
tests/​scripts/​run_lxc_unprivileged_test.sh Tests rejection, workload prevention, and cleanup for an identity-mapped container.
tests/​scripts/​run_lxc_all_tests.sh Adds the admission regression to the LXC suite.
src/​mxc-sdk/​src/​backends/​lxc/​common/​lxc_bindings.rs Adds UID-map validation and routes command execution through validated startup.
docs/​backends/​lxc/​lxc-backend.md Updates prerequisites and describes the admission check.

Review effort: Balanced

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ee956a7c-701c-4e30-ba23-88ed75d298fc
Copilot AI balanced review requested due to automatic review settings November 6, 2026 19:09

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.

🔵 Needs a closer look

The admission check trusts guest-controlled output and can expose host credentials, while the V1 compatibility break lacks the required security-servicing documentation and migration guidance.

5 open issues
1 previously missed issue

In code that hasn't changed since last review

Medium severity Configure shifted UID/GID mappings in all CI hosts

.github/​workflows/​lxc-e2e.yml:51

[P1] Scheduled LXC validation (scripts/ci/prepare-linux-host.sh) and Azure SDK integration (.azure-pipelines/templates/SDK.Integration.Test.Job.yml) still install LXC without configuring shifted mappings or root subordinate UID/GID ranges. On clean hosts with default LXC configuration, the new admission check rejects their normal success-path scenarios. Provision the mappings and required mapping tools in those entry points too, preferably through shared host setup with appropriate cleanup.

Review effort: Balanced

The streaming and PTY cases need no host files; sharing /tmp can prevent mapped-container startup on hosts with nested mounts.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ee956a7c-701c-4e30-ba23-88ed75d298fc
Namespace entry restored capabilities dropped on the host, allowing raw-socket traffic through the ICMP allowance.  Reading UID mappings on the host avoids trusting guest code during admission.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ee956a7c-701c-4e30-ba23-88ed75d298fc
Comment thread docs/backends/lxc/lxc-backend.md Resolved
@microsoft-github-policy-service microsoft-github-policy-service Bot added the Needs-Author-Feedback Waiting for additional information or action from the issue or pull-request author. label Nov 9, 2026
Retain guest networking capabilities and enforce policy outside the container.  Cross-container UDP reply theft remains unresolved.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 8d35d189-89d3-400f-aaef-a33c8ce5860c
Copilot AI balanced review requested due to automatic review settings November 10, 2026 17:59

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.

Comment thread .github/workflows/lxc-e2e.yml Resolved
Install policy in the container's network namespace before init with network capabilities already removed; networkless creation does not prevent later networked reuse.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 8d35d189-89d3-400f-aaef-a33c8ce5860c
Keep the HTTP probes behavioral instead of adding firewall introspection to satisfy a stale inventory.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 8d35d189-89d3-400f-aaef-a33c8ce5860c
Copilot AI balanced review requested due to automatic review settings November 14, 2026 00:25

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.

🔵 Needs a closer look

The reservation shell lacks cancellation-aware process ownership and inherits blocked fatal signals, allowing it and its descendants to survive executor exit while holding the reservation lock or modifying shared lxc-net configuration.

4 open issues

Review effort: Balanced

Keep updated trace-source selection alongside the capture availability probe.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 8d35d189-89d3-400f-aaef-a33c8ce5860c
Copilot AI balanced review requested due to automatic review settings November 14, 2026 01:58

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.

🟡 Changes recommended

Unresolved findings expose host firewall changes before admission checks, reservation subprocesses that can outlive cancellation, scheduled LXC validation failures, and lost preserved-policy regression coverage.

6 open issues

Review effort: Balanced

lxc)
install_lxc
command -v lxc-start
busybox --list | grep -Fx udhcpc

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.

Looks legit.

set -eu
PATH=/usr/sbin:/usr/bin:/sbin:/bin
export PATH
: "${LXC_PID:?LXC_PID is required}"

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.

looks legit.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 8d35d189-89d3-400f-aaef-a33c8ce5860c
Copilot AI balanced review requested due to automatic review settings November 14, 2026 03:35

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.

🔵 Needs a closer look

The untracked reservation shell can outlive cancellation and continue changing host networking, while scheduled LXC validation lacks the UID/GID mappings required to pass unprivileged-container checks.

6 open issues

Review effort: Balanced

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 8d35d189-89d3-400f-aaef-a33c8ce5860c
Copilot AI balanced review requested due to automatic review settings November 14, 2026 03:43

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.

🔵 Needs a closer look

Startup cancellation can leave the untracked reservation helper running as root after MXC exits, allowing it to modify shared dnsmasq configuration or retain the reservation lock without completing cleanup.

6 open issues

Review effort: Balanced

Newer LXC preserves ping's file capability, which the container's bounding set rejects.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 8d35d189-89d3-400f-aaef-a33c8ce5860c
Copilot AI balanced review requested due to automatic review settings November 14, 2026 04:24

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.

🔵 Needs a closer look

The reservation helper bypasses startup process ownership and inherits blocked termination signals, so cancellation can leave a root process modifying shared network configuration after MXC exits.

6 open issues

Review effort: Balanced

@dhoehna
Darren Hoehna (dhoehna) requested review from Soham Das (SohamDas2021) and removed request for a team November 16, 2026 17:05
run_test "LXC Network Proxy Reuse" "$SCRIPT_DIR/run_lxc_network_proxy_reuse_test.sh"
run_test "LXC Network Proxy Reset" "$SCRIPT_DIR/run_lxc_network_proxy_reset_test.sh"
run_test "LXC Network Proxy Credentials" "$SCRIPT_DIR/run_lxc_network_proxy_credentials_test.sh"
run_test "LXC Network Preserve Policy" "$SCRIPT_DIR/run_lxc_network_preserve_policy_test.sh"

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.

Why are we deleting this?


// Generous enough to delete a large rootfs on slow storage.
const RELEASE_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(120);
let timeout = crate::lxc_common::signal_cleanup::startup_time_remaining()

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.

Failed startup clears the startup deadline, so cleanup falls back to 120s while the new guard exits MXC at 60s?

set -eu
PATH=/usr/sbin:/usr/bin:/sbin:/bin
export PATH
: "${LXC_PID:?LXC_PID is required}"

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.

looks legit.

lxc)
install_lxc
command -v lxc-start
busybox --list | grep -Fx udhcpc

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.

Looks legit.

Comment on lines +32 to +34
let output = command
.output()
.map_err(|error| format!("Failed to reserve LXC address: {error}"))?;

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.

Looks legit.

@microsoft-github-policy-service microsoft-github-policy-service Bot added the Needs-Author-Feedback Waiting for additional information or action from the issue or pull-request author. label Nov 16, 2026
Validate both complete maps instead of treating one shifted UID row as proof that the container is unprivileged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4a64f88e-58c0-48bf-a5b2-c07d15557095
Copilot AI balanced review requested due to automatic review settings November 16, 2026 22:25

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.

🔵 Needs a closer look

Human assessment is needed because functional coverage does not verify retained-container filtering after executor exit or rejection of containers retaining the host user namespace.

6 open issues

Review effort: Balanced

assert_eq!(
result.is_ok(),
accepted,
"uid_map={uid_map:?}, gid_map={gid_map:?}; got {result:?}"
@SohamDas2021

Copy link
Copy Markdown
Contributor

Could we add a CI-wired lxc-exec E2E covering valid shifted maps, an identity GID map, and a non-root container UID mapped to host UID 0? The unit tests don’t verify live admission and cleanup. For rejected cases, please assert the admission error, no workload execution, and a stopped container with destroyOnExit: false.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs-Attention Requires attention or a decision from the MXC maintainers. Needs-Author-Feedback Waiting for additional information or action from the issue or pull-request author.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants