Skip to content

feat: enforce allow_git through permissions - #17036

Closed
viyatb-oai wants to merge 7 commits into
codex/viyatb/allow-limited-git-writes-runtimefrom
codex/viyatb/allow-limited-git-writes
Closed

viyatb-oai wants to merge 7 commits into
codex/viyatb/allow-limited-git-writes-runtimefrom
codex/viyatb/allow-limited-git-writes

Conversation

@viyatb-oai

@viyatb-oai viyatb-oai commented Apr 7, 2026 •

Copy link
Copy Markdown
Contributor

Stack

  1. feat: allow limited git writes in workspace sandbox #25664: runtime sandbox support for limited Git metadata writes.
  2. This PR: ergonomic allow_git permissions and requirements setting built on that runtime support.

Why

allow_git is the ergonomic user-facing switch on top of the runtime limited Git write sandbox support in #25664. It lets requirements and permission profiles ask for Git metadata writes without exposing another [sandbox_workspace_write] knob.

What changed

  • Adds allow_git under permissions filesystem config, including requirements-level [permissions.filesystem], so it can be enforced across profile selection and runtime profile updates.
  • Maps allow_git onto the internal limited Git write sandbox policy from feat: allow limited git writes in workspace sandbox #25664.
  • Keeps the default restrictive behavior unchanged unless the permission or requirements setting opts in.
  • Handles explicit :workspace_roots rules for .git: managed requirements remove conflicting writes to protected Git config/hooks paths, and disabling the managed setting re-protects all .git metadata.
  • Does not add [sandbox_workspace_write].allow_git; legacy sandbox policy structs keep only the internal plumbing needed by app-server and platform lowerers.

Security

allow_git does not imply network access, so git push still depends on the active network policy. It also does not make Git config or hooks writable. Managed requirements win over local profile entries that try to write those protected paths.

Validation

  • just fmt
  • just clippy -p codex-core

Fixes #15505

@viyatb-oai
viyatb-oai force-pushed the codex/viyatb/allow-limited-git-writes branch from 3c27416 to 1cbe335 Compare April 7, 2026 20:17
@viyatb-oai viyatb-oai changed the title [codex] Allow limited Git writes in workspace sandbox feat: alow limited git writes in workspace sandbox Apr 7, 2026
@viyatb-oai viyatb-oai changed the title feat: alow limited git writes in workspace sandbox feat: allow limited git writes in workspace sandbox Apr 7, 2026
@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.

@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.

@github-actions github-actions Bot closed this May 16, 2026
@viyatb-oai viyatb-oai reopened this May 27, 2026
@viyatb-oai
viyatb-oai marked this pull request as ready for review May 27, 2026 20:05
@viyatb-oai
viyatb-oai requested a review from a team as a code owner May 27, 2026 20:05
@viyatb-oai

Copy link
Copy Markdown
Contributor Author

@codex review

@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: 8a7300e345

ℹ️ 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 +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 repo config/hooks at the gitdir root

When allow_limited_git_writes is enabled for a bare repository whose writable root is the gitdir itself, this branch still protects <root>/.git/config and <root>/.git/hooks. Bare repos store config and hooks/ directly under the gitdir root, so the actual sensitive paths remain writable even though the permission model promises they stay read-only. This affects users running Codex from or granting write access to a bare repo.

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.

P2 Badge Keep gitdir pointer files read-only

For worktrees and submodules where .git is a gitdir: pointer file, this resolves the current gitdir and protects that gitdir’s config and hooks, but it leaves the pointer file itself writable. In a writable worktree, the sandboxed command can replace .git to point at a gitdir it controls, then subsequent Git commands use that unprotected config/hooks tree, bypassing the carveout this option is meant to preserve.

Useful? React with 👍 / 👎.

Comment thread codex-rs/protocol/src/permissions.rs Outdated
Comment on lines +1603 to +1605
// 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 nested submodule gitdirs

When the writable root is a normal superproject, submodule gitdirs live under .git/modules/<submodule>/, but limited Git writes only add read-only carveouts for the top-level .git/config and .git/hooks. That leaves .git/modules/*/config and .git/modules/*/hooks writable from the superproject sandbox, so an agent can still alter submodule-local config or hooks even though these are the same sensitive Git surfaces the new flag is intended to keep read-only.

Useful? React with 👍 / 👎.

Comment thread codex-rs/config/src/permissions_toml.rs Outdated
Comment on lines +236 to +237
#[serde(default)]
pub 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 Preserve inherited limited-git-write settings

Because this new field is a plain bool with serde(default), profile inheritance cannot distinguish an omitted child value from an explicit false: merge_permission_profiles serializes the deserialized child profile before merging, so any child [filesystem] table that adds entries but omits allow_limited_git_writes overwrites a parent profile’s true setting with false. This makes extending a profile that enables limited Git writes silently disable the feature.

Useful? React with 👍 / 👎.

Comment thread codex-rs/protocol/src/permissions.rs Outdated
Comment on lines +1603 to +1605
// 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 Avoid masking parent repos on Linux

When allow_limited_git_writes is enabled in a writable subdirectory of a parent Git repo that has no child .git, these missing .git/config and .git/hooks carveouts are passed to bwrap. The bwrap builder handles a missing read-only subpath by mounting the first missing component, so it creates an empty read-only .git directory and prevents Git inside the sandbox from discovering the parent repository.

Useful? React with 👍 / 👎.

Comment thread codex-rs/protocol/src/permissions.rs Outdated
Comment on lines +1603 to +1605
// 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 Materialize missing Git carveouts on Windows

These new missing-path protections are not enforced by the Windows sandbox because compute_allow_paths_for_permissions only adds deny-write paths that already exist. In a workspace without .git yet, or with a missing hooks directory, no deny ACL is installed for the emitted .git/config/.git/hooks paths, so the sandboxed process can create exactly the protected config or hook path later.

Useful? React with 👍 / 👎.

Comment thread codex-rs/protocol/src/permissions.rs Outdated
}

fn protected_git_subpaths_when_writable(gitdir: &AbsolutePathBuf) -> Vec<AbsolutePathBuf> {
["config", "hooks"]

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 Treat config.worktree as protected Git config

Protecting only config leaves $GIT_DIR/config.worktree writable in repositories that have extensions.worktreeConfig enabled; Git reads that file as worktree-specific config and git config --worktree core.hooksPath ... writes there. In that scenario an agent can still change repo-local Git configuration, including hook configuration, despite the limited-write mode promising that Git config remains read-only.

Useful? React with 👍 / 👎.

@viyatb-oai viyatb-oai changed the title feat: allow limited git writes in workspace sandbox feat: enforce limited Git writes through permissions Jun 1, 2026
@viyatb-oai viyatb-oai changed the title feat: enforce limited Git writes through permissions feat: enforce allow_git through permissions Jun 1, 2026
@viyatb-oai
viyatb-oai changed the base branch from main to codex/viyatb/allow-limited-git-writes-runtime June 1, 2026 18:19
@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
@viyatb-oai
viyatb-oai force-pushed the codex/viyatb/allow-limited-git-writes branch 3 times, most recently from 461a095 to 74b704d Compare June 1, 2026 22:59
@viyatb-oai
viyatb-oai force-pushed the codex/viyatb/allow-limited-git-writes branch from 74b704d to e4272f9 Compare June 1, 2026 23:42
@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.

.git is mounted read-only even though Codex is configured for workspace-write

1 participant