Skip to content

fix: canonicalize the writeable paths used in seatbelt policy - #275

Merged
tibo-openai merged 1 commit into
openai:mainfrom
jonchurch:canonicalize-writeable-roots
Apr 18, 2025
Merged

tibo-openai merged 1 commit into
openai:mainfrom
jonchurch:canonicalize-writeable-roots

Conversation

@jonchurch

@jonchurch jonchurch commented Apr 17, 2025 •

Copy link
Copy Markdown
Contributor

closes #207

I'd be lying if I said I was familiar with these particulars more than a couple hours ago, but after investigating and testing locally, this does fix the go issue, I prefer it over #272 which is a lot of code and a one off fix

cc @bolinfest do you mind taking a look here?

  1. Seatbelt compares the paths it gets from the kernal to its policies
  2. Go is attempting to write to the os.tmpdir, which we have allowlisted.
  3. The kernel rewrites /var/… to /private/var/… before the sandbox check.
  4. The policy still said /var/…, so writes were denied.

Fix: canonicalise every writable root we feed into the policy (realpathSync(...)).
We do not have to touch runtime file paths—the kernel already canonicalises those.

before

see that the command exited 1, and that the command was reported to be prohibited, despite using the allowlisted tmpdir

fail_go.mov

after

command exits 0

success_go.mov

@jonchurch

This comment was marked as off-topic.

@tibo-openai

Copy link
Copy Markdown
Collaborator

Deferring to @fouad-openai for review here, but this looks like the proper fix to me.

@tibo-openai

Copy link
Copy Markdown
Collaborator

@fouad-openai I have tested this locally and this works as expected. Will merge now but please revert if you see issues with this in the future.

@tibo-openai
tibo-openai merged commit 3356ac0 into openai:main Apr 18, 2025
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 18, 2025
@bolinfest

Copy link
Copy Markdown
Collaborator

I have concerns with this PR:

  • Without testing, it is not 100% clear to me that this fixes your specific problem without creating problems for a number of other people. For example, if I have a symlink like ~/myrepo, which is a symlink to one of multiple clones of my repo (~/src/myrepo1, ~/src/myrepo2, etc.) and I start Codex in ~/myrepo, will canonicalizing the path screw things up? Because the agent is likely to spawn commands with paths relative to ~/myrepo.
  • This uses realpathSync(). In general, we try to avoid blocking I/O calls in our codebase.
  • You call this in execWithSeatbelt(), which means the canonicalization is done every time Seatbelt is used as opposed to just doing it one time at the start of the agent loop.

A workaround would be to use the new -w flag I introduced in #263 with -w $GOTMPDIR or -w $(realpath $GOTMPDIR) or however things work in Go. (Sorry, I don't write Go.)

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.

bug: full auto mode cannot build Go code

3 participants