Skip to content

feat: allow limited git writes in workspace sandbox - #25664

Closed
viyatb-oai wants to merge 5 commits into
mainfrom
codex/viyatb/allow-limited-git-writes-runtime
Closed

viyatb-oai wants to merge 5 commits into
mainfrom
codex/viyatb/allow-limited-git-writes-runtime

Conversation

@viyatb-oai

@viyatb-oai viyatb-oai commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

Stack

  1. This PR: runtime sandbox support for limited Git metadata writes.
  2. feat: enforce allow_git through permissions #17036: ergonomic allow_git permissions and requirements setting built on this runtime support.

Why

Codex needs a sandbox policy shape that lets Git update repository metadata without making repository-local execution or configuration surfaces writable.

What changed

  • Adds internal limited Git write support to workspace-write sandbox policy plumbing.
  • Allows Git metadata writes while keeping .git/config, .git/hooks, and linked-worktree <gitdir>/config / <gitdir>/hooks read-only.
  • Projects linked-worktree gitdirs into the platform sandbox roots so seatbelt, bwrap/Landlock, and Windows lowering all see the same policy.
  • Carries the internal setting through app-server protocol/config surfaces needed by running sessions.

Security

This does not grant network access. Git config and hooks remain protected, so this enables local metadata updates without allowing repository-local config or hook mutation.

Validation

  • just fmt
  • just clippy -p codex-core (run on the stacked branch after the CI compile fix)

Part of #15505

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dae5690232

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codex-rs/protocol/src/permissions.rs Outdated
Comment on lines +1597 to +1600
if is_git_pointer_file(&top_level_git)
&& let Some(gitdir) = resolve_gitdir_from_file(&top_level_git)
{
subpaths.extend(protected_git_subpaths_when_writable(&gitdir));

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.

P1 Badge Add the linked gitdir as a writable root

When allow_limited_git_writes is enabled for a linked worktree, this branch only records <gitdir>/config and <gitdir>/hooks as read-only carveouts, but it never grants write access to the resolved <gitdir> itself. The platform lowerings I inspected (e.g. bwrap binds only each WritableRoot.root before re-applying read_only_subpaths) treat these subpaths as exclusions, not write grants, so a normal linked worktree whose .git file points outside the workspace still cannot update HEAD, index, or lock files in the actual gitdir. This means the new “limited git writes” mode works for directory .git repos but still fails for linked worktrees, which is one of the scenarios this code path is meant to support.

Useful? React with 👍 / 👎.

Comment on lines 451 to +452
#[serde(default)]
allow_limited_git_writes: bool,

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.

P2 Badge Keep the new v2 field optional for clients

For app-server v2 clients that consume the generated TypeScript, adding this boolean without a TS optional annotation makes the workspaceWrite variant require allowLimitedGitWrites (as generated in schema/typescript/v2/SandboxPolicy.ts), even though serde still accepts old JSON because of the default. Existing clients that construct a sandboxPolicy for command/exec or turn/start now fail to compile until they know about this new flag. Please make the new field optional in the TS surface, or otherwise avoid making an additive defaulted server field a required client-side property.

Useful? React with 👍 / 👎.

Comment thread codex-rs/core/src/config/permissions.rs Outdated
Comment on lines +316 to +319
file_system_sandbox_policy.allow_limited_git_writes = profile
.filesystem
.as_ref()
.is_some_and(|filesystem| filesystem.allow_limited_git_writes);

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.

P2 Badge Preserve inherited limited-Git-write settings

When a custom permission profile inherits a filesystem profile that set allow_limited_git_writes = true, a child profile that adds its own [filesystem] entries but omits this new flag is deserialized with the default false, and this assignment then overwrites the inherited runtime policy. That makes limited Git writes disappear merely because the child adds another filesystem rule. The flag needs to distinguish “omitted” from “explicitly false” during profile merging/compilation so inherited profiles keep their setting unless the child overrides it.

Useful? React with 👍 / 👎.

Comment thread codex-rs/protocol/src/permissions.rs Outdated
Comment on lines +1597 to +1600
if is_git_pointer_file(&top_level_git)
&& let Some(gitdir) = resolve_gitdir_from_file(&top_level_git)
{
subpaths.extend(protected_git_subpaths_when_writable(&gitdir));

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.

P1 Badge Keep linked-worktree .git pointer files read-only

For worktrees/submodules where .git is a pointer file, this branch protects only the resolved gitdir’s config and hooks but leaves the .git file itself writable under allow_limited_git_writes. In a writable workspace the agent can rewrite that pointer to a gitdir it controls, after which later Git commands read config/hooks from the new location and bypass the protected paths. The pointer file needs to stay read-only while the actual gitdir metadata is made writable.

Useful? React with 👍 / 👎.

Comment thread codex-rs/protocol/src/permissions.rs Outdated
Comment on lines +1602 to +1605
} else {
// Git metadata remains writable, but these execution surfaces do
// not become writable merely because `.git` is created later.
subpaths.extend(protected_git_subpaths_when_writable(&top_level_git));

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.

P2 Badge Protect bare-repository config and hooks

When the writable root is itself a bare Git repository, there is no .git child; the sensitive files are <root>/config and <root>/hooks. This branch falls into the missing-.git path and protects <root>/.git/config and <root>/.git/hooks instead, so bare repos run with allow_limited_git_writes still allow modifying their real config and hooks. The bare-repo case called out in the comment needs to add carveouts for the root gitdir itself.

Useful? React with 👍 / 👎.

@viyatb-oai
viyatb-oai force-pushed the codex/viyatb/allow-limited-git-writes-runtime branch from dae5690 to 8980fd1 Compare June 1, 2026 21:02
@github-actions

Copy link
Copy Markdown
Contributor

Closing this pull request because it has had no updates for more than 14 days. If you plan to continue working on it, feel free to reopen or open a new PR.

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.

1 participant