Skip to content

[LXC] Address file system policy gaps#630

Open
dhoehna wants to merge 1 commit into
microsoft:mainfrom
dhoehna:user/dahoehna/lxc-fs-policy-gaps
Open

[LXC] Address file system policy gaps#630
dhoehna wants to merge 1 commit into
microsoft:mainfrom
dhoehna:user/dahoehna/lxc-fs-policy-gaps

Conversation

@dhoehna

@dhoehna dhoehna commented Jul 10, 2026

Copy link
Copy Markdown

Linked work item: AB#62861419 — [LXC] Address file system policy gaps

Summary

Hardens LXC denied-path masking and adds a reusable most-specific-path-wins policy resolver.

  • Denied-path masking: replaces the is_file() heuristic (which follows symlinks, is TOCTOU-prone, and mis-classifies missing paths) with an explicit type: "file" | "dir" schema discriminator plus a symlink_metadata() fallback that never follows symlinks. A missing path with no explicit type now fails closed with an actionable error.
  • Most-specific-path-wins resolver: new path_specificity module in wxc_common — deeper paths override shallower ancestors; exact-path ties resolve most-restrictive-wins (deny > readonly > readwrite). Wired into LXC mount emission (shallowest → deepest so the deepest intent wins).

Model / schema

  • Kept denied_paths: Vec<String> for compatibility; added MaskKind + denied_path_kinds: HashMap<String, MaskKind> (default empty).
  • Wire deniedPaths now accepts a bare string or { path, type }. Regenerated JSON schema + TS wire types.

Validation

  • cargo fmt --all -- --check; cargo clippy for wxc_common and (linux target) lxc_common with -D warnings — clean
  • cargo test -p wxc_common — 398 passed
  • cargo check --target x86_64-unknown-linux-gnu for wxc_common and lxc_common --tests — pass

Independent of the sibling LXC branches (no shared model fields).

Microsoft Reviewers: Open in CodeFlow

…B#62861419)

- Replace is_file() masking heuristic with explicit `type` schema field + symlink_metadata() fallback (no symlink follow; fail-closed on missing+untyped).
- Add reusable most-specific-path-wins resolver in wxc_common (deny>ro>rw); wire LXC mounts to emit in specificity order.

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 hardens filesystem policy handling by extending the wire format for filesystem.deniedPaths and introducing a reusable “most-specific-path-wins” resolver to produce deterministic mount emission order for Linux backends.

Changes:

  • Extend deniedPaths to accept either a legacy string or an object { path, type: "file" | "dir" }, and plumb the parsed mask kind into ContainerPolicy.
  • Add wxc_common::path_specificity to resolve overlapping filesystem intents by specificity (deep overrides shallow; exact ties pick most restrictive).
  • Update LXC mount emission to use the new resolver and apply explicit denied-path mask kinds.

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/core/wxc_common/src/wire.rs Changes wire model so deniedPaths supports string or typed object entries.
src/core/wxc_common/src/ts_emit.rs Updates TS emitter to correctly emit anyOf unions and allOf wrappers as TypeScript type aliases.
src/core/wxc_common/src/path_specificity.rs Introduces the new most-specific-path-wins resolver and tests.
src/core/wxc_common/src/models.rs Adds MaskKind and denied_path_kinds to ContainerPolicy for backend masking decisions.
src/core/wxc_common/src/lib.rs Exposes the new path_specificity module.
src/core/wxc_common/src/filesystem_resolve.rs Keeps compatibility by re-exporting the resolver from the new module.
src/core/wxc_common/src/config_parser.rs Converts wire denied-path entries into denied_paths + denied_path_kinds in the domain policy.
src/backends/lxc/common/src/filesystem_mounts.rs Switches mount emission ordering to the resolver and adds explicit denied-path masking logic.
sdk/src/generated/wire.ts Regenerates TS wire types for the new DeniedPath union/object forms.
schemas/dev/mxc-config.schema.0.8.0-dev.json Regenerates the dev schema to reflect the new denied-path shapes.

Comment on lines +44 to +62
fn observed_mask_path_kind(full_path: &str) -> Result<Option<ObservedMaskPathKind>, String> {
match std::fs::symlink_metadata(full_path) {
Ok(metadata) => {
let file_type = metadata.file_type();
if file_type.is_dir() {
Ok(Some(ObservedMaskPathKind::Dir))
} else if file_type.is_symlink() {
Ok(Some(ObservedMaskPathKind::Symlink))
} else {
Ok(Some(ObservedMaskPathKind::File))
}
}
Err(err) if err.kind() == std::io::ErrorKind::NotFound => Ok(None),
Err(err) => Err(format!(
"Unable to inspect denied path '{}': {}. Set deniedPaths entry to an object with explicit type \"file\" or \"dir\".",
full_path, err
)),
}
}
Comment on lines +118 to +125
let rootfs_base = format!("{}/{}/rootfs", container.lxc_path(), container.name());
let full_path = Path::new(&rootfs_base).join(container_path);
let explicit = policy.denied_path_kinds.get(host_path).copied();
let kind = resolve_mask_kind(
host_path,
explicit,
observed_mask_path_kind(&full_path.to_string_lossy())?,
)?;
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