Skip to content

Filter Windows sandbox roots from SSH config dependencies - #18493

Merged
efrazer-oai merged 4 commits into
mainfrom
efrazer/windows-sandbox-ssh-dependency-roots-v2
Apr 19, 2026
Merged

efrazer-oai merged 4 commits into
mainfrom
efrazer/windows-sandbox-ssh-dependency-roots-v2

Conversation

@efrazer-oai

@efrazer-oai efrazer-oai commented Apr 18, 2026 •

Copy link
Copy Markdown
Contributor

Stack

  1. Base PR: Do not grant Windows sandbox ACLs on USERPROFILE #18443 stops granting ACLs on USERPROFILE.
  2. This PR: filters additional SSH-owned profile roots discovered from SSH config.

Bug

The base PR removes the broadest bad grant: USERPROFILE itself.

That still leaves one important case. A user profile child can be SSH-owned even when its name is not one of our fixed exclusions.

For example:

Host devbox
  IdentityFile ~/.keys/devbox
  CertificateFile ~/.certs/devbox-cert.pub
  UserKnownHostsFile ~/.known_hosts_custom
  Include ~/.ssh/conf.d/*.conf

After profile expansion, the sandbox might see these as normal profile children:

C:\Users\me\.keys
C:\Users\me\.certs
C:\Users\me\.known_hosts_custom
C:\Users\me\.ssh

Those paths have another owner: OpenSSH and the tools that manage SSH identity and host-key state. Codex should not add sandbox ACLs to them.

OpenSSH describes this dependency tree in ssh_config(5), and the client parser follows the same shape in readconf.c:

  • Include recursively reads more config files and expands globs
  • IdentityFile and CertificateFile name authentication files
  • UserKnownHostsFile, GlobalKnownHostsFile, and RevokedHostKeys name host-key files
  • ControlPath and IdentityAgent can name profile-owned sockets or control files
  • these path directives can use forms such as ~, %d, and ${HOME}

Change

This PR adds a small SSH config dependency scanner.

It starts at:

~/.ssh/config

Then it returns concrete paths named by Include and by path-valued SSH config directives:

IdentityFile
CertificateFile
UserKnownHostsFile
GlobalKnownHostsFile
RevokedHostKeys
ControlPath
IdentityAgent

For example:

IdentityFile ~/.keys/devbox
CertificateFile ~/.certs/devbox-cert.pub
Include ~/.ssh/conf.d/*.conf

returns paths like:

C:\Users\me\.keys\devbox
C:\Users\me\.certs\devbox-cert.pub
C:\Users\me\.ssh\conf.d\devbox.conf

The setup code then maps those paths back to their top-level USERPROFILE child and filters matching sandbox roots out of both the writable and readable root lists.

Why this shape

The parser reports what SSH config references. The sandbox setup code decides which USERPROFILE roots are unsafe to grant.

That keeps the policy simple:

  1. expand broad profile grants
  2. remove the profile root
  3. remove fixed sensitive profile folders
  4. remove profile folders referenced by SSH config dependencies

If a path has two possible owners, the sandbox steps back. SSH keeps control of SSH config, keys, certificates, known-hosts files, sockets, and included config files.

Tests

  • cargo test -p codex-windows-sandbox --lib
  • just bazel-lock-check
  • just fix -p codex-windows-sandbox
  • git diff --check

@efrazer-oai efrazer-oai changed the title Filter Windows sandbox SSH dependency roots Filter Windows sandbox roots from SSH config dependencies Apr 18, 2026
@efrazer-oai
efrazer-oai force-pushed the efrazer/windows-sandbox-block-profile-root branch from ab952b1 to d4f84ad Compare April 18, 2026 18:42
@efrazer-oai
efrazer-oai force-pushed the efrazer/windows-sandbox-ssh-dependency-roots-v2 branch from 88228de to 6a15ba6 Compare April 18, 2026 18:46
@efrazer-oai
efrazer-oai force-pushed the efrazer/windows-sandbox-block-profile-root branch from d4f84ad to 2f71016 Compare April 18, 2026 18:58
@efrazer-oai
efrazer-oai force-pushed the efrazer/windows-sandbox-ssh-dependency-roots-v2 branch 3 times, most recently from 9d9d627 to 87dc7ab Compare April 18, 2026 19:13
efrazer-oai added a commit that referenced this pull request Apr 19, 2026
efrazer-oai added a commit that referenced this pull request Apr 19, 2026
@efrazer-oai
efrazer-oai marked this pull request as ready for review April 19, 2026 16:20
@efrazer-oai
efrazer-oai force-pushed the efrazer/windows-sandbox-ssh-dependency-roots-v2 branch from 96d1d9f to 6a8fe3b Compare April 19, 2026 19:37
efrazer-oai added a commit that referenced this pull request Apr 19, 2026
## Stack

1. This PR: expand and filter `USERPROFILE` roots.
2. Follow-up: #18493 filters SSH config dependency roots on top of this
base.

## Bug

On Windows, Codex can grant the sandbox ACL access to the whole user
profile directory.

That means the sandbox ACL can be applied under paths like:

```text
C:\Users\me\.ssh
C:\Users\me\.tsh
```

This breaks SSH. Windows OpenSSH checks permissions on SSH config and
key material. If Codex adds a sandbox group ACL to those files, OpenSSH
can reject the config or keys.

The bad interaction is:

1. Codex asks the Windows sandbox to grant access to `USERPROFILE`.
2. The sandbox applies ACLs under that root.
3. SSH-owned files get an extra ACL entry.
4. OpenSSH rejects those files because their permissions are no longer
strict enough.

## Why this happens more now

Codex now has more flows that naturally start in the user profile:

- a new chat can start in the user directory
- a project can be rooted in the user directory
- a user can start the Codex CLI from the user directory

Those are valid user actions. The bug is that `USERPROFILE` is too broad
a sandbox root.

## Change

This PR keeps the useful behavior of starting from the user profile
without granting the profile root itself.

The new flow is:

1. collect the normal read and write roots
2. if a root is exactly `USERPROFILE`, replace it with the direct
children of `USERPROFILE`
3. remove `USERPROFILE` itself from the final root list
4. apply the existing user-profile read exclusions to both read and
write roots
5. add `.tsh` and `.brev` to that exclusion list

So this input:

```text
C:\Users\me
```

becomes roots like:

```text
C:\Users\me\Desktop
C:\Users\me\Documents
C:\Users\me\Downloads
```

and does not include:

```text
C:\Users\me
C:\Users\me\.ssh
C:\Users\me\.tsh
C:\Users\me\.brev
```

If `USERPROFILE` cannot be listed, expansion falls back to the profile
root and the later filter removes it. That keeps the failure mode closed
for this bug.

## Why this shape

The sandbox still gets access to ordinary profile folders when the user
starts from home.

The sandbox no longer grants access to the profile root itself.

All filtering happens after expansion, for both read and write roots.
That gives us one simple rule: expand broad profile grants first, then
remove roots the sandbox must not own.

## Tests

- `just fmt`
- `cargo test -p codex-windows-sandbox`
- `just fix -p codex-windows-sandbox`
- `git diff --check`
Base automatically changed from efrazer/windows-sandbox-block-profile-root to main April 19, 2026 20:59
@efrazer-oai
efrazer-oai force-pushed the efrazer/windows-sandbox-ssh-dependency-roots-v2 branch from 6a8fe3b to abd3f86 Compare April 19, 2026 21:02
@efrazer-oai
efrazer-oai merged commit b885c3f into main Apr 19, 2026
46 of 47 checks passed
@efrazer-oai
efrazer-oai deleted the efrazer/windows-sandbox-ssh-dependency-roots-v2 branch April 19, 2026 21:58
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants