Skip to content

Seatbelt: fall back to policy-allowed cwd to avoid getcwd warnings - #688

Open
richiemsft wants to merge 1 commit into
mainfrom
user/saulg/fix-611-seatbelt
Open

Seatbelt: fall back to policy-allowed cwd to avoid getcwd warnings#688
richiemsft wants to merge 1 commit into
mainfrom
user/saulg/fix-611-seatbelt

Conversation

@richiemsft

@richiemsft richiemsft commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

📖 Description

When an explicit process.cwd (or the inherited host cwd) is not readable under the deny-by-default Seatbelt profile, the child shell's startup getcwd() walk fails and leaks noisy "cannot access parent directories" warnings from bash's shell-init / job-working-directory onto stderr.

resolve_working_directory now honors an explicit working directory only when it is readable under the filesystem policy (within a readwrite/readonly path and not within a denied path, matched component-wise). Otherwise it launches from a policy-allowed directory (first readwrite, else first readonly, else /) and logs an informational diagnostic to the mxc log. The command still runs unchanged; only the launch directory changes, never the granted filesystem access.

Adds unit tests for the allow/deny/fallback/tilde/component-boundary cases and an end-to-end characterization test asserting an out-of-policy cwd produces no getcwd noise while the command still succeeds. Updates the Seatbelt backend doc.

🔗 References

Resolves the Mac issue from #611

🔍 Validation

Validated locally on a Mac. All green

✅ 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

@richiemsft
richiemsft requested a review from a team as a code owner July 27, 2026 20:26
Copilot AI review requested due to automatic review settings July 27, 2026 20:26

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.

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

@azure-pipelines

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

@richiemsft

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

When an explicit process.cwd (or the inherited host cwd) is not readable
under the deny-by-default Seatbelt profile, the child shell's startup
getcwd() walk fails and leaks noisy "cannot access parent directories"
warnings from bash's shell-init / job-working-directory onto stderr.

resolve_working_directory now honors an explicit working directory only
when it is readable under the filesystem policy (within a
readwrite/readonly path and not within a denied path, matched
component-wise). Otherwise it launches from a policy-allowed directory
(first readwrite, else first readonly, else /) and logs an informational
diagnostic to the mxc log. The command still runs unchanged; only the
launch directory changes, never the granted filesystem access.

Adds unit tests for the allow/deny/fallback/tilde/component-boundary
cases and an end-to-end characterization test asserting an out-of-policy
cwd produces no getcwd noise while the command still succeeds. Updates
the Seatbelt backend doc.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: e4e66e58-7a38-4be3-ab78-32fa15b726ca
Copilot AI review requested due to automatic review settings July 27, 2026 20:32
@richiemsft
richiemsft force-pushed the user/saulg/fix-611-seatbelt branch from 89b985e to 8f21b13 Compare July 27, 2026 20:32

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

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

Comments suppressed due to low confidence (1)

src/backends/seatbelt/common/src/seatbelt_runner.rs:722

  • The first policy path is not guaranteed to be usable. Missing paths are only warned about (config_parser.rs:358-373), and a broader deny can cover an allow (for example, allow /work/sub plus deny /work), so this can select a nonexistent or denied cwd and make Command::spawn fail instead of trying a valid readonly path or /. Select the first expanded, existing directory that also passes the deny check.
    let default = request
        .policy
        .readwrite_paths
        .first()
        .or_else(|| request.policy.readonly_paths.first())

Comment on lines +700 to +702
if is_working_directory_allowed(request, &request.working_directory) {
return request.working_directory.clone();
}
Comment on lines +766 to +767
let child_components: Vec<&str> = child.trim_end_matches('/').split('/').collect();
let ancestor_components: Vec<&str> = ancestor.trim_end_matches('/').split('/').collect();
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