[LXC] Address file system policy gaps#630
Open
dhoehna wants to merge 1 commit into
Open
Conversation
…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
Contributor
There was a problem hiding this comment.
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
deniedPathsto accept either a legacy string or an object{ path, type: "file" | "dir" }, and plumb the parsed mask kind intoContainerPolicy. - Add
wxc_common::path_specificityto 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())?, | ||
| )?; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
is_file()heuristic (which follows symlinks, is TOCTOU-prone, and mis-classifies missing paths) with an explicittype: "file" | "dir"schema discriminator plus asymlink_metadata()fallback that never follows symlinks. A missing path with no explicittypenow fails closed with an actionable error.path_specificitymodule inwxc_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
denied_paths: Vec<String>for compatibility; addedMaskKind+denied_path_kinds: HashMap<String, MaskKind>(default empty).deniedPathsnow accepts a bare string or{ path, type }. Regenerated JSON schema + TS wire types.Validation
cargo fmt --all -- --check;cargo clippyforwxc_commonand (linux target)lxc_commonwith-D warnings— cleancargo test -p wxc_common— 398 passedcargo check --target x86_64-unknown-linux-gnuforwxc_commonandlxc_common --tests— passIndependent of the sibling LXC branches (no shared model fields).
Microsoft Reviewers: Open in CodeFlow