-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix: realpathSafe to safely resolve symlinks for seatbelt #378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
d72cf59
to
f63d267
Compare
Ty for persisting and fixing this for others. CI looks like it's failing, but will merge once that is fixed! |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
@tibo-openai I do think that some extra opinions on this change is warranted, if you have any macos greybeards you can ping to look at this seatbelt policy, that would go pretty far. The specifics here are not something Im confident in beyond what I have been able to test |
Deferring to @bolinfest for the review here |
@jonchurch thanks for your detailed investigation on this! Here's what I think we should do: Since #263 already elevated As for the set of default writable roots, based on your investigation, I would only do it for macOS and I would NOT try/catch because if const writableRoots = [
process.cwd(),
// Comment here explaining why...should probably link to this PR?
process.platform === 'darwin' ? await realpath(os.tmpdir()) : os.tmpdir(),
...additionalWritableRoots,
];
Though I am curious if, for some reason, we need both codex/codex-cli/tests/agent-project-doc.test.ts Lines 92 to 93 in 081786e
I'm pretty sure full-auto mode has also worked with Rust tests that write to $TMPDIR via https://crates.io/crates/tempfile. So perhaps the issue is "specific to Go" insofar as Go does I just want to be sure we don't fix something for Go and break the other languages. |
@jonchurch just checking in: were you planning on following up on this PR? Since you did a lot of the investigation, I think it would be great to make the suggested changes and get this in. |
This is a followup to #370 and #275
It fixes #330
And also integrates feedback from @bolinfest (ty for the very good feedback!)
I tested w/ a symlinked cwd, and in both versions (w/ and w/o realpath) they succeeded for reading/writing in the cwd. Which surprised me, tbh. I expected that it would fail w/o the realpath resolution.
Seatbelt is apparently poorly documented, or rather the implementation and policy language is considered apple internal. Im reading reverse engineer documents and bug reports to wayfind here 🤣 The bug we were fixing for originally of
/var
needed to be resolved in the policy to/private/var
is an edgecase that I have read about (yes Im using AI to accelerate this understanding, buyer beware) and seems to be known.Edit to add: Didnt make this clear, we are not touching userland paths. We are only altering the paths we add to the policy, for comparison against what the kernel hands to seatbelt for checking.
addressed the sync. I did sync originally bc I missed that the function was returning
Promise<ExecResult>
, saw the lack of async keyword on the func and thought I was making the least invasive change.As for caching it, yeah I can do that if desired. This isn't what I'd call a hotpath, but if the additional complexity is worth trimming the waste here in your mind I can do that. We have minute long network calls making up most of the latency in this application. Strong opinion held weakly on my end.
The issue here is that writing to macos tmpdir is currently broken without the realpath change. The agent cannot write to it, nor the software it invokes. Im not a go dev either, but the particulars are generic to tmp dir writeability.
Try it out on a mac:
A targetted fix would be to realpath just the tmp dir and play whackamole as new reports come in w/ other edgecaes (which is fully valid). I can make that change if desired.