Skip to content

fix(security): refuse the git keys that make git run a program - #2641

Merged
dan-petty merged 9 commits into
mainfrom
fix/2483-refuse-git-code-env-keys
Oct 29, 2026
Merged

dan-petty merged 9 commits into
mainfrom
fix/2483-refuse-git-code-env-keys

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

build_subprocess_env refused no git key. A caller override of GIT_CONFIG_COUNT with its pairs, GIT_SSH_COMMAND, GIT_CONFIG_GLOBAL or GIT_EXEC_PATH made a git child run a program that the caller did not choose. The ambient allowlist also passed GIT_CONFIG_GLOBAL, GIT_CONFIG_SYSTEM, GIT_EXEC_PATH, EDITOR and PAGER to an isolated child.

  • The guard refuses each GIT_ key of a caller, but the five keys that callers set and that run no program: GIT_TERMINAL_PROMPT, GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL. A list of names missed keys that run a program, for example GIT_TEST_FSMONITOR, GIT_ALLOW_PROTOCOL and GIT_DIFFTOOL_EXTCMD. A key that git adds later stays refused until a person reviews it.
  • The guard also refuses EDITOR, VISUAL, PAGER, LESSOPEN, LESSCLOSE and MERGE_TOOLS_DIR. XDG_CONFIG_HOME stays accepted, because devops openspec sets it.
  • DEFAULT_ALLOWED_ENV_VARS no longer holds GIT_CONFIG_GLOBAL, GIT_CONFIG_SYSTEM, GIT_EXEC_PATH, EDITOR and PAGER. Thus no refused key reaches an isolated child from the environment.
  • The Argo CD fetch of render_at_revision gets its SSH option as git -c core.sshCommand=ssh -o BatchMode=yes. Its environment keeps only GIT_TERMINAL_PROMPT=0. This replaces the post-guard GIT_SSH_COMMAND step of criterion 3 of the issue, because the result is the same and the guard keeps no exception.
  • The three git config --global calls name GIT_CONFIG_GLOBAL in extra_allowed_env, so that they write the file that the person set.
  • ARCHITECTURE.md and the subprocess-environment spec describe the git keys. Follow-up for the SSH keys: fix(security): the subprocess environment guard accepts the ssh keys that make an ssh child run a program #2633.

Change: openspec/changes/archive/2026-10-29-2483-refuse-git-code-env-keys/

Closes #2483

…2483)

Plans #2483. The change adds the git keys that make git run a program to the
caller override guard, removes five ambient keys from the isolated child
environment, and moves the SSH option of the Argo CD fetch to the arguments of git.
…ogram (#2483)

The tests fail on main for the right reason: the guard accepts each git key, and
an isolated child gets the ambient GIT_CONFIG_GLOBAL, GIT_CONFIG_SYSTEM,
GIT_EXEC_PATH, EDITOR and PAGER. Two tests pin what the fix must keep: the SSH
option of the Argo CD fetch, and the global git file of git config --global.
build_subprocess_env refused no git key, so a caller override of GIT_CONFIG_COUNT
with its pairs, GIT_SSH_COMMAND, GIT_CONFIG_GLOBAL or GIT_EXEC_PATH made a git
child run a program. The guard now refuses these keys and the other keys that
git documents as a program, a configuration file or a directory of hooks.

- An isolated child no longer gets GIT_CONFIG_GLOBAL, GIT_CONFIG_SYSTEM,
  GIT_EXEC_PATH, EDITOR or PAGER from the environment.
- The Argo CD fetch gets its SSH option as git -c core.sshCommand, and its
  environment keeps only GIT_TERMINAL_PROMPT.
- The git config --global calls name GIT_CONFIG_GLOBAL in extra_allowed_env, so
  they write the file that the person set.

Closes #2483
The test imported the private _run_cmd of the cluster runtime. It now starts
git with the public run_subprocess, and the recorder types its env parameter,
so it needs no type ignore.
…not set (#2483)

A review found keys that run a program and that the list of names missed:
GIT_TEST_FSMONITOR, GIT_TEST_MAINT_SCHEDULER, GIT_ALLOW_PROTOCOL,
GIT_DIFFTOOL_EXTCMD, MERGE_TOOLS_DIR, LESSOPEN and LESSCLOSE, and the GIT_TRACE
keys that write a file of the caller. The tests refuse each one, with a key that
no page lists, GIT_EXAMPLE_KEY, to pin the rule that a GIT_ key is refused unless
the guard accepts it. A new test pins that no key of the ambient allowlist is
refused.
…ot set (#2483)

A list of names missed keys that run a program: GIT_TEST_FSMONITOR,
GIT_TEST_MAINT_SCHEDULER, GIT_ALLOW_PROTOCOL, GIT_DIFFTOOL_EXTCMD and
MERGE_TOOLS_DIR. It also let GIT_TRACE write a file that the caller names, and
it missed LESSOPEN, which makes the pager of git run a program.

- CONST_CODE_LOADING_ENV_PATTERNS holds GIT_*, and CONST_GIT_ACCEPTED_ENV names
  the five keys that callers set and that run no program.
- The guard also refuses MERGE_TOOLS_DIR, LESSOPEN and LESSCLOSE.
- XDG_CONFIG_HOME stays accepted, because devops openspec sets it.
…sentences (#2483)

The design records the rule, the accepted keys, XDG_CONFIG_HOME, the trace keys
and the replacement of criterion 3 of the issue. The evidence of the rejected
pin names the code that acts on every git child. ARCHITECTURE.md has a bullet for
the git child environment.
@dan-petty dan-petty added scope/security Security linters (trivy, bandit, gitleaks, kubeconform) and Vault type/security Type security: a vulnerability or a leak labels Oct 29, 2026
@dan-petty

Copy link
Copy Markdown
Owner Author

Test results of the branch, on git 2.55.0.

  • Targeted tests: 1024 passed in 12 files: tests/test_subprocess_env_boundary.py, tests/test_review_rules_pack.py, tests/test_k8s_argocd_overrides.py, tests/test_devcontainer.py, tests/test_ssh.py, tests/test_k8s_deploy_stack_urls.py, tests/test_tool_executor_contract.py, tests/test_ci.py, tests/test_cli_startup_imports.py, tests/test_architectural_invariants.py, tests/test_process.py and tests/test_process_contract.py.
  • ruff check, ruff format --check, devops openspec check and devops docs check pass.
  • Fail-to-pass, devops ci fail-to-pass --base origin/main: 138 tests fail on the base tree, 402 pass, 0 error. Each failing test is a refusal of a key, the check that an isolated child gets no refused key, or the check of the fetch arguments.
138 failed on base (138 failed and 402 passed in tests/test_devcontainer.py, tests/test_k8s_argocd_overrides.py, tests/test_subprocess_env_boundary.py; 0 errored).

Examples of the failures on the base tree:

failed on base: tests.test_subprocess_env_boundary::test_a_caller_override_that_loads_code_into_the_child_is_refused[GIT_TEST_FSMONITOR-isolated] (Failed: DID NOT RAISE SecurityError)
failed on base: tests.test_subprocess_env_boundary::test_a_caller_override_that_loads_code_into_the_child_is_refused[GIT_ALLOW_PROTOCOL-not-isolated] (Failed: DID NOT RAISE SecurityError)
failed on base: tests.test_subprocess_env_boundary::test_a_caller_override_that_loads_code_into_the_child_is_refused[LESSOPEN-isolated] (Failed: DID NOT RAISE SecurityError)
failed on base: tests.test_subprocess_env_boundary::test_an_isolated_child_gets_no_refused_key_from_the_environment (AssertionError)
failed on base: tests.test_k8s_argocd_overrides::test_only_the_fetch_gets_the_ssh_option_and_every_command_gets_only_the_prompt_switch (AssertionError)

Two tests pass on the base tree, and they pin what the fix keeps: the SSH option of the Argo CD fetch reaches ssh, and git config --global writes the file that GIT_CONFIG_GLOBAL names.

…#2483)

Bandit B108 flagged two /tmp paths in the test of the accepted git keys, and the
Static Analysis check failed. The paths now come from tmp_path.
@dan-petty
dan-petty marked this pull request as ready for review October 29, 2026 14:22
@dan-petty
dan-petty merged commit b4b1277 into main Oct 29, 2026
17 checks passed
@dan-petty
dan-petty deleted the fix/2483-refuse-git-code-env-keys branch October 29, 2026 14:33
dan-petty-release Bot added a commit that referenced this pull request Oct 29, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.16.2](v0.16.1...v0.16.2)
(2026-10-29)


### Bug Fixes

* **security:** refuse the git keys that make git run a program
([#2641](#2641))
([b4b1277](b4b1277)),
closes [#2483](#2483)

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope/security Security linters (trivy, bandit, gitleaks, kubeconform) and Vault type/security Type security: a vulnerability or a leak

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(security): the subprocess environment guard accepts the git keys that make a git child run a program

1 participant