Repository navigation
feat: enforce allow_git through permissions - #17036
viyatb-oai wants to merge 7 commits into
Conversation
3c27416 to
1cbe335
Compare
|
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. |
|
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. |
|
@codex review |
There was a problem hiding this comment.
💡 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".
| } 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)); |
There was a problem hiding this comment.
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 👍 / 👎.
| 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)); |
There was a problem hiding this comment.
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 👍 / 👎.
| // 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)); |
There was a problem hiding this comment.
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 👍 / 👎.
| #[serde(default)] | ||
| pub allow_limited_git_writes: bool, |
There was a problem hiding this comment.
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 👍 / 👎.
| // 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)); |
There was a problem hiding this comment.
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 👍 / 👎.
| // 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)); |
There was a problem hiding this comment.
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 👍 / 👎.
| } | ||
|
|
||
| fn protected_git_subpaths_when_writable(gitdir: &AbsolutePathBuf) -> Vec<AbsolutePathBuf> { | ||
| ["config", "hooks"] |
There was a problem hiding this comment.
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 👍 / 👎.
dae5690 to
8980fd1
Compare
461a095 to
74b704d
Compare
Co-authored-by: Codex [email protected]
Co-authored-by: Codex [email protected]
Co-authored-by: Codex [email protected]
Co-authored-by: Codex [email protected]
Co-authored-by: Codex [email protected]
Co-authored-by: Codex [email protected]
Co-authored-by: Codex [email protected]
74b704d to
e4272f9
Compare
|
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. |
Stack
allow_gitpermissions and requirements setting built on that runtime support.Why
allow_gitis 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
allow_gitunder permissions filesystem config, including requirements-level[permissions.filesystem], so it can be enforced across profile selection and runtime profile updates.allow_gitonto the internal limited Git write sandbox policy from feat: allow limited git writes in workspace sandbox #25664.:workspace_rootsrules for.git: managed requirements remove conflicting writes to protected Git config/hooks paths, and disabling the managed setting re-protects all.gitmetadata.[sandbox_workspace_write].allow_git; legacy sandbox policy structs keep only the internal plumbing needed by app-server and platform lowerers.Security
allow_gitdoes not imply network access, sogit pushstill 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 fmtjust clippy -p codex-coreFixes #15505