diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md
index 74298f06dc..3799d4da6b 100644
--- a/ARCHITECTURE.md
+++ b/ARCHITECTURE.md
@@ -178,7 +178,8 @@ All external binaries run through `run_subprocess` / `run_subprocess_async` (`de
- Explicit bounded timeouts (default 1800 s) with standardized `TimeoutExpired` domain error translation.
- An audit-record writer (`devops_cli.core.audit.record_audit_event`, `.data/logs/audit.jsonl`) records each write of a config file (`save_settings`). It is not yet called from command or subprocess execution.
- Deterministic mock isolation protocols for fast offline unit testing, dry-run reporting, environment isolation, and OpenTelemetry spans.
-- **Child environment**: With `isolate_env=True`, the default, `build_subprocess_env` gives a child the allowed keys of the environment, without credentials. With `isolate_env=False`, it gives the full environment, credentials included. It puts the `env` of the caller on top. It refuses with `SecurityError` a caller key that `CONST_CODE_LOADING_ENV_PATTERNS` lists. The list holds the loader keys of glibc and macOS, `GCONV_PATH`, and the keys of bash and zsh that run code. It also holds the keys of Python, Node.js, Perl, Ruby and Java that load code. An isolated child gets none of these keys from the environment, unless the caller names the key in `extra_allowed_keys` (`extra_allowed_env` of `run_subprocess`). Some keys that make a child run code still reach the child. `HOME` is one: zsh and Python read start-up files below it, so a caller that sets `HOME` gives a directory that it controls. The git keys that make git run a program are others, for example `GIT_SSH_COMMAND` and `GIT_CONFIG_GLOBAL` (#2483). The library keys that make a library load a module are others, for example `OPENSSL_CONF` (#2503). `build_subprocess_env` also refuses a null byte in a caller key or value. Give a child only the keys that it needs, never a copy of `os.environ`.
+- **Child environment**: With `isolate_env=True`, the default, `build_subprocess_env` gives a child the allowed keys of the environment, without credentials. With `isolate_env=False`, it gives the full environment, credentials included. It puts the `env` of the caller on top. It refuses with `SecurityError` a caller key that `CONST_CODE_LOADING_ENV_PATTERNS` lists. The list holds the loader keys of glibc and macOS, `GCONV_PATH`, and the keys of bash and zsh that run code. It also holds the keys of Python, Node.js, Perl, Ruby and Java that load code, and the git keys of the next bullet. An isolated child gets none of these keys from the environment, unless the caller names the key in `extra_allowed_keys` (`extra_allowed_env` of `run_subprocess`). Some keys that make a child run code still reach the child. `HOME` is one: zsh and Python read start-up files below it, so a caller that sets `HOME` gives a directory that it controls. `XDG_CONFIG_HOME` is another: git reads its configuration below it, and `devops openspec` sets it. The library keys that make a library load a module are others, for example `OPENSSL_CONF` (#2503). `build_subprocess_env` also refuses a null byte in a caller key or value. Give a child only the keys that it needs, never a copy of `os.environ`.
+- **Git child environment**: The guard refuses each `GIT_` key of a caller, but `GIT_TERMINAL_PROMPT` and the author and committer keys (#2483). Git reads configuration, programs and hooks from the other keys. A key that git adds later stays refused until a person reviews it. The guard also refuses `EDITOR`, `VISUAL`, `PAGER` and `LESSOPEN`, which a git child uses. A caller that must give git an option puts it in the arguments, for example `git -c core.sshCommand=...`, and never in the environment. The `git config --global` calls name `GIT_CONFIG_GLOBAL` in `extra_allowed_env`, so that they write the file that the person set.
- **Subprocess spans**: A subprocess span holds the program and the number of its arguments. It holds the arguments only when `telemetry.capture_command_args` turns them on ([docs/TELEMETRY.md](docs/TELEMETRY.md)).
- **LLM inference spans**: AI inference spans omit prompt and response previews by default, and Logfire scrubs private host patterns. They record previews only when `telemetry.capture_llm_content` turns them on ([docs/TELEMETRY.md](docs/TELEMETRY.md)).
- **Process groups**: Start a child with `start_new_session=True`, and stop it by its process group (`os.killpg`), as `_terminate_process_group` in `src/devops_cli/sandbox/host.py` does. Do not signal a pid below 2, the own process group (`os.getpgrp()`) or a process group below 2.
diff --git a/openspec/changes/archive/2026-10-29-2483-refuse-git-code-env-keys/.openspec.yaml b/openspec/changes/archive/2026-10-29-2483-refuse-git-code-env-keys/.openspec.yaml
new file mode 100644
index 0000000000..5c99d6d744
--- /dev/null
+++ b/openspec/changes/archive/2026-10-29-2483-refuse-git-code-env-keys/.openspec.yaml
@@ -0,0 +1,2 @@
+schema: spec-driven
+created: 2026-10-29
diff --git a/openspec/changes/archive/2026-10-29-2483-refuse-git-code-env-keys/design.md b/openspec/changes/archive/2026-10-29-2483-refuse-git-code-env-keys/design.md
new file mode 100644
index 0000000000..eb9392f3f6
--- /dev/null
+++ b/openspec/changes/archive/2026-10-29-2483-refuse-git-code-env-keys/design.md
@@ -0,0 +1,39 @@
+# Design
+
+## Decisions
+
+- **The sources are the git manuals, the git source and sudo.** The sudo table removes `GIT_SSH_COMMAND` and the `GIT_CONFIG_*` family before sudo runs a program for another user. The table is `initial_badenv_table` of `plugins/sudoers/env.c`. The pages `git(1)`, `git-config(1)`, `git-init(1)`, `git-var(1)` and `less(1)` name more keys. The source of git names the keys that only its tests and scripts use. A probe with git 2.55.0 and a temporary `HOME` confirms each refused key (proposal, Feasibility).
+- **A `GIT_` key is refused unless the guard accepts it.** The first list had 21 names, and a review found five more keys that run a program. A list of names stays incomplete when git adds a key. The constant now holds the pattern `GIT_*`, and `CONST_GIT_ACCEPTED_ENV` names the exceptions. The refine of #2483 rejected this rule, because it blocks a safe key until a review. That review is the wanted effect, and a new key costs one line.
+- **Five git keys are accepted.** They are the keys that callers set and that run no program: `GIT_TERMINAL_PROMPT` and the author and committer keys. `roadmap/refine.py`, `roadmap/refine_investigation.py`, `ai/review/samples.py` and `CONST_GIT_NONINTERACTIVE_ENV` set `GIT_TERMINAL_PROMPT`. A tool request sets the author and the committer in `tests/test_tool_executor_contract.py`. `GIT_SSH_VARIANT` and `GIT_CONFIG_NOSYSTEM` run no program, but no caller sets them. Thus the guard refuses them until a caller needs one.
+- **The trace keys are refused.** `GIT_TRACE`, `GIT_TRACE2` and `GIT_TRACE_CURL` append to a file that the caller names. The trace line holds the arguments of the git command. A newline in an argument then puts a line of the caller into an existing file. A caller has no reason to set these keys.
+- **The other refused keys are in the constant by name.** `EDITOR`, `VISUAL` and `PAGER` are the keys that git uses when `GIT_EDITOR`, `core.editor`, `GIT_PAGER` and `core.pager` are not set (`git-var(1)`). `LESSOPEN` and `LESSCLOSE` make `less`, the default pager, run a filter program (`less(1)`). `MERGE_TOOLS_DIR` names the directory from which `git-mergetool--lib` reads a shell file. Each key ran a program in a probe. No file of `src/` sets or reads them for a child, and no test sets one.
+- **No refused key reaches an isolated child from the environment.** `DEFAULT_ALLOWED_ENV_VARS` removes `GIT_CONFIG_GLOBAL`, `GIT_CONFIG_SYSTEM`, `GIT_EXEC_PATH`, `EDITOR` and `PAGER`. A test gives each allowed key as an override, so a key that a refused pattern matches fails it. #2429 removed `PYTHONPATH` and `PYTHONHOME` on the same ground. The default `env_reset` of sudo keeps neither `EDITOR` nor `PAGER`. A person who wants an ambient value uses `isolate_env=False` or the `extra_allowed_env` of a caller.
+- **`XDG_CONFIG_HOME` stays accepted.** `src/devops_cli/openspec/tool.py` sets it as a caller override, to a scratch directory that holds the configuration of `openspec`. The ambient lists for `gh` and for `go` hold it too (`CONST_GH_LOGIN_ENV_VARS`, `CONST_GO_HOST_ENV_VARIABLES`). A probe shows that git reads `$XDG_CONFIG_HOME/git/config`, so the key has the effect of the refused `GIT_CONFIG_GLOBAL`. It is the case of `HOME` below: a caller must be able to give a child its own configuration directory.
+- **The own override moves to the argument list of git.** `render_at_revision` passes `CONST_GIT_NONINTERACTIVE_ENV` as a caller override of `build_subprocess_env`. After the change the fetch is `git -C
-c core.sshCommand=ssh -o BatchMode=yes fetch ...`, and the environment holds only `GIT_TERMINAL_PROMPT=0`. The option `-c` beats the configuration files. The guard keeps no exception and no flag. With isolation on, an ambient `GIT_SSH_COMMAND` never reaches the child, so it cannot take precedence.
+- **This replaces criterion 3 of the issue.** The criterion asks for a child whose environment holds `GIT_SSH_COMMAND`, set by a post-guard step. It names a mechanism, not the result. The result is that `ssh` starts with `-o BatchMode=yes`, and a probe shows that `-c core.sshCommand` gives the same arguments. A post-guard step needs a flag or a program-wide pin, as the rejected alternatives show. The test of this change asserts the result with a stand-in `ssh` program.
+- **The `git config --global` calls name `GIT_CONFIG_GLOBAL`.** With the key out of the allowlist, `git config --global` writes `$HOME/.gitconfig`. Git of the person reads `GIT_CONFIG_GLOBAL` alone when it is set. The three calls give `extra_allowed_env=CONST_GIT_GLOBAL_CONFIG_ENV`: the signing keys of `ssh register` and `ssh rotate`, and the two defaults of `devcontainer post-start`. The value is the one that the person set, as the design of #2429 says for `extra_allowed_keys`. The `global_git_config` fixture of `tests/test_ssh.py` keeps working with no change.
+- **The constant keeps the length rule of #2433.** The comment above `CONST_CODE_LOADING_ENV_PATTERNS` stays at 25 words, and the change does not edit it. Each group of the git block has one short comment with its pages, for example `# less(1)`. The block sits between the zsh keys and the Python keys, and the test list follows the same order. A later change that appends a group at the end of the tuple (#2503) then merges with no conflict.
+- **The spec change only adds requirements.** The requirement "A caller override that loads code into the child is refused" names the loader and interpreter keys. A MODIFIED copy would conflict with #2503, which changes the same requirement. The new requirements add the git refusal, the accepted keys, the fetch, the global file and the allowlist rule. A delta cannot change a purpose, so the change edits the purpose line of `openspec/specs/subprocess-environment/spec.md` directly, as #2429 did.
+- **The tests are in the file of the behaviour.** `tests/test_subprocess_env_boundary.py` takes the refused keys in `REFUSED_OVERRIDE_KEYS`, so the tests of the override and of the ambient environment cover them. The fetch tests are in `tests/test_k8s_argocd_overrides.py`, and they start git with the public `run_subprocess`. The `git config --global` tests are in `tests/test_devcontainer.py` and the existing `tests/test_ssh.py`.
+
+## Rejected alternatives
+
+- **Pin `GIT_SSH_COMMAND` after the guard, as `_pin_github_token` pins `GH_TOKEN`.** The pin acts on the program name (`_github_client_name`), so it reaches every git child that `run_subprocess` starts, for example `git status` and `git config`. It replaces the `core.sshCommand` of the person in each of them. A pin for one call needs a flag on `run_subprocess`, which is the next alternative.
+- **Add a flag or a trusted-environment parameter to `build_subprocess_env`.** It weakens the guard for every caller, and a reviewer must audit each use of the flag.
+- **Accept `GIT_SSH_COMMAND` when its value is the exact constant of devops-cli.** It keeps one path, but the guard then holds an exception that the next caller extends. The argument list needs none.
+- **Check the value of `GIT_SSH_COMMAND`.** A new ssh option or another program name passes such a check, and the value is a shell command line.
+- **Refuse the git keys by name only.** The first version did so. A review found five keys that it missed, and git adds keys with each release.
+- **Keep `EDITOR` and `PAGER` in the allowlist and refuse them only as caller overrides.** A refused key then reaches an isolated child from the environment, which the spec requirement and its test forbid. No code needs the ambient keys.
+- **Find the global configuration file in Python for the `git config --global` calls.** It copies the lookup that git does (`GIT_CONFIG_GLOBAL`, then `$XDG_CONFIG_HOME/git/config`, then `~/.gitconfig`). `extra_allowed_env` lets git do the lookup.
+
+## Keys considered and accepted
+
+- `HOME` makes git read `$HOME/.gitconfig`, which can set `core.fsmonitor`. It has the effect of the refused `GIT_CONFIG_GLOBAL`. The guard accepts it, because a caller must be able to give a child its own home directory. `src/devops_cli/telemetry/semconv.py` sets it for `weaver`.
+- `XDG_CONFIG_HOME` is accepted for the reason in Decisions.
+- The five keys of `CONST_GIT_ACCEPTED_ENV` run no program and write no file.
+
+## Non-goals
+
+- The library keys that make a library of the child load a module, for example `OPENSSL_CONF`: #2503.
+- The keys of `ssh` that name a program, `SSH_ASKPASS` and `SSH_ASKPASS_REQUIRE`: #2633.
+- The keys of `gh` and `kubectl` that name a program, for example `GH_EDITOR` and `KUBE_EDITOR`: #2633 names them as candidates. No probe of them ran.
diff --git a/openspec/changes/archive/2026-10-29-2483-refuse-git-code-env-keys/proposal.md b/openspec/changes/archive/2026-10-29-2483-refuse-git-code-env-keys/proposal.md
new file mode 100644
index 0000000000..738cc01338
--- /dev/null
+++ b/openspec/changes/archive/2026-10-29-2483-refuse-git-code-env-keys/proposal.md
@@ -0,0 +1,68 @@
+# Proposal
+
+## Why
+
+Issue #2483: the subprocess environment guard accepts git keys that make a git child run a program that its caller did not choose.
+
+- `build_subprocess_env` in `src/devops_cli/core/process.py` refuses a caller override that `CONST_CODE_LOADING_ENV_PATTERNS` matches. The patterns hold the loader, gconv, bash, zsh and interpreter keys (#2205, #2433, #2429). They hold no git key.
+- `GIT_CONFIG_COUNT` with `GIT_CONFIG_KEY_` and `GIT_CONFIG_VALUE_` gives git a configuration value. A value such as `core.fsmonitor`, `core.sshCommand` or an alias that starts with `!` runs a program.
+- Many other git keys run a program. `GIT_SSH_COMMAND`, `GIT_ASKPASS` and `GIT_EDITOR` name one. `GIT_EXEC_PATH` and `GIT_TEMPLATE_DIR` name a directory of programs or hooks. `GIT_CONFIG_GLOBAL` names a configuration file.
+- A review found keys that a list of names misses: `GIT_TEST_FSMONITOR`, `GIT_TEST_MAINT_SCHEDULER`, `GIT_ALLOW_PROTOCOL`, `GIT_DIFFTOOL_EXTCMD` and `MERGE_TOOLS_DIR`. A list stays incomplete when git adds a key.
+- `EDITOR`, `VISUAL` and `PAGER` are the keys that git uses when its own keys are not set. `LESSOPEN` makes `less`, the pager of git, run a program.
+- `DEFAULT_ALLOWED_ENV_VARS` lets the ambient `GIT_CONFIG_GLOBAL`, `GIT_CONFIG_SYSTEM`, `GIT_EXEC_PATH`, `EDITOR` and `PAGER` reach an isolated child.
+- devops-cli gives git the override `GIT_SSH_COMMAND=ssh -o BatchMode=yes` in `render_at_revision`. It is a caller override, so a guard that refuses the key stops that fetch.
+
+## What Changes
+
+- The guard refuses each `GIT_` key of a caller, but five keys that devops-cli callers set and that run no program. The five are `GIT_TERMINAL_PROMPT`, `GIT_AUTHOR_NAME`, `GIT_AUTHOR_EMAIL`, `GIT_COMMITTER_NAME` and `GIT_COMMITTER_EMAIL`. 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`. Each raises the same `SecurityError` as the other refused keys, with isolation on and off.
+- `DEFAULT_ALLOWED_ENV_VARS` removes `GIT_CONFIG_GLOBAL`, `GIT_CONFIG_SYSTEM`, `GIT_EXEC_PATH`, `EDITOR` and `PAGER`. Thus no refused key reaches an isolated child from the environment.
+- `render_at_revision` gives `git fetch` the option `-c core.sshCommand=ssh -o BatchMode=yes`. `CONST_GIT_NONINTERACTIVE_ENV` keeps only `GIT_TERMINAL_PROMPT=0`.
+- This replaces criterion 3 of the issue. The issue asked for a post-guard step that gives the child `GIT_SSH_COMMAND`. The design says why the argument is better.
+- The three `git config --global` calls name `GIT_CONFIG_GLOBAL` in `extra_allowed_env`. They write the file that the person set.
+- `ARCHITECTURE.md` and the purpose of the `subprocess-environment` spec name the git keys as refused keys.
+- The refusal and the isolated environment are what a consumer sees, so the change adds requirements to the `subprocess-environment` spec.
+- The change fits one pull request.
+
+## Capabilities
+
+### New Capabilities
+
+None.
+
+### Modified Capabilities
+
+- `subprocess-environment`: the guard refuses the git keys that devops-cli does not set, and an isolated child gets none of them from the environment. The change adds requirements and rewrites no existing requirement.
+
+## Impact
+
+- Code: `src/devops_cli/config/constants.py`, `src/devops_cli/core/process.py`, `src/devops_cli/k8s/argocd_overrides.py`, `src/devops_cli/crypto/ssh_keys.py`, `src/devops_cli/commands/devcontainer.py`.
+- Tests: `tests/test_subprocess_env_boundary.py`, `tests/test_k8s_argocd_overrides.py`, `tests/test_devcontainer.py`.
+- Documents: `ARCHITECTURE.md`, and the purpose of `openspec/specs/subprocess-environment/spec.md`.
+
+## Feasibility
+
+- The guard accepts the keys today. On `origin/main` at `a3eb41f4`, the command of step 1 of the issue printed `['GIT_CONFIG_COUNT', 'GIT_CONFIG_KEY_0', 'GIT_CONFIG_VALUE_0', 'GIT_SSH_COMMAND']` with no `SecurityError`. `DEFAULT_ALLOWED_ENV_VARS` holds `GIT_CONFIG_GLOBAL`, `GIT_CONFIG_SYSTEM`, `GIT_EXEC_PATH`, `EDITOR` and `PAGER`.
+- Step 3 of the issue, with git 2.55.0 and `env -i PATH=/usr/bin:/bin HOME=`, printed `GIT-CONFIG-FSMONITOR-RAN`. A `GIT_CONFIG_GLOBAL` file with `core.fsmonitor` printed `GIT-CONFIG-GLOBAL-RAN`.
+- Each probe below ran in a temporary directory, with the same `env -i` environment and a temporary `HOME`. It used a repository made with `git init` and a key whose value prints a marker. Each printed its marker, so the program ran.
+ - Configuration: `GIT_CONFIG_SYSTEM` with a file that sets `core.fsmonitor`, and `GIT_CONFIG_PARAMETERS='core.fsmonitor=...'`, with `git status`.
+ - Programs: `GIT_SSH_COMMAND` and `GIT_SSH` with `git ls-remote ssh://host.invalid/x`, and `GIT_PROXY_COMMAND` with `git ls-remote git://host.invalid/x`.
+ - Programs: `GIT_ASKPASS` with `git credential fill`, and `GIT_EXTERNAL_DIFF` with `git diff`.
+ - Editors: `GIT_EDITOR`, `EDITOR` and `VISUAL` (with `TERM=xterm`) with `git commit --allow-empty`, and `GIT_SEQUENCE_EDITOR` with `git rebase -i --root`.
+ - Pagers: `GIT_PAGER` and `PAGER` with `git log -1` on a pseudo-terminal that `script(1)` made. `LESSOPEN="| %s"` and `LESSCLOSE` ran with `less ` on the same pseudo-terminal.
+ - Directories: `GIT_EXEC_PATH` with a directory that holds `git-frobnicate` and `git-remote-https`, and `GIT_TEMPLATE_DIR` with a `hooks/post-checkout` file, with `git clone`.
+ - Keys that only the source of git names: `GIT_TEST_FSMONITOR` with `git status`, and `GIT_TEST_MAINT_SCHEDULER=crontab:` with `git maintenance start`.
+ - Keys of the scripts of git: `GIT_DIFFTOOL_EXTCMD` with `git difftool -y HEAD`, and `MERGE_TOOLS_DIR` (a shell file) with `git difftool -y -t HEAD`.
+ - Protocol: `GIT_ALLOW_PROTOCOL=ext` with `git ls-remote 'ext::'`. Without the key, git did not run the program.
+- The source of git reads `GIT_TEST_FSMONITOR` in `fsmonitor-settings.c` and `GIT_TEST_MAINT_SCHEDULER` in `builtin/gc.c`. The scripts `git-difftool--helper` and `git-mergetool--lib` read `GIT_DIFFTOOL_EXTCMD` and `MERGE_TOOLS_DIR`.
+- With `GIT_CONFIG_NOSYSTEM=1`, git did not read the `GIT_CONFIG_SYSTEM` file. The pages `git(1)`, `git-config(1)`, `git-init(1)`, `git-var(1)` and `less(1)` list the other keys. No page lists `GIT_CONFIG_PARAMETERS`: `git -c` uses it for child processes of git.
+- The default `env_delete` table of sudo (`initial_badenv_table` in `plugins/sudoers/env.c`, branch `main`) lists `GIT_SSH_COMMAND` and `GIT_CONFIG_*`. Commit `40217ea5` of 2026-03-28 added `GIT_SSH_COMMAND` and `GIT_CONFIG_GLOBAL`, and `main` now lists the whole `GIT_CONFIG_*` family.
+- The path of the own override: `_stdout` of `src/devops_cli/k8s/argocd_overrides.py` calls the runner of `render_at_revision` with `env=dict(CONST_GIT_NONINTERACTIVE_ENV)`. The runner is `_run_cmd` of `src/devops_cli/commands/k8s/cluster_runtime.py`. It calls `run_subprocess`, which calls `build_subprocess_env(env=...)`. It is the only use of `CONST_GIT_NONINTERACTIVE_ENV`.
+- The callers that set a git key give only `GIT_TERMINAL_PROMPT=0` (`roadmap/refine.py`, `roadmap/refine_investigation.py`, `ai/review/samples.py`). A tool request in `tests/test_tool_executor_contract.py` sets the author and the committer. No other file of `src/` or `tests/` gives a `GIT_` key as a caller override.
+- `git -c core.sshCommand='ssh -o BatchMode=yes' fetch ssh://git@example.com/x.git main` started `ssh` with `-o BatchMode=yes`, as `GIT_SSH_COMMAND='ssh -o BatchMode=yes'` does. A stand-in `ssh` file on `PATH` recorded the arguments of both.
+- No file in `src/` sets or reads `EDITOR`, `VISUAL` or `PAGER` for a child, and no test sets one. The ambient `GIT_CONFIG_GLOBAL` has two readers: the three `git config --global` calls, and the `global_git_config` fixture of `tests/test_ssh.py`.
+- `src/devops_cli/openspec/tool.py` sets `XDG_CONFIG_HOME` as a caller override, so the guard cannot refuse it. A probe with `XDG_CONFIG_HOME` and a `git/config` file that sets `core.fsmonitor` ran a program in `git status`.
+
+## Existing Tool Considered
+
+The default `env_delete` table of sudo is the maintained, open list of environment keys that change the code that a program runs. It names two of the git keys, and the pages and the source of git name the others. No library publishes a list for import, so the constant names the sources, as #2205 and #2429 decided. The match keeps `fnmatch.fnmatchcase` of the standard library. The SSH option moves to `git -c`, the option that git gives for this need. Thus the change builds no pin step and no bypass, and it deletes five keys from the ambient allowlist.
diff --git a/openspec/changes/archive/2026-10-29-2483-refuse-git-code-env-keys/specs/subprocess-environment/spec.md b/openspec/changes/archive/2026-10-29-2483-refuse-git-code-env-keys/specs/subprocess-environment/spec.md
new file mode 100644
index 0000000000..b14c33a4a9
--- /dev/null
+++ b/openspec/changes/archive/2026-10-29-2483-refuse-git-code-env-keys/specs/subprocess-environment/spec.md
@@ -0,0 +1,66 @@
+## ADDED Requirements
+
+### Requirement: A caller override of a git key that devops-cli does not set is refused
+`build_subprocess_env` SHALL raise `SecurityError` for a caller override whose upper-case key starts with `GIT_`, but not for the five keys of the next requirement. It SHALL refuse `EDITOR`, `VISUAL`, `PAGER`, `LESSOPEN`, `LESSCLOSE` and `MERGE_TOOLS_DIR` in the same way. The message is "Prohibited dangerous environment variable override: ''" and the error code is `SECURITY_ERROR`. It SHALL do this with environment isolation on and off.
+
+#### Scenario: A git configuration key
+- **WHEN** a caller builds a child environment with the override `GIT_CONFIG_COUNT`, `GIT_CONFIG_KEY_0`, `GIT_CONFIG_VALUE_12`, `GIT_CONFIG_PARAMETERS`, `GIT_CONFIG_GLOBAL` or `GIT_CONFIG_SYSTEM`, in upper or lower case
+- **THEN** `build_subprocess_env` raises `SecurityError` that names the key, with the error code `SECURITY_ERROR`
+
+#### Scenario: A program that git starts
+- **WHEN** a caller builds a child environment with the override `GIT_SSH`, `GIT_SSH_COMMAND`, `GIT_ASKPASS`, `GIT_EDITOR`, `GIT_SEQUENCE_EDITOR`, `GIT_PAGER`, `GIT_EXTERNAL_DIFF` or `GIT_PROXY_COMMAND`, in upper or lower case
+- **THEN** `build_subprocess_env` raises `SecurityError` that names the key, with the error code `SECURITY_ERROR`
+
+#### Scenario: A directory of git programs or hooks, and the ext transport
+- **WHEN** a caller builds a child environment with the override `GIT_EXEC_PATH`, `GIT_TEMPLATE_DIR` or `GIT_ALLOW_PROTOCOL`, in upper or lower case
+- **THEN** `build_subprocess_env` raises `SecurityError` that names the key, with the error code `SECURITY_ERROR`
+
+#### Scenario: A key that the source or a script of git reads
+- **WHEN** a caller builds a child environment with the override `GIT_TEST_FSMONITOR`, `GIT_TEST_MAINT_SCHEDULER`, `GIT_DIFFTOOL_EXTCMD` or `MERGE_TOOLS_DIR`, in upper or lower case
+- **THEN** `build_subprocess_env` raises `SecurityError` that names the key, with the error code `SECURITY_ERROR`
+
+#### Scenario: A trace key that writes a file
+- **WHEN** a caller builds a child environment with the override `GIT_TRACE`, `GIT_TRACE2` or `GIT_TRACE_CURL`, in upper or lower case
+- **THEN** `build_subprocess_env` raises `SecurityError` that names the key, with the error code `SECURITY_ERROR`
+
+#### Scenario: A git key that no caller sets
+- **WHEN** a caller builds a child environment with the override `GIT_SSH_VARIANT`, `GIT_CONFIG_NOSYSTEM` or `GIT_EXAMPLE_KEY`, in upper or lower case
+- **THEN** `build_subprocess_env` raises `SecurityError` that names the key, with the error code `SECURITY_ERROR`
+
+#### Scenario: The editor, the pager and their filters
+- **WHEN** a caller builds a child environment with the override `EDITOR`, `VISUAL`, `PAGER`, `LESSOPEN` or `LESSCLOSE`, in upper or lower case
+- **THEN** `build_subprocess_env` raises `SecurityError` that names the key, with the error code `SECURITY_ERROR`
+
+### Requirement: A git key that devops-cli sets reaches the child
+`build_subprocess_env` SHALL put `GIT_TERMINAL_PROMPT`, `GIT_AUTHOR_NAME`, `GIT_AUTHOR_EMAIL`, `GIT_COMMITTER_NAME` and `GIT_COMMITTER_EMAIL` of the caller override in the child environment with their values. It SHALL do the same for a key that only contains a refused git name, and for `XDG_CONFIG_HOME`.
+
+#### Scenario: The five git keys and keys that look like a refused key
+- **WHEN** a caller builds a child environment with the overrides `GIT_TERMINAL_PROMPT`, `GIT_AUTHOR_NAME`, `GIT_AUTHOR_EMAIL`, `GIT_COMMITTER_NAME`, `GIT_COMMITTER_EMAIL`, `GITHUB_STEP_SUMMARY`, `EXAMPLE_GIT_SSH_COMMAND` and `XDG_CONFIG_HOME`
+- **THEN** the child environment holds each of these keys with its value, with isolation on and off
+
+### Requirement: The ambient allowlist holds no refused key
+No key of `DEFAULT_ALLOWED_ENV_VARS` SHALL be a key that `build_subprocess_env` refuses from a caller.
+
+#### Scenario: Each allowed key as an override
+- **WHEN** a caller builds a child environment with one key of `DEFAULT_ALLOWED_ENV_VARS` as the override
+- **THEN** `build_subprocess_env` raises no error, and the child environment holds the key with its value
+
+### Requirement: The fetch of an Argo CD revision never asks a question
+`render_at_revision` SHALL run `git fetch` with the argument `-c` and the value `core.sshCommand=ssh -o BatchMode=yes`. It SHALL give each command the environment override `GIT_TERMINAL_PROMPT=0` and no other git key. The override passes the guard, so the fetch of an SSH remote starts `ssh` with `-o BatchMode=yes`.
+
+#### Scenario: A fetch over SSH through run_subprocess
+- **WHEN** `render_at_revision` fetches the SSH remote `ssh://git@example.com/repository.git` through `run_subprocess`, and a stand-in `ssh` program is first on `PATH`
+- **THEN** the stand-in `ssh` starts with the arguments `-o BatchMode=yes`
+- **AND** no `SecurityError` is raised before the fetch fails
+
+### Requirement: A git command that writes the global configuration uses the file that the environment names
+The calls `git config --global` of `devops ssh register`, `devops ssh rotate` and `devops devcontainer post-start` SHALL name `GIT_CONFIG_GLOBAL` in `extra_allowed_env`. When the environment holds the key, each call writes in the file that the key names, as `git config --global` does in a shell.
+
+#### Scenario: The signing key of a registered SSH key
+- **WHEN** the environment holds `GIT_CONFIG_GLOBAL` with the path of a file below a temporary directory, and `devops ssh register` runs
+- **THEN** that file holds `gpg.format`, `user.signingkey` and `commit.gpgsign`
+
+#### Scenario: The git defaults of the post-start step
+- **WHEN** the environment holds `GIT_CONFIG_GLOBAL` with the path of a file below a temporary directory, and `devops devcontainer post-start` runs
+- **THEN** that file holds `push.autoSetupRemote` set to `true` and `init.defaultBranch` set to `main`
+- **AND** the home directory holds no `.gitconfig`
diff --git a/openspec/changes/archive/2026-10-29-2483-refuse-git-code-env-keys/tasks.md b/openspec/changes/archive/2026-10-29-2483-refuse-git-code-env-keys/tasks.md
new file mode 100644
index 0000000000..5ae90b55db
--- /dev/null
+++ b/openspec/changes/archive/2026-10-29-2483-refuse-git-code-env-keys/tasks.md
@@ -0,0 +1,39 @@
+# Tasks
+
+## 1. The guard refuses the git keys that devops-cli does not set
+
+- [x] 1.1 Add failing tests: a caller override of each refused key raises `SecurityError`, in upper and lower case, with isolation on and off
+ - Verification: `uv run devops ci test tests/test_subprocess_env_boundary.py`
+- [x] 1.2 Add failing tests: with each refused key in the environment, an isolated child holds none. No key of the allowlist is refused. The five accepted git keys, `XDG_CONFIG_HOME` and `GITHUB_STEP_SUMMARY` reach the child
+ - Verification: `uv run devops ci test tests/test_subprocess_env_boundary.py`
+- [x] 1.3 Add `GIT_*` and the other keys of the design to `CONST_CODE_LOADING_ENV_PATTERNS`, with the pages above them. Add `CONST_GIT_ACCEPTED_ENV`, and make the guard skip its keys. Keep the comment of the constant at 25 words
+ - Verification: `uv run devops ci test tests/test_subprocess_env_boundary.py tests/test_review_rules_pack.py`
+- [x] 1.4 Remove `GIT_CONFIG_GLOBAL`, `GIT_CONFIG_SYSTEM`, `GIT_EXEC_PATH`, `EDITOR` and `PAGER` from `DEFAULT_ALLOWED_ENV_VARS`
+ - Verification: `uv run devops ci test tests/test_subprocess_env_boundary.py tests/test_ci.py tests/test_cli_startup_imports.py`
+
+## 2. The own git children pass the guard
+
+- [x] 2.1 Add failing tests: `render_at_revision` through `run_subprocess` starts `ssh` with `-o BatchMode=yes` for an SSH remote. The fetch has `-c core.sshCommand=ssh -o BatchMode=yes`, and each command has only `GIT_TERMINAL_PROMPT=0`
+ - Verification: `uv run devops ci test tests/test_k8s_argocd_overrides.py`
+- [x] 2.2 Move the SSH option of `CONST_GIT_NONINTERACTIVE_ENV` to `CONST_GIT_NONINTERACTIVE_SSH_CONFIG`, and give it to the `git fetch` of `render_at_revision` as `-c`
+ - Verification: `uv run devops ci test tests/test_k8s_argocd_overrides.py tests/test_k8s_deploy_stack_urls.py`
+- [x] 2.3 Add a failing test: with `GIT_CONFIG_GLOBAL` in the environment, `devops devcontainer post-start` writes its two git defaults in that file
+ - Verification: `uv run devops ci test tests/test_devcontainer.py`
+- [x] 2.4 Add `CONST_GIT_GLOBAL_CONFIG_ENV`, and name it in `extra_allowed_env` of the three `git config --global` calls
+ - Verification: `uv run devops ci test tests/test_devcontainer.py tests/test_ssh.py`
+
+## 3. Documentation
+
+- [x] 3.1 Write the child environment bullets of `ARCHITECTURE.md` and the purpose of the `subprocess-environment` spec for the git keys
+ - Verification: `uv run devops docs generate --sync-readme` and `uv run devops docs check`
+
+## 4. Archive
+
+- [x] 4.1 Archive the change
+ - Verification: `uv run devops openspec archive 2483-refuse-git-code-env-keys`
+
+## Workflow follow-up
+
+- The keys of `ssh` that make an `ssh` child run a program, `SSH_ASKPASS` and `SSH_ASKPASS_REQUIRE`: #2633.
+- The library keys that make a library of the child load a module, for example `OPENSSL_CONF`: #2503.
+- Pending a person: review the diff in tuicr (tuicr -r origin/main..HEAD).
diff --git a/openspec/specs/subprocess-environment/spec.md b/openspec/specs/subprocess-environment/spec.md
index 9bc9acda5d..f22a54ccd5 100644
--- a/openspec/specs/subprocess-environment/spec.md
+++ b/openspec/specs/subprocess-environment/spec.md
@@ -1,7 +1,7 @@
# subprocess-environment Specification
## Purpose
-Which caller overrides of the environment of a child process devops-cli refuses, and what a refusal reports. Each refused key makes the dynamic loader, the shell or the interpreter of the child load or run code that the caller did not choose. An isolated child does not get a refused key from the environment, unless the caller names the key in `extra_allowed_keys`.
+Which caller overrides of the environment of a child process devops-cli refuses, and what a refusal reports. Each refused key makes the dynamic loader, the shell, the interpreter or git load or run code that the caller did not choose. An isolated child does not get a refused key from the environment, unless the caller names the key in `extra_allowed_keys`.
## Requirements
@@ -72,3 +72,68 @@ With environment isolation on, `build_subprocess_env` SHALL keep each key that t
#### Scenario: Refused keys in the environment of the person
- **WHEN** the environment holds `PYTHONPATH`, `PYTHONHOME`, `ZDOTDIR`, `NODE_OPTIONS`, `PERL5LIB`, `LD_PRELOAD`, `BASH_ENV` and each other refused key, and a caller builds a child environment with isolation on
- **THEN** the child environment holds none of these keys
+
+### Requirement: A caller override of a git key that devops-cli does not set is refused
+`build_subprocess_env` SHALL raise `SecurityError` for a caller override whose upper-case key starts with `GIT_`, but not for the five keys of the next requirement. It SHALL refuse `EDITOR`, `VISUAL`, `PAGER`, `LESSOPEN`, `LESSCLOSE` and `MERGE_TOOLS_DIR` in the same way. The message is "Prohibited dangerous environment variable override: ''" and the error code is `SECURITY_ERROR`. It SHALL do this with environment isolation on and off.
+
+#### Scenario: A git configuration key
+- **WHEN** a caller builds a child environment with the override `GIT_CONFIG_COUNT`, `GIT_CONFIG_KEY_0`, `GIT_CONFIG_VALUE_12`, `GIT_CONFIG_PARAMETERS`, `GIT_CONFIG_GLOBAL` or `GIT_CONFIG_SYSTEM`, in upper or lower case
+- **THEN** `build_subprocess_env` raises `SecurityError` that names the key, with the error code `SECURITY_ERROR`
+
+#### Scenario: A program that git starts
+- **WHEN** a caller builds a child environment with the override `GIT_SSH`, `GIT_SSH_COMMAND`, `GIT_ASKPASS`, `GIT_EDITOR`, `GIT_SEQUENCE_EDITOR`, `GIT_PAGER`, `GIT_EXTERNAL_DIFF` or `GIT_PROXY_COMMAND`, in upper or lower case
+- **THEN** `build_subprocess_env` raises `SecurityError` that names the key, with the error code `SECURITY_ERROR`
+
+#### Scenario: A directory of git programs or hooks, and the ext transport
+- **WHEN** a caller builds a child environment with the override `GIT_EXEC_PATH`, `GIT_TEMPLATE_DIR` or `GIT_ALLOW_PROTOCOL`, in upper or lower case
+- **THEN** `build_subprocess_env` raises `SecurityError` that names the key, with the error code `SECURITY_ERROR`
+
+#### Scenario: A key that the source or a script of git reads
+- **WHEN** a caller builds a child environment with the override `GIT_TEST_FSMONITOR`, `GIT_TEST_MAINT_SCHEDULER`, `GIT_DIFFTOOL_EXTCMD` or `MERGE_TOOLS_DIR`, in upper or lower case
+- **THEN** `build_subprocess_env` raises `SecurityError` that names the key, with the error code `SECURITY_ERROR`
+
+#### Scenario: A trace key that writes a file
+- **WHEN** a caller builds a child environment with the override `GIT_TRACE`, `GIT_TRACE2` or `GIT_TRACE_CURL`, in upper or lower case
+- **THEN** `build_subprocess_env` raises `SecurityError` that names the key, with the error code `SECURITY_ERROR`
+
+#### Scenario: A git key that no caller sets
+- **WHEN** a caller builds a child environment with the override `GIT_SSH_VARIANT`, `GIT_CONFIG_NOSYSTEM` or `GIT_EXAMPLE_KEY`, in upper or lower case
+- **THEN** `build_subprocess_env` raises `SecurityError` that names the key, with the error code `SECURITY_ERROR`
+
+#### Scenario: The editor, the pager and their filters
+- **WHEN** a caller builds a child environment with the override `EDITOR`, `VISUAL`, `PAGER`, `LESSOPEN` or `LESSCLOSE`, in upper or lower case
+- **THEN** `build_subprocess_env` raises `SecurityError` that names the key, with the error code `SECURITY_ERROR`
+
+### Requirement: A git key that devops-cli sets reaches the child
+`build_subprocess_env` SHALL put `GIT_TERMINAL_PROMPT`, `GIT_AUTHOR_NAME`, `GIT_AUTHOR_EMAIL`, `GIT_COMMITTER_NAME` and `GIT_COMMITTER_EMAIL` of the caller override in the child environment with their values. It SHALL do the same for a key that only contains a refused git name, and for `XDG_CONFIG_HOME`.
+
+#### Scenario: The five git keys and keys that look like a refused key
+- **WHEN** a caller builds a child environment with the overrides `GIT_TERMINAL_PROMPT`, `GIT_AUTHOR_NAME`, `GIT_AUTHOR_EMAIL`, `GIT_COMMITTER_NAME`, `GIT_COMMITTER_EMAIL`, `GITHUB_STEP_SUMMARY`, `EXAMPLE_GIT_SSH_COMMAND` and `XDG_CONFIG_HOME`
+- **THEN** the child environment holds each of these keys with its value, with isolation on and off
+
+### Requirement: The ambient allowlist holds no refused key
+No key of `DEFAULT_ALLOWED_ENV_VARS` SHALL be a key that `build_subprocess_env` refuses from a caller.
+
+#### Scenario: Each allowed key as an override
+- **WHEN** a caller builds a child environment with one key of `DEFAULT_ALLOWED_ENV_VARS` as the override
+- **THEN** `build_subprocess_env` raises no error, and the child environment holds the key with its value
+
+### Requirement: The fetch of an Argo CD revision never asks a question
+`render_at_revision` SHALL run `git fetch` with the argument `-c` and the value `core.sshCommand=ssh -o BatchMode=yes`. It SHALL give each command the environment override `GIT_TERMINAL_PROMPT=0` and no other git key. The override passes the guard, so the fetch of an SSH remote starts `ssh` with `-o BatchMode=yes`.
+
+#### Scenario: A fetch over SSH through run_subprocess
+- **WHEN** `render_at_revision` fetches the SSH remote `ssh://git@example.com/repository.git` through `run_subprocess`, and a stand-in `ssh` program is first on `PATH`
+- **THEN** the stand-in `ssh` starts with the arguments `-o BatchMode=yes`
+- **AND** no `SecurityError` is raised before the fetch fails
+
+### Requirement: A git command that writes the global configuration uses the file that the environment names
+The calls `git config --global` of `devops ssh register`, `devops ssh rotate` and `devops devcontainer post-start` SHALL name `GIT_CONFIG_GLOBAL` in `extra_allowed_env`. When the environment holds the key, each call writes in the file that the key names, as `git config --global` does in a shell.
+
+#### Scenario: The signing key of a registered SSH key
+- **WHEN** the environment holds `GIT_CONFIG_GLOBAL` with the path of a file below a temporary directory, and `devops ssh register` runs
+- **THEN** that file holds `gpg.format`, `user.signingkey` and `commit.gpgsign`
+
+#### Scenario: The git defaults of the post-start step
+- **WHEN** the environment holds `GIT_CONFIG_GLOBAL` with the path of a file below a temporary directory, and `devops devcontainer post-start` runs
+- **THEN** that file holds `push.autoSetupRemote` set to `true` and `init.defaultBranch` set to `main`
+- **AND** the home directory holds no `.gitconfig`
diff --git a/src/devops_cli/commands/devcontainer.py b/src/devops_cli/commands/devcontainer.py
index 3b8124086e..9766eccafc 100755
--- a/src/devops_cli/commands/devcontainer.py
+++ b/src/devops_cli/commands/devcontainer.py
@@ -28,6 +28,7 @@
CONST_DEVCONTAINER_PUBLISHED_IMAGE,
CONST_GH_LOGIN_ENV_VARS,
CONST_GH_TOKEN_ENV_VARS,
+ CONST_GIT_GLOBAL_CONFIG_ENV,
CONST_K8S_MINIKUBE_CONTEXT,
CONST_KEYRING_PACKAGES,
CONST_KEYRING_PROMPT_TIMEOUT_SECONDS,
@@ -1062,11 +1063,13 @@ def _run_post_start_lifecycle(workspace_dir: Path, *, dry_run: bool = False) ->
["git", "config", "--global", "push.autoSetupRemote", "true"],
check=False,
quiet=True,
+ extra_allowed_env=CONST_GIT_GLOBAL_CONFIG_ENV,
)
run_subprocess(
["git", "config", "--global", "init.defaultBranch", "main"],
check=False,
quiet=True,
+ extra_allowed_env=CONST_GIT_GLOBAL_CONFIG_ENV,
)
actions.append("Configured git push.autoSetupRemote=true and init.defaultBranch=main")
diff --git a/src/devops_cli/config/constants.py b/src/devops_cli/config/constants.py
index 3a172d381d..6725abc301 100644
--- a/src/devops_cli/config/constants.py
+++ b/src/devops_cli/config/constants.py
@@ -1069,11 +1069,26 @@
CONST_K8S_ARGOCD_FETCH_TIMEOUT_SECONDS: Final[float] = 300.0
"""How long fetching an Application's revision may take before deploy-stack gives up."""
"""JQ expression in cluster.yaml ignoreDifferences matching Argo CD PreDelete/PostDelete finalizers (#1674)."""
-CONST_GIT_NONINTERACTIVE_ENV: Final[dict[str, str]] = {
- "GIT_TERMINAL_PROMPT": "0",
- "GIT_SSH_COMMAND": "ssh -o BatchMode=yes",
-}
-"""Environment that makes git fail instead of prompting for credentials or a passphrase."""
+CONST_GIT_NONINTERACTIVE_ENV: Final[dict[str, str]] = {"GIT_TERMINAL_PROMPT": "0"}
+"""Environment that makes git fail instead of prompting for credentials."""
+CONST_GIT_NONINTERACTIVE_SSH_CONFIG: Final[str] = "core.sshCommand=ssh -o BatchMode=yes"
+"""The `git -c` value that makes git fail instead of asking for a passphrase or a host key. It is
+an argument, because the guard of `build_subprocess_env` refuses `GIT_SSH_COMMAND` (#2483)."""
+CONST_GIT_ACCEPTED_ENV: Final[frozenset[str]] = frozenset(
+ {
+ "GIT_TERMINAL_PROMPT",
+ "GIT_AUTHOR_NAME",
+ "GIT_AUTHOR_EMAIL",
+ "GIT_COMMITTER_NAME",
+ "GIT_COMMITTER_EMAIL",
+ }
+)
+"""The git keys that `build_subprocess_env` accepts from a caller (#2483). devops-cli sets
+`GIT_TERMINAL_PROMPT`, and a tool request sets the author and the committer (git(1)). None runs a
+program or writes a file. The guard refuses each other `GIT_` key, also one that git adds later."""
+CONST_GIT_GLOBAL_CONFIG_ENV: Final[frozenset[str]] = frozenset({"GIT_CONFIG_GLOBAL"})
+"""The ambient key that a `git config --global` call names in `extra_allowed_env`, so that it
+writes the global file that the environment names, as it does in a shell (#2483)."""
CONST_K8S_TEMPLATE_EXTENSIONS: Final[tuple[str, ...]] = (".yaml", ".yml")
# ── Kubernetes RBAC Audit ─────────────────────────────────────────────────────
@@ -1551,6 +1566,17 @@ class WebhookExposure(StrEnum):
"FPATH",
"NULLCMD",
"READNULLCMD",
+ # git(1), git-config(1), git-init(1): each GIT_ key but the ones of CONST_GIT_ACCEPTED_ENV
+ "GIT_*",
+ # git-var(1), the fall-back keys of GIT_EDITOR and GIT_PAGER
+ "VISUAL",
+ "EDITOR",
+ "PAGER",
+ # less(1), the filter that a pager runs
+ "LESSOPEN",
+ "LESSCLOSE",
+ # the git-mergetool--lib script, which reads a shell file from this directory
+ "MERGE_TOOLS_DIR",
# python(1)
"PYTHONPATH",
"PYTHONHOME",
diff --git a/src/devops_cli/core/process.py b/src/devops_cli/core/process.py
index 9ad769951b..0ae4cf5481 100644
--- a/src/devops_cli/core/process.py
+++ b/src/devops_cli/core/process.py
@@ -26,6 +26,7 @@
CONST_GH_LOGIN_ENV_VARS,
CONST_GH_NON_API_COMMANDS,
CONST_GH_TOKEN_ENV_VARS,
+ CONST_GIT_ACCEPTED_ENV,
CONST_GIT_CLI,
CONST_GITHUB_APP_PRIVATE_KEY_ENV,
)
@@ -94,15 +95,10 @@
"DOCKER_CONFIG",
"DOCKER_TLS_VERIFY",
"DOCKER_CERT_PATH",
- "PAGER",
- "EDITOR",
"GIT_AUTHOR_NAME",
"GIT_AUTHOR_EMAIL",
"GIT_COMMITTER_NAME",
"GIT_COMMITTER_EMAIL",
- "GIT_CONFIG_GLOBAL",
- "GIT_CONFIG_SYSTEM",
- "GIT_EXEC_PATH",
"CI",
"PYTEST_CURRENT_TEST",
"XDG_RUNTIME_DIR",
@@ -140,6 +136,14 @@ def _is_env_var_denied(
return any(fnmatch.fnmatchcase(upper_key, pat) for pat in denied_patterns)
+def _is_env_override_refused(key: str) -> bool:
+ """Whether a caller may not set `key`: a pattern of `CONST_CODE_LOADING_ENV_PATTERNS` matches
+ it, and it is not a git key that `CONST_GIT_ACCEPTED_ENV` names."""
+ return key.upper() not in CONST_GIT_ACCEPTED_ENV and _is_env_var_denied(
+ key, CONST_CODE_LOADING_ENV_PATTERNS
+ )
+
+
def _is_env_var_allowed(
key: str,
*,
@@ -186,7 +190,7 @@ def build_subprocess_env(
from devops_cli.exceptions.security import SecurityError
for k, v in env.items():
- if _is_env_var_denied(k, CONST_CODE_LOADING_ENV_PATTERNS):
+ if _is_env_override_refused(k):
raise SecurityError(f"Prohibited dangerous environment variable override: '{k}'")
if "\x00" in k or "\x00" in str(v):
raise SecurityError(f"Null byte in environment variable prohibited: '{k}'")
diff --git a/src/devops_cli/crypto/ssh_keys.py b/src/devops_cli/crypto/ssh_keys.py
index 081052817d..02995d50ad 100755
--- a/src/devops_cli/crypto/ssh_keys.py
+++ b/src/devops_cli/crypto/ssh_keys.py
@@ -15,7 +15,11 @@
PublicFormat,
)
-from devops_cli.config.constants import CONST_PERM_PRIVATE_KEY, CONST_PERM_PUBLIC_KEY
+from devops_cli.config.constants import (
+ CONST_GIT_GLOBAL_CONFIG_ENV,
+ CONST_PERM_PRIVATE_KEY,
+ CONST_PERM_PUBLIC_KEY,
+)
from devops_cli.core.serialization import strip_json_comments
from devops_cli.core.validation import validate_safe_key_path
from devops_cli.exceptions import ValidationError
@@ -311,7 +315,11 @@ def configure_git_signing(key_path: Path, repo_dir: Path | None = None) -> None:
("commit.gpgsign", "true"),
)
for key, value in settings:
- run_subprocess(["git", "config", "--global", key, value], quiet=True)
+ run_subprocess(
+ ["git", "config", "--global", key, value],
+ quiet=True,
+ extra_allowed_env=CONST_GIT_GLOBAL_CONFIG_ENV,
+ )
target_repo = (repo_dir or Path.cwd()).resolve()
if (target_repo / ".git").exists():
diff --git a/src/devops_cli/k8s/argocd_overrides.py b/src/devops_cli/k8s/argocd_overrides.py
index 780804bb51..f48e0ef742 100644
--- a/src/devops_cli/k8s/argocd_overrides.py
+++ b/src/devops_cli/k8s/argocd_overrides.py
@@ -21,6 +21,7 @@
from devops_cli.config.constants import (
CONST_GIT_NONINTERACTIVE_ENV,
+ CONST_GIT_NONINTERACTIVE_SSH_CONFIG,
CONST_K8S_ARGOCD_FETCH_TIMEOUT_SECONDS,
)
from devops_cli.exceptions.k8s import KubernetesContextError
@@ -83,12 +84,15 @@ def render_at_revision(source: ApplicationSource, workdir: Path, run: Run) -> st
The revision is fetched into `workdir`, never into the caller's checkout, so the hosts come
from what Argo CD builds whichever branch the caller has checked out. The repository and
revision come from the cluster or the command line, so git reads them after
- ``--end-of-options`` and can never take one for an option.
+ ``--end-of-options`` and can never take one for an option. The fetch gets the SSH option as
+ ``git -c``, because the guard of ``build_subprocess_env`` refuses ``GIT_SSH_COMMAND``.
"""
checkout = workdir / "checkout"
git = ["git", "-C", str(checkout)]
_stdout(run, ["git", "init", "--quiet", str(checkout)])
fetch = [
+ "-c",
+ CONST_GIT_NONINTERACTIVE_SSH_CONFIG,
"fetch",
"--quiet",
"--depth",
diff --git a/tests/test_devcontainer.py b/tests/test_devcontainer.py
index 878dae0412..ee470d8170 100644
--- a/tests/test_devcontainer.py
+++ b/tests/test_devcontainer.py
@@ -191,6 +191,30 @@ def test_post_start_command_executes_successfully(
assert "post-start lifecycle complete" in result.output
assert (fake_home / ".kube" / "config").exists()
+ @pytest.mark.usefixtures("no_configured_k8s_context")
+ def test_post_start_writes_the_git_defaults_in_the_global_file_the_environment_names(
+ self, runner: CliRunner, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+ ) -> None:
+ """With `GIT_CONFIG_GLOBAL` in the environment, `git config --global` writes the two git
+ defaults in that file, as it does in a shell, and the home directory gets no `.gitconfig`
+ (#2483)."""
+ fake_home = tmp_path / "home"
+ fake_home.mkdir()
+ global_config = tmp_path / "global-gitconfig"
+ monkeypatch.setenv("HOME", str(fake_home))
+ monkeypatch.setenv("GIT_CONFIG_GLOBAL", str(global_config))
+ monkeypatch.setenv("DEVOPS_MINIKUBE_AUTOSTART", "false")
+
+ result = runner.invoke(app, ["post-start", "--workspace", str(tmp_path)])
+
+ written = global_config.read_text(encoding="utf-8") if global_config.exists() else ""
+ assert (
+ result.exit_code,
+ "autoSetupRemote = true" in written,
+ "defaultBranch = main" in written,
+ (fake_home / ".gitconfig").exists(),
+ ) == (0, True, True, False)
+
def test_post_start_spawns_background_k8s_bootstrap(
self, runner: CliRunner, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
diff --git a/tests/test_k8s_argocd_overrides.py b/tests/test_k8s_argocd_overrides.py
index feb93221d1..e14daecb03 100644
--- a/tests/test_k8s_argocd_overrides.py
+++ b/tests/test_k8s_argocd_overrides.py
@@ -11,6 +11,7 @@
import yaml
from devops_cli.config.constants import CONST_K8S_ARGOCD_HOMELAB_APPLICATIONS
+from devops_cli.core.process import run_subprocess
from devops_cli.exceptions.k8s import KubernetesContextError
from devops_cli.k8s.argocd_overrides import (
ApplicationSource,
@@ -208,6 +209,73 @@ def test_an_application_renders_what_its_revision_holds(tmp_path: Path) -> None:
]
+def _guarded_run(
+ cmd: list[str],
+ *,
+ check: bool = False,
+ capture: bool = True,
+ timeout: float,
+ env: dict[str, str] | None = None,
+) -> subprocess.CompletedProcess[str]:
+ """A runner as `deploy-stack` gives `render_at_revision`: it starts the command with
+ `run_subprocess`, so the environment of the caller passes the guard of
+ `build_subprocess_env`."""
+ return run_subprocess(cmd, check=check, capture_output=capture, timeout=timeout, env=env)
+
+
+def test_the_fetch_of_an_ssh_remote_starts_ssh_without_a_prompt_through_the_guard(
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ """`run_subprocess` gives git the environment of the fetch through the guard of
+ `build_subprocess_env`, and `ssh` starts with `-o BatchMode=yes` (#2483). A stand-in `ssh`
+ program records its arguments and fails, so the fetch ends at once."""
+ ssh_log = tmp_path / "ssh.log"
+ bin_dir = tmp_path / "bin"
+ bin_dir.mkdir()
+ stand_in = bin_dir / "ssh"
+ stand_in.write_text(f'#!/bin/sh\nprintf "%s\\n" "$*" >> "{ssh_log}"\nexit 1\n')
+ stand_in.chmod(0o755)
+ monkeypatch.setenv("PATH", f"{bin_dir}{os.pathsep}{os.environ['PATH']}")
+ source = ApplicationSource("ssh://git@example.com/repository.git", "main", "k8s/app")
+
+ with pytest.raises(KubernetesContextError, match="fetch"):
+ render_at_revision(source, tmp_path / "work", _guarded_run)
+
+ assert ssh_log.read_text(encoding="utf-8").splitlines()[0].startswith("-o BatchMode=yes ")
+
+
+def test_only_the_fetch_gets_the_ssh_option_and_every_command_gets_only_the_prompt_switch(
+ tmp_path: Path,
+) -> None:
+ """The SSH option is an argument of `git fetch`, the one command that opens an SSH
+ connection, and the environment of each command holds `GIT_TERMINAL_PROMPT=0` and no other
+ key (#2483)."""
+ started: list[tuple[list[str], dict[str, str] | None]] = []
+
+ def record(
+ cmd: list[str], *, env: dict[str, str] | None = None, **_: object
+ ) -> subprocess.CompletedProcess[str]:
+ started.append((cmd, env))
+ return subprocess.CompletedProcess(cmd, 0, stdout="", stderr="")
+
+ source = ApplicationSource("ssh://git@example.com/repository.git", "main", "k8s/app")
+ render_at_revision(source, tmp_path / "work", record)
+
+ fetch = next(cmd for cmd, _ in started if "fetch" in cmd)
+ before_subcommand = fetch[: fetch.index("fetch")]
+ assert (
+ [fetch[at + 1] for at, word in enumerate(fetch) if word == "-c"],
+ "-c" in before_subcommand,
+ [cmd for cmd, _ in started if "-c" in cmd] == [fetch],
+ [env for _, env in started],
+ ) == (
+ ["core.sshCommand=ssh -o BatchMode=yes"],
+ True,
+ True,
+ [{"GIT_TERMINAL_PROMPT": "0"}] * len(started),
+ )
+
+
@pytest.mark.parametrize(
("revision", "path", "message"),
[("main", "../outside", "leaves its repository"), ("missing", "k8s/app", "git -C")],
diff --git a/tests/test_subprocess_env_boundary.py b/tests/test_subprocess_env_boundary.py
index c5feae930b..8c433c30f0 100644
--- a/tests/test_subprocess_env_boundary.py
+++ b/tests/test_subprocess_env_boundary.py
@@ -11,7 +11,11 @@
import pytest
-from devops_cli.config.constants import CONST_EXIT_FAILURE, CONST_GH_CLI
+from devops_cli.config.constants import (
+ CONST_EXIT_FAILURE,
+ CONST_GH_CLI,
+ CONST_GIT_NONINTERACTIVE_ENV,
+)
from devops_cli.config.defaults import (
DEFAULT_GH_AUTH_TOKEN_RETRY_SECONDS,
DEFAULT_GH_AUTH_TOKEN_TIMEOUT_SECONDS,
@@ -157,11 +161,27 @@ def test_build_subprocess_env_case_insensitivity(monkeypatch: pytest.MonkeyPatch
# list, BASH_FUNC_x(), the export form of the patched bash of Red Hat, and two function names pin
# the prefix rule. BASH_FUNC_git%% replaces the git command in a bash child. zsh reads its start-up
# files from ZDOTDIR (zsh(1)), functions from FPATH and a command from NULLCMD and READNULLCMD
-# (zshparam(1)). The Python, Node.js, Perl, Ruby and Java keys name a file, a module, a directory
-# or an option that makes the interpreter load code (python(1), node(1), perlrun(1), ruby(1),
-# java(1), the JVM TI specification). The default env_delete table of sudo lists each zsh and
-# interpreter key but PYTHONPLATLIBDIR, PYTHONPYCACHEPREFIX, NODE_COMPILE_CACHE,
-# NODE_REPL_EXTERNAL_MODULE and JDK_JAVA_OPTIONS, and it is the source of _JAVA_OPTIONS.
+# (zshparam(1)). The guard refuses each GIT_ key but the five that devops-cli callers set and
+# that run no program (git(1)). git reads configuration values from GIT_CONFIG_COUNT with its
+# numbered KEY and VALUE pairs and from GIT_CONFIG_PARAMETERS, which `git -c` sets, and a
+# configuration file from GIT_CONFIG_GLOBAL and GIT_CONFIG_SYSTEM (git-config(1), git(1)). It starts
+# the program of GIT_SSH, GIT_SSH_COMMAND, GIT_ASKPASS, GIT_EDITOR, GIT_SEQUENCE_EDITOR, GIT_PAGER
+# and GIT_EXTERNAL_DIFF (git(1)) and of GIT_PROXY_COMMAND (git-config(1)). It runs the git
+# commands of GIT_EXEC_PATH (git(1)) and the hooks of GIT_TEMPLATE_DIR (git-init(1)), and it
+# enables the ext:: transport with GIT_ALLOW_PROTOCOL (git(1)). With no GIT_EDITOR and no GIT_PAGER
+# it falls back to VISUAL, EDITOR and PAGER (git-var(1)), and less runs the filter of LESSOPEN
+# and LESSCLOSE (less(1)). The source of git runs the program of GIT_TEST_FSMONITOR
+# (fsmonitor-settings.c) and GIT_TEST_MAINT_SCHEDULER (builtin/gc.c), and the script
+# git-difftool--helper runs GIT_DIFFTOOL_EXTCMD. The script git-mergetool--lib reads a shell file
+# from MERGE_TOOLS_DIR. GIT_TRACE, GIT_TRACE2 and GIT_TRACE_CURL append to a file that the caller
+# names (git(1)). GIT_SSH_VARIANT, GIT_CONFIG_NOSYSTEM and GIT_EXAMPLE_KEY, which no page lists
+# as a program, pin the rule that a GIT_ key is refused unless the guard names it. The Python,
+# Node.js, Perl, Ruby and Java keys name a file, a module, a directory or an option that makes the
+# interpreter load code (python(1), node(1), perlrun(1), ruby(1), java(1), the JVM TI
+# specification). The default env_delete table of sudo lists each zsh and interpreter key but
+# PYTHONPLATLIBDIR, PYTHONPYCACHEPREFIX, NODE_COMPILE_CACHE, NODE_REPL_EXTERNAL_MODULE and
+# JDK_JAVA_OPTIONS, it is the source of _JAVA_OPTIONS, and it lists GIT_SSH_COMMAND and the
+# GIT_CONFIG_* family. GIT_CONFIG_KEY_12 and GIT_CONFIG_VALUE_12 pin the prefix rule of the pairs.
REFUSED_OVERRIDE_KEYS: tuple[str, ...] = (
"LD_AUDIT",
"LD_LIBRARY_PATH",
@@ -188,6 +208,40 @@ def test_build_subprocess_env_case_insensitivity(monkeypatch: pytest.MonkeyPatch
"FPATH",
"NULLCMD",
"READNULLCMD",
+ "GIT_CONFIG_COUNT",
+ "GIT_CONFIG_KEY_0",
+ "GIT_CONFIG_KEY_12",
+ "GIT_CONFIG_VALUE_0",
+ "GIT_CONFIG_VALUE_12",
+ "GIT_CONFIG_PARAMETERS",
+ "GIT_CONFIG_GLOBAL",
+ "GIT_CONFIG_SYSTEM",
+ "GIT_SSH",
+ "GIT_SSH_COMMAND",
+ "GIT_ASKPASS",
+ "GIT_EDITOR",
+ "GIT_SEQUENCE_EDITOR",
+ "GIT_PAGER",
+ "GIT_EXTERNAL_DIFF",
+ "GIT_PROXY_COMMAND",
+ "GIT_EXEC_PATH",
+ "GIT_TEMPLATE_DIR",
+ "GIT_ALLOW_PROTOCOL",
+ "GIT_TEST_FSMONITOR",
+ "GIT_TEST_MAINT_SCHEDULER",
+ "GIT_DIFFTOOL_EXTCMD",
+ "GIT_TRACE",
+ "GIT_TRACE2",
+ "GIT_TRACE_CURL",
+ "GIT_SSH_VARIANT",
+ "GIT_CONFIG_NOSYSTEM",
+ "GIT_EXAMPLE_KEY",
+ "MERGE_TOOLS_DIR",
+ "EDITOR",
+ "VISUAL",
+ "PAGER",
+ "LESSOPEN",
+ "LESSCLOSE",
"PYTHONPATH",
"PYTHONHOME",
"PYTHONSTARTUP",
@@ -220,7 +274,7 @@ def test_a_caller_override_that_loads_code_into_the_child_is_refused(
) -> None:
"""A caller override of a loader, glibc, shell or interpreter variable that loads or runs
code raises `SecurityError` that names the key, in upper and in lower case, with isolation on
- and off (#2151, #2205, #2433, #2429)."""
+ and off (#2151, #2205, #2433, #2429, #2483)."""
with pytest.raises(SecurityError) as refused:
build_subprocess_env(
env={"EXAMPLE_FLAG": "on", key: "libexample.so"}, isolate_env=isolate_env
@@ -237,8 +291,8 @@ def test_an_isolated_child_gets_no_refused_key_from_the_environment(
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""With isolation on, no key that the guard refuses from a caller reaches the child from the
- environment of the person, in upper or in lower case, for example `PYTHONPATH` and
- `PYTHONHOME` (#2429)."""
+ environment of the person, in upper or in lower case, for example `PYTHONPATH`,
+ `PYTHONHOME` and `GIT_CONFIG_GLOBAL` (#2429, #2483)."""
environment_keys = [*REFUSED_OVERRIDE_KEYS, *(key.lower() for key in REFUSED_OVERRIDE_KEYS)]
for key in environment_keys:
monkeypatch.setenv(key, "example")
@@ -270,6 +324,45 @@ def test_a_caller_override_outside_the_refused_families_reaches_the_child(
assert {key: env.get(key) for key in override} == override
+@pytest.mark.parametrize("isolate_env", [True, False], ids=["isolated", "not-isolated"])
+def test_a_git_key_that_devops_cli_sets_reaches_the_child(
+ isolate_env: bool, tmp_path: Path
+) -> None:
+ """The five git keys that callers set and that run no program, a key that starts with `GIT`
+ and has no underscore after it, a key that only contains a refused git name, and
+ `XDG_CONFIG_HOME`, which `devops openspec` sets, reach the child with their values (#2483)."""
+ override = {
+ "GIT_TERMINAL_PROMPT": "0",
+ "GIT_AUTHOR_NAME": "Example Author",
+ "GIT_AUTHOR_EMAIL": "author@example.com",
+ "GIT_COMMITTER_NAME": "Example Committer",
+ "GIT_COMMITTER_EMAIL": "committer@example.com",
+ "GITHUB_STEP_SUMMARY": str(tmp_path / "summary"),
+ "EXAMPLE_GIT_SSH_COMMAND": "example",
+ "XDG_CONFIG_HOME": str(tmp_path / "config"),
+ }
+
+ env = build_subprocess_env(env=override, isolate_env=isolate_env)
+
+ assert {key: env.get(key) for key in override} == override
+
+
+def test_the_git_environment_of_devops_cli_passes_the_guard() -> None:
+ """The environment that devops-cli gives its own git children passes the guard (#2483)."""
+ env = build_subprocess_env(env=CONST_GIT_NONINTERACTIVE_ENV)
+
+ assert {
+ key: env.get(key) for key in CONST_GIT_NONINTERACTIVE_ENV
+ } == CONST_GIT_NONINTERACTIVE_ENV
+
+
+@pytest.mark.parametrize("key", sorted(DEFAULT_ALLOWED_ENV_VARS))
+def test_no_key_of_the_ambient_allowlist_is_refused_from_a_caller(key: str) -> None:
+ """A key that an isolated child gets from the environment is not one that the guard refuses,
+ so a key added to the allowlist that a refused pattern matches fails here (#2483)."""
+ assert build_subprocess_env(env={key: "example"})[key] == "example"
+
+
@pytest.mark.parametrize("isolate_env", [True, False], ids=["isolated", "not-isolated"])
@pytest.mark.parametrize(
("override", "named_key"),