From e2b68fbc27402562d5b6b59f081c9b1fa4265f39 Mon Sep 17 00:00:00 2001 From: Daniel Petty Date: Thu, 29 Oct 2026 13:27:13 +0000 Subject: [PATCH 1/9] docs(openspec): plan the refusal of the git keys that run a program (#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. --- .../.openspec.yaml | 2 + .../2483-refuse-git-code-env-keys/design.md | 48 ++++++++++++++ .../2483-refuse-git-code-env-keys/proposal.md | 62 +++++++++++++++++++ .../specs/subprocess-environment/spec.md | 51 +++++++++++++++ .../2483-refuse-git-code-env-keys/tasks.md | 37 +++++++++++ 5 files changed, 200 insertions(+) create mode 100644 openspec/changes/2483-refuse-git-code-env-keys/.openspec.yaml create mode 100644 openspec/changes/2483-refuse-git-code-env-keys/design.md create mode 100644 openspec/changes/2483-refuse-git-code-env-keys/proposal.md create mode 100644 openspec/changes/2483-refuse-git-code-env-keys/specs/subprocess-environment/spec.md create mode 100644 openspec/changes/2483-refuse-git-code-env-keys/tasks.md diff --git a/openspec/changes/2483-refuse-git-code-env-keys/.openspec.yaml b/openspec/changes/2483-refuse-git-code-env-keys/.openspec.yaml new file mode 100644 index 0000000000..5c99d6d744 --- /dev/null +++ b/openspec/changes/2483-refuse-git-code-env-keys/.openspec.yaml @@ -0,0 +1,2 @@ +schema: spec-driven +created: 2026-10-29 diff --git a/openspec/changes/2483-refuse-git-code-env-keys/design.md b/openspec/changes/2483-refuse-git-code-env-keys/design.md new file mode 100644 index 0000000000..70773e4260 --- /dev/null +++ b/openspec/changes/2483-refuse-git-code-env-keys/design.md @@ -0,0 +1,48 @@ +# Design + +## Decisions + +- **The sources are the git manual pages and sudo.** sudo removes `GIT_SSH_COMMAND` and the `GIT_CONFIG_*` family before it runs a program for another user (`initial_badenv_table` of `plugins/sudoers/env.c`). The pages `git(1)`, `git-config(1)`, `git-init(1)` and `git-var(1)` name the other keys. A probe with git 2.55.0 confirms that each refused key makes git run a program (proposal, Feasibility). +- **The refused keys, with their sources.** + + | Group | Keys | Source | + | :--- | :--- | :--- | + | Configuration | `GIT_CONFIG_COUNT`, `GIT_CONFIG_KEY_`, `GIT_CONFIG_VALUE_`, `GIT_CONFIG_GLOBAL`, `GIT_CONFIG_SYSTEM` | `git-config(1)`, sudo, probe | + | Configuration | `GIT_CONFIG_PARAMETERS` | `git(1)` option `-c`, probe | + | Program | `GIT_SSH`, `GIT_SSH_COMMAND`, `GIT_ASKPASS`, `GIT_EDITOR`, `GIT_SEQUENCE_EDITOR`, `GIT_PAGER`, `GIT_EXTERNAL_DIFF`, `GIT_EXEC_PATH` | `git(1)`, sudo for `GIT_SSH_COMMAND`, probe | + | Program | `GIT_PROXY_COMMAND` | `git-config(1)`, `core.gitProxy`, probe | + | Directory | `GIT_TEMPLATE_DIR` | `git-init(1)`, probe | + | Fall-back | `EDITOR`, `VISUAL`, `PAGER` | `git-var(1)`, probe | + +- **Exact names, with a prefix only for the numbered keys.** The constant lists each key by its name, and `GIT_CONFIG_KEY_*` and `GIT_CONFIG_VALUE_*` for the pairs that `GIT_CONFIG_COUNT` counts. sudo refuses the whole `GIT_CONFIG_*` family. That family also holds `GIT_CONFIG_NOSYSTEM`, which makes git skip the system file and runs no program, and a caller can have a reason to set it. #2429 made the same choice for `PYTHONUNBUFFERED` and `NODE_ENV`. The test of the accepted overrides pins `GIT_CONFIG_NOSYSTEM`, `GIT_SSH_VARIANT`, `GIT_TERMINAL_PROMPT`, the author and committer keys, and two names that only contain a refused name. +- **A key that runs a program only in some runs is refused too.** `GIT_ASKPASS` runs only when git asks for a password. The editor keys run only for a commit message or a rebase list, and the pager keys only on a terminal. `GIT_EXEC_PATH` runs a program only for a git command that is not built in. A caller has no reason to set one of these keys, and the value is a program or the place of one, as #2429 decided for `PS4`, `FPATH` and `PYTHONSTARTUP`. +- **`EDITOR`, `VISUAL` and `PAGER` are refused with the git keys.** `git-var(1)` says that git uses `$VISUAL`, then `$EDITOR`, when `GIT_EDITOR` and `core.editor` are not set, and `$PAGER` when `GIT_PAGER` and `core.pager` are not set. The probe ran the program of each. A refusal of `GIT_EDITOR` alone leaves the other keys that name the same program. No file of `src/` sets or reads these keys 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`. Then no allowed key or prefix matches a refused pattern, and the test of #2429 pins this with every refused key in the environment. This is the rule of the spec requirement "An isolated child gets no refused key from the environment", and #2429 removed `PYTHONPATH` and `PYTHONHOME` on the same ground. The default `env_reset` of sudo keeps neither `EDITOR` nor `PAGER` either. A person who wants an ambient value in a child keeps two paths: `isolate_env=False`, and the `extra_allowed_env` of a caller. +- **The own override moves to the argument list of git.** The path of the override is a caller override of `build_subprocess_env`: `render_at_revision` passes `CONST_GIT_NONINTERACTIVE_ENV` as `env` to the runner. 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`, a key that the guard accepts. `-c` is the option of git for a one-run configuration value, and it beats the configuration files. The guard keeps no exception, no flag and no list of trusted values, and the code that chooses the option is the code of devops-cli, not a caller of the guard. The option goes only to the fetch, the one command that opens an SSH connection, and not to `git init`, `git checkout` and `kubectl kustomize`, which the old override reached for no reason. With isolation on, an ambient `GIT_SSH_COMMAND` never reaches the child, so it cannot take precedence over `core.sshCommand`. +- **The `git config --global` calls name `GIT_CONFIG_GLOBAL`.** With the key out of the allowlist, `git config --global` writes `$HOME/.gitconfig`, and git of the person reads `GIT_CONFIG_GLOBAL` alone when it is set. The three calls (the signing keys of `ssh register` and `ssh rotate`, and the two defaults of `devcontainer post-start`) give `extra_allowed_env={"GIT_CONFIG_GLOBAL"}` through `CONST_GIT_GLOBAL_CONFIG_ENV`. 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. The git block adds one short comment above each group of keys, with the pages that name them, for example `# git-config(1)`. Each key has its source next to it. The block sits between the zsh keys and the Python keys, and the test list follows the same order, so a later change that appends a group at the end of the tuple (#2503) 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 in its sentence and scenarios. A MODIFIED copy would conflict with #2503, which changes the same requirement. The new requirements add the git refusal, the accepted git keys, the SSH option of the fetch and the `git config --global` file. The purpose of the spec names the git child, and 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 behaviour file of the guard.** `tests/test_subprocess_env_boundary.py` takes the refused git keys in `REFUSED_OVERRIDE_KEYS`, so the existing tests of the override and of the ambient environment cover them. The fetch test is in `tests/test_k8s_argocd_overrides.py`, and the `git config --global` test is 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 works on the program name, so it reaches every git child, for example a release push, which #1124 runs with the environment of the person. It replaces the `core.sshCommand` of the person too. A pin that reaches one call needs a flag on `run_subprocess`, which is the bypass below. +- **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 whole `GIT_CONFIG_*` family, as sudo does.** It refuses `GIT_CONFIG_NOSYSTEM`, which runs no program. +- **Refuse every `GIT_*` key that is not on a list.** It refuses `GIT_DIR`, `GIT_INDEX_FILE`, `GIT_WORK_TREE`, `GIT_TRACE` and the other keys that a caller has a reason to set. A new safe key of git then needs a review before it works. The probe shows which keys run a program, so the refusal lists them. +- **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 + +- `GIT_DIR`, `GIT_WORK_TREE`, `GIT_COMMON_DIR`, `GIT_INDEX_FILE`, `GIT_OBJECT_DIRECTORY` and `GIT_ALTERNATE_OBJECT_DIRECTORIES` point git at a repository. Git runs a program only through the configuration of a repository that the caller chose, as it does for the `cwd` of the caller. Git hooks set these keys, and a caller that runs git inside a hook needs them. +- `GIT_CONFIG_NOSYSTEM`, `GIT_SSH_VARIANT`, `GIT_TERMINAL_PROMPT`, `GIT_AUTHOR_*` and `GIT_COMMITTER_*` run no program. +- `GIT_TRACE*` writes to a file that the caller names and runs no program. +- `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 for the reason that #2429 gives: a caller must be able to give a child its own home directory. + +## 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, and no probe of them ran. diff --git a/openspec/changes/2483-refuse-git-code-env-keys/proposal.md b/openspec/changes/2483-refuse-git-code-env-keys/proposal.md new file mode 100644 index 0000000000..6d4c73591b --- /dev/null +++ b/openspec/changes/2483-refuse-git-code-env-keys/proposal.md @@ -0,0 +1,62 @@ +# Proposal + +## Why + +Issue #2483: the subprocess environment guard accepts the 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 loader, gconv, bash, zsh and interpreter keys (#2205, #2433, #2429). It has no git key. +- A caller override of `GIT_CONFIG_COUNT` with `GIT_CONFIG_KEY_` and `GIT_CONFIG_VALUE_` gives git a configuration value. A value such as `core.fsmonitor`, `core.sshCommand`, `core.pager` or an alias that starts with `!` runs a program. `GIT_CONFIG_PARAMETERS`, which `git -c` sets, does the same. +- `GIT_SSH_COMMAND` and `GIT_SSH` name the program that git starts for an SSH remote. `GIT_CONFIG_GLOBAL` and `GIT_CONFIG_SYSTEM` name a configuration file. `GIT_EXEC_PATH` names the directory of the git sub-programs. `GIT_ASKPASS`, `GIT_EDITOR`, `GIT_SEQUENCE_EDITOR`, `GIT_PAGER`, `GIT_EXTERNAL_DIFF` and `GIT_PROXY_COMMAND` name a program. `GIT_TEMPLATE_DIR` names a directory whose hooks git copies into a new repository. `EDITOR`, `VISUAL` and `PAGER` are the fall-back keys of the editor and the pager of git. +- `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` itself, in `render_at_revision` of `src/devops_cli/k8s/argocd_overrides.py`, as a caller override of `build_subprocess_env`. A guard that refuses `GIT_SSH_COMMAND` stops that fetch, so the change moves the option out of the environment. + +## What Changes + +- `CONST_CODE_LOADING_ENV_PATTERNS` in `src/devops_cli/config/constants.py` adds the git group of the design, in its own block with the manual page of each key. A caller override of one of these keys raises the same `SecurityError` as the other refused keys, with isolation on and off. The keys that git documents and that run no program stay accepted: `GIT_AUTHOR_NAME`, `GIT_AUTHOR_EMAIL`, `GIT_COMMITTER_NAME`, `GIT_COMMITTER_EMAIL`, `GIT_TERMINAL_PROMPT`, `GIT_CONFIG_NOSYSTEM` and `GIT_SSH_VARIANT`. +- `DEFAULT_ALLOWED_ENV_VARS` in `src/devops_cli/core/process.py` removes `GIT_CONFIG_GLOBAL`, `GIT_CONFIG_SYSTEM`, `GIT_EXEC_PATH`, `EDITOR` and `PAGER`. Thus no key that the guard refuses reaches an isolated child from the environment of the person. +- `render_at_revision` gives `git fetch` the option `-c core.sshCommand=ssh -o BatchMode=yes` in its argument list, and `CONST_GIT_NONINTERACTIVE_ENV` keeps only `GIT_TERMINAL_PROMPT=0`. The option has the same effect as the old override, and no environment key carries it. +- The three `git config --global` calls (`configure_git_signing` of `src/devops_cli/crypto/ssh_keys.py` and the two git defaults of `src/devops_cli/commands/devcontainer.py`) name `GIT_CONFIG_GLOBAL` in `extra_allowed_env`, so that they write the file that `git config --global` writes in the shell of the person. +- The child environment bullet of `ARCHITECTURE.md` and the purpose of the `subprocess-environment` spec name the git keys as refused keys, and no longer as keys that reach the child. +- 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 refused caller overrides add the git keys that make git run a program, and an isolated child gets none of them from the environment unless the caller names it. 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, a repository made with `git init`, and a key whose value prints a marker. Each printed its marker, so git ran the program: + - `GIT_CONFIG_SYSTEM` with a file that sets `core.fsmonitor`, and `GIT_CONFIG_PARAMETERS='core.fsmonitor=...'`, with `git status`. + - `GIT_SSH_COMMAND`, and `GIT_SSH` with an executable file, with `git ls-remote ssh://host.invalid/x`. + - `GIT_PROXY_COMMAND` with `git ls-remote git://host.invalid/x`. + - `GIT_EXEC_PATH` with a directory that holds `git-frobnicate` (`git frobnicate`) and `git-remote-https` (`git ls-remote https://example.invalid/x`). + - `GIT_ASKPASS` with `git credential fill`. + - `GIT_EDITOR`, `EDITOR` and `VISUAL` (with `TERM=xterm`) with `git commit --allow-empty`, and `GIT_SEQUENCE_EDITOR` with `git rebase -i --root`. + - `GIT_EXTERNAL_DIFF` with `git diff`. + - `GIT_TEMPLATE_DIR` with a `hooks/post-checkout` file, with `git clone`. + - `GIT_PAGER` and `PAGER` with `git log -1` on a pseudo-terminal that `script(1)` made. +- With `GIT_CONFIG_NOSYSTEM=1`, git did not read the `GIT_CONFIG_SYSTEM` file, so that key runs no program. The `git(1)` page lists `GIT_AUTHOR_*`, `GIT_COMMITTER_*`, `GIT_TERMINAL_PROMPT` and `GIT_SSH_VARIANT` with no program. +- The manual pages of git 2.55.0 list the keys: `git(1)`, `git-config(1)`, `git-init(1)` and `git-var(1)`. No page lists `GIT_CONFIG_PARAMETERS`: it is the variable that `git -c` uses for the child processes of git, and the probe shows its effect. +- 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`, that is `_run_cmd` of `src/devops_cli/commands/k8s/cluster_runtime.py`, with `env=dict(CONST_GIT_NONINTERACTIVE_ENV)`. `_run_cmd` calls `run_subprocess`, and `run_subprocess` calls `build_subprocess_env(env=...)`. It is a caller override. It is the only use of `CONST_GIT_NONINTERACTIVE_ENV`. The other callers that set a git key give only `GIT_TERMINAL_PROMPT=0` (`roadmap/refine.py`, `roadmap/refine_investigation.py`, `ai/review/samples.py`). +- `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. 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`, which redirects them to a file below `tmp_path`. + +## 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. The `git(1)`, `git-config(1)`, `git-init(1)` and `git-var(1)` pages name the others, and the probes confirm each one. No library publishes the list for import, so the constant copies the keys and 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, so the change builds no pin step and no bypass. The change deletes the five keys from the ambient allowlist and the SSH key from `CONST_GIT_NONINTERACTIVE_ENV`. diff --git a/openspec/changes/2483-refuse-git-code-env-keys/specs/subprocess-environment/spec.md b/openspec/changes/2483-refuse-git-code-env-keys/specs/subprocess-environment/spec.md new file mode 100644 index 0000000000..2a37b3af98 --- /dev/null +++ b/openspec/changes/2483-refuse-git-code-env-keys/specs/subprocess-environment/spec.md @@ -0,0 +1,51 @@ +## ADDED Requirements + +### Requirement: A caller override that makes git run a program is refused +`build_subprocess_env` SHALL raise `SecurityError` with the message "Prohibited dangerous environment variable override: ''" and the error code `SECURITY_ERROR` when the upper-case form of a key of the caller override is a git key that a scenario of this requirement names, or starts with `GIT_CONFIG_KEY_` or `GIT_CONFIG_VALUE_`. It SHALL do this with environment isolation on and off. + +#### Scenario: A git configuration value +- **WHEN** a caller builds a child environment with the override `GIT_CONFIG_COUNT`, `GIT_CONFIG_KEY_0`, `GIT_CONFIG_VALUE_0`, `GIT_CONFIG_KEY_12`, `GIT_CONFIG_VALUE_12` or `GIT_CONFIG_PARAMETERS`, in upper or lower case +- **THEN** `build_subprocess_env` raises `SecurityError` that names the key, with the error code `SECURITY_ERROR` + +#### Scenario: A git configuration file +- **WHEN** a caller builds a child environment with the override `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 +- **WHEN** a caller builds a child environment with the override `GIT_EXEC_PATH` or `GIT_TEMPLATE_DIR`, in upper or lower case +- **THEN** `build_subprocess_env` raises `SecurityError` that names the key, with the error code `SECURITY_ERROR` + +#### Scenario: The editor and the pager that git falls back to +- **WHEN** a caller builds a child environment with the override `EDITOR`, `VISUAL` or `PAGER`, 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 runs no program reaches the child +`build_subprocess_env` SHALL put each git key of the caller override that runs no program in the child environment with its value, and each key that contains a refused git name but does not start with it. + +#### Scenario: Git keys that run no program and keys that look like a refused key +- **WHEN** a caller builds a child environment with the overrides `GIT_AUTHOR_NAME`, `GIT_AUTHOR_EMAIL`, `GIT_COMMITTER_NAME`, `GIT_COMMITTER_EMAIL`, `GIT_TERMINAL_PROMPT`, `GIT_CONFIG_NOSYSTEM`, `GIT_SSH_VARIANT`, `GIT_CONFIGURATION` and `EXAMPLE_GIT_SSH_COMMAND` +- **THEN** the child environment holds each of these keys with its value, with isolation on and off + +### 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`, and 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 the production runner +- **WHEN** `render_at_revision` fetches the SSH remote `ssh://git@example.com/repository.git` through `_run_cmd`, 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 of the process holds `GIT_CONFIG_GLOBAL`, each call writes its setting 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/2483-refuse-git-code-env-keys/tasks.md b/openspec/changes/2483-refuse-git-code-env-keys/tasks.md new file mode 100644 index 0000000000..b3c7f865aa --- /dev/null +++ b/openspec/changes/2483-refuse-git-code-env-keys/tasks.md @@ -0,0 +1,37 @@ +# Tasks + +## 1. The guard refuses the git keys that make git run a program + +- [ ] 1.1 Add failing tests: a caller override of each git key of the design, in upper and lower case, raises `SecurityError` with isolation on and off; with each of them in the environment, the isolated child holds none; `GIT_AUTHOR_NAME`, `GIT_COMMITTER_EMAIL`, `GIT_TERMINAL_PROMPT`, `GIT_CONFIG_NOSYSTEM`, `GIT_SSH_VARIANT`, `GIT_CONFIGURATION` and `EXAMPLE_GIT_SSH_COMMAND` reach the child + - Verification: `uv run devops ci test tests/test_subprocess_env_boundary.py` +- [ ] 1.2 Add the git block to `CONST_CODE_LOADING_ENV_PATTERNS`, with the manual page of each group above its keys, and 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` +- [ ] 1.3 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 + +- [ ] 2.1 Add failing tests: `render_at_revision` through `_run_cmd` fetches an SSH remote with `-o BatchMode=yes` and raises no `SecurityError`; the fetch has `-c core.sshCommand=ssh -o BatchMode=yes` in its arguments; `CONST_GIT_NONINTERACTIVE_ENV` holds only `GIT_TERMINAL_PROMPT=0` + - Verification: `uv run devops ci test tests/test_k8s_argocd_overrides.py` +- [ ] 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` +- [ ] 2.3 Add a failing test: with `GIT_CONFIG_GLOBAL` in the environment, `devops devcontainer post-start` writes the two git defaults in that file and no `.gitconfig` in the home directory + - Verification: `uv run devops ci test tests/test_devcontainer.py` +- [ ] 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 + +- [ ] 3.1 Write the child environment bullet of `ARCHITECTURE.md` and the purpose of the `subprocess-environment` spec for the git keys, the `-c` option and the `extra_allowed_env` of the `git config --global` calls + - Verification: `uv run devops docs generate --sync-readme` and `uv run devops docs check` + +## 4. Archive + +- [ ] 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). From ec18e9ee23485d086afa87a6d0758ba4ed0acd88 Mon Sep 17 00:00:00 2001 From: Daniel Petty Date: Thu, 29 Oct 2026 13:29:28 +0000 Subject: [PATCH 2/9] test(security): the guard refuses the git keys that make git run a program (#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. --- .../2483-refuse-git-code-env-keys/tasks.md | 6 +- tests/test_devcontainer.py | 24 +++++++ tests/test_k8s_argocd_overrides.py | 52 ++++++++++++++ tests/test_subprocess_env_boundary.py | 67 ++++++++++++++++--- 4 files changed, 138 insertions(+), 11 deletions(-) diff --git a/openspec/changes/2483-refuse-git-code-env-keys/tasks.md b/openspec/changes/2483-refuse-git-code-env-keys/tasks.md index b3c7f865aa..8bed029723 100644 --- a/openspec/changes/2483-refuse-git-code-env-keys/tasks.md +++ b/openspec/changes/2483-refuse-git-code-env-keys/tasks.md @@ -2,7 +2,7 @@ ## 1. The guard refuses the git keys that make git run a program -- [ ] 1.1 Add failing tests: a caller override of each git key of the design, in upper and lower case, raises `SecurityError` with isolation on and off; with each of them in the environment, the isolated child holds none; `GIT_AUTHOR_NAME`, `GIT_COMMITTER_EMAIL`, `GIT_TERMINAL_PROMPT`, `GIT_CONFIG_NOSYSTEM`, `GIT_SSH_VARIANT`, `GIT_CONFIGURATION` and `EXAMPLE_GIT_SSH_COMMAND` reach the child +- [x] 1.1 Add failing tests: a caller override of each git key of the design, in upper and lower case, raises `SecurityError` with isolation on and off; with each of them in the environment, the isolated child holds none; `GIT_AUTHOR_NAME`, `GIT_COMMITTER_EMAIL`, `GIT_TERMINAL_PROMPT`, `GIT_CONFIG_NOSYSTEM`, `GIT_SSH_VARIANT`, `GIT_CONFIGURATION` and `EXAMPLE_GIT_SSH_COMMAND` reach the child - Verification: `uv run devops ci test tests/test_subprocess_env_boundary.py` - [ ] 1.2 Add the git block to `CONST_CODE_LOADING_ENV_PATTERNS`, with the manual page of each group above its keys, and 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` @@ -11,11 +11,11 @@ ## 2. The own git children pass the guard -- [ ] 2.1 Add failing tests: `render_at_revision` through `_run_cmd` fetches an SSH remote with `-o BatchMode=yes` and raises no `SecurityError`; the fetch has `-c core.sshCommand=ssh -o BatchMode=yes` in its arguments; `CONST_GIT_NONINTERACTIVE_ENV` holds only `GIT_TERMINAL_PROMPT=0` +- [x] 2.1 Add failing tests: `render_at_revision` through `_run_cmd` fetches an SSH remote with `-o BatchMode=yes` and raises no `SecurityError`; the fetch has `-c core.sshCommand=ssh -o BatchMode=yes` in its arguments; `CONST_GIT_NONINTERACTIVE_ENV` holds only `GIT_TERMINAL_PROMPT=0` - Verification: `uv run devops ci test tests/test_k8s_argocd_overrides.py` - [ ] 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` -- [ ] 2.3 Add a failing test: with `GIT_CONFIG_GLOBAL` in the environment, `devops devcontainer post-start` writes the two git defaults in that file and no `.gitconfig` in the home directory +- [x] 2.3 Add a failing test: with `GIT_CONFIG_GLOBAL` in the environment, `devops devcontainer post-start` writes the two git defaults in that file and no `.gitconfig` in the home directory - Verification: `uv run devops ci test tests/test_devcontainer.py` - [ ] 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` 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..7096ffe934 100644 --- a/tests/test_k8s_argocd_overrides.py +++ b/tests/test_k8s_argocd_overrides.py @@ -10,6 +10,7 @@ import pytest import yaml +from devops_cli.commands.k8s.cluster_runtime import _run_cmd from devops_cli.config.constants import CONST_K8S_ARGOCD_HOMELAB_APPLICATIONS from devops_cli.exceptions.k8s import KubernetesContextError from devops_cli.k8s.argocd_overrides import ( @@ -208,6 +209,57 @@ def test_an_application_renders_what_its_revision_holds(tmp_path: Path) -> None: ] +def test_the_fetch_of_an_ssh_remote_starts_ssh_without_a_prompt_through_the_guard( + tmp_path: Path, monkeypatch: pytest.MonkeyPatch +) -> None: + """The runner of `deploy-stack` 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", _run_cmd) + + 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], **kwargs: object) -> subprocess.CompletedProcess[str]: + started.append((cmd, kwargs.get("env"))) # type: ignore[arg-type] + 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..2f0f5067e9 100644 --- a/tests/test_subprocess_env_boundary.py +++ b/tests/test_subprocess_env_boundary.py @@ -157,11 +157,19 @@ 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)). git reads configuration values from GIT_CONFIG_COUNT with its numbered KEY and +# VALUE pairs and from GIT_CONFIG_PARAMETERS, which `git -c` sets (git-config(1), git(1)). It reads +# a configuration file from GIT_CONFIG_GLOBAL and GIT_CONFIG_SYSTEM (git-config(1)), 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)), and runs the git commands +# of GIT_EXEC_PATH (git(1)) and the hooks of GIT_TEMPLATE_DIR (git-init(1)). With no GIT_EDITOR +# and no GIT_PAGER it falls back to VISUAL, EDITOR and PAGER (git-var(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, 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 +196,27 @@ 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", + "EDITOR", + "VISUAL", + "PAGER", "PYTHONPATH", "PYTHONHOME", "PYTHONSTARTUP", @@ -220,7 +249,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 +266,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 +299,28 @@ 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_runs_no_program_reaches_the_child(isolate_env: bool) -> None: + """The author and committer keys, `GIT_TERMINAL_PROMPT`, `GIT_CONFIG_NOSYSTEM` and + `GIT_SSH_VARIANT` run no program, and two names that only contain a refused git name are not + refused, so all of them reach the child with their values (#2483).""" + override = { + "GIT_AUTHOR_NAME": "Example Author", + "GIT_AUTHOR_EMAIL": "author@example.com", + "GIT_COMMITTER_NAME": "Example Committer", + "GIT_COMMITTER_EMAIL": "committer@example.com", + "GIT_TERMINAL_PROMPT": "0", + "GIT_CONFIG_NOSYSTEM": "1", + "GIT_SSH_VARIANT": "ssh", + "GIT_CONFIGURATION": "example", + "EXAMPLE_GIT_SSH_COMMAND": "example", + } + + env = build_subprocess_env(env=override, isolate_env=isolate_env) + + assert {key: env.get(key) for key in override} == override + + @pytest.mark.parametrize("isolate_env", [True, False], ids=["isolated", "not-isolated"]) @pytest.mark.parametrize( ("override", "named_key"), From 7e7c49ea2941e75bdb35565afb27c7803838bb43 Mon Sep 17 00:00:00 2001 From: Daniel Petty Date: Thu, 29 Oct 2026 13:34:10 +0000 Subject: [PATCH 3/9] fix(security): refuse the git keys that make git run a program (#2483) 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 --- ARCHITECTURE.md | 2 +- .../2483-refuse-git-code-env-keys/tasks.md | 10 ++--- openspec/specs/subprocess-environment/spec.md | 2 +- src/devops_cli/commands/devcontainer.py | 3 ++ src/devops_cli/config/constants.py | 37 ++++++++++++++++--- src/devops_cli/core/process.py | 5 --- src/devops_cli/crypto/ssh_keys.py | 12 +++++- src/devops_cli/k8s/argocd_overrides.py | 6 ++- 8 files changed, 57 insertions(+), 20 deletions(-) diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index 74298f06dc..7030562460 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -178,7 +178,7 @@ 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 holds the keys of git that make git run a program (#2483): the configuration, SSH, askpass, editor, pager, diff and proxy keys. It holds `GIT_EXEC_PATH` and `GIT_TEMPLATE_DIR` too, and `EDITOR`, `VISUAL` and `PAGER`, which git uses when its own keys are not set. 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`). The `git config --global` calls name `GIT_CONFIG_GLOBAL` in `extra_allowed_env`, so that they write the file that the person set. A caller that must give git an option puts it in the arguments, for example `git -c core.sshCommand=...`, and never in the environment. 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 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`. - **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/2483-refuse-git-code-env-keys/tasks.md b/openspec/changes/2483-refuse-git-code-env-keys/tasks.md index 8bed029723..8791f8ae9c 100644 --- a/openspec/changes/2483-refuse-git-code-env-keys/tasks.md +++ b/openspec/changes/2483-refuse-git-code-env-keys/tasks.md @@ -4,25 +4,25 @@ - [x] 1.1 Add failing tests: a caller override of each git key of the design, in upper and lower case, raises `SecurityError` with isolation on and off; with each of them in the environment, the isolated child holds none; `GIT_AUTHOR_NAME`, `GIT_COMMITTER_EMAIL`, `GIT_TERMINAL_PROMPT`, `GIT_CONFIG_NOSYSTEM`, `GIT_SSH_VARIANT`, `GIT_CONFIGURATION` and `EXAMPLE_GIT_SSH_COMMAND` reach the child - Verification: `uv run devops ci test tests/test_subprocess_env_boundary.py` -- [ ] 1.2 Add the git block to `CONST_CODE_LOADING_ENV_PATTERNS`, with the manual page of each group above its keys, and keep the comment of the constant at 25 words +- [x] 1.2 Add the git block to `CONST_CODE_LOADING_ENV_PATTERNS`, with the manual page of each group above its keys, and 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` -- [ ] 1.3 Remove `GIT_CONFIG_GLOBAL`, `GIT_CONFIG_SYSTEM`, `GIT_EXEC_PATH`, `EDITOR` and `PAGER` from `DEFAULT_ALLOWED_ENV_VARS` +- [x] 1.3 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_cmd` fetches an SSH remote with `-o BatchMode=yes` and raises no `SecurityError`; the fetch has `-c core.sshCommand=ssh -o BatchMode=yes` in its arguments; `CONST_GIT_NONINTERACTIVE_ENV` holds only `GIT_TERMINAL_PROMPT=0` - Verification: `uv run devops ci test tests/test_k8s_argocd_overrides.py` -- [ ] 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` +- [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 the two git defaults in that file and no `.gitconfig` in the home directory - Verification: `uv run devops ci test tests/test_devcontainer.py` -- [ ] 2.4 Add `CONST_GIT_GLOBAL_CONFIG_ENV`, and name it in `extra_allowed_env` of the three `git config --global` calls +- [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 -- [ ] 3.1 Write the child environment bullet of `ARCHITECTURE.md` and the purpose of the `subprocess-environment` spec for the git keys, the `-c` option and the `extra_allowed_env` of the `git config --global` calls +- [x] 3.1 Write the child environment bullet of `ARCHITECTURE.md` and the purpose of the `subprocess-environment` spec for the git keys, the `-c` option and the `extra_allowed_env` of the `git config --global` calls - Verification: `uv run devops docs generate --sync-readme` and `uv run devops docs check` ## 4. Archive diff --git a/openspec/specs/subprocess-environment/spec.md b/openspec/specs/subprocess-environment/spec.md index 9bc9acda5d..3230a18e3e 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 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..8f41471206 100644 --- a/src/devops_cli/config/constants.py +++ b/src/devops_cli/config/constants.py @@ -1069,11 +1069,14 @@ 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_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 +1554,30 @@ class WebhookExposure(StrEnum): "FPATH", "NULLCMD", "READNULLCMD", + # git-config(1), git(1) option -c + "GIT_CONFIG_COUNT", + "GIT_CONFIG_KEY_*", + "GIT_CONFIG_VALUE_*", + "GIT_CONFIG_PARAMETERS", + "GIT_CONFIG_GLOBAL", + "GIT_CONFIG_SYSTEM", + # git(1) + "GIT_SSH", + "GIT_SSH_COMMAND", + "GIT_ASKPASS", + "GIT_EDITOR", + "GIT_SEQUENCE_EDITOR", + "GIT_PAGER", + "GIT_EXTERNAL_DIFF", + "GIT_EXEC_PATH", + # git-config(1), core.gitProxy + "GIT_PROXY_COMMAND", + # git-init(1) + "GIT_TEMPLATE_DIR", + # git-var(1), the fall-back keys of GIT_EDITOR and GIT_PAGER + "VISUAL", + "EDITOR", + "PAGER", # python(1) "PYTHONPATH", "PYTHONHOME", diff --git a/src/devops_cli/core/process.py b/src/devops_cli/core/process.py index 9ad769951b..7b610aa8a9 100644 --- a/src/devops_cli/core/process.py +++ b/src/devops_cli/core/process.py @@ -94,15 +94,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", 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", From a56181a1ce7335070457f84c916de6c1a3921ac8 Mon Sep 17 00:00:00 2001 From: Daniel Petty Date: Thu, 29 Oct 2026 13:54:34 +0000 Subject: [PATCH 4/9] test(k8s): drive the SSH fetch test through run_subprocess (#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. --- tests/test_k8s_argocd_overrides.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/tests/test_k8s_argocd_overrides.py b/tests/test_k8s_argocd_overrides.py index 7096ffe934..e14daecb03 100644 --- a/tests/test_k8s_argocd_overrides.py +++ b/tests/test_k8s_argocd_overrides.py @@ -10,8 +10,8 @@ import pytest import yaml -from devops_cli.commands.k8s.cluster_runtime import _run_cmd 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, @@ -209,10 +209,24 @@ 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: - """The runner of `deploy-stack` gives git the environment of the fetch through the guard of + """`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" @@ -225,7 +239,7 @@ def test_the_fetch_of_an_ssh_remote_starts_ssh_without_a_prompt_through_the_guar source = ApplicationSource("ssh://git@example.com/repository.git", "main", "k8s/app") with pytest.raises(KubernetesContextError, match="fetch"): - render_at_revision(source, tmp_path / "work", _run_cmd) + render_at_revision(source, tmp_path / "work", _guarded_run) assert ssh_log.read_text(encoding="utf-8").splitlines()[0].startswith("-o BatchMode=yes ") @@ -238,8 +252,10 @@ def test_only_the_fetch_gets_the_ssh_option_and_every_command_gets_only_the_prom key (#2483).""" started: list[tuple[list[str], dict[str, str] | None]] = [] - def record(cmd: list[str], **kwargs: object) -> subprocess.CompletedProcess[str]: - started.append((cmd, kwargs.get("env"))) # type: ignore[arg-type] + 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") From 25fe987518bb085e8dac61b2e883a69fd2e884d4 Mon Sep 17 00:00:00 2001 From: Daniel Petty Date: Thu, 29 Oct 2026 13:55:51 +0000 Subject: [PATCH 5/9] test(security): the guard refuses every git key that devops-cli does 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. --- tests/test_subprocess_env_boundary.py | 74 +++++++++++++++++++++------ 1 file changed, 57 insertions(+), 17 deletions(-) diff --git a/tests/test_subprocess_env_boundary.py b/tests/test_subprocess_env_boundary.py index 2f0f5067e9..ff8144e998 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,14 +161,22 @@ 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)). git reads configuration values from GIT_CONFIG_COUNT with its numbered KEY and -# VALUE pairs and from GIT_CONFIG_PARAMETERS, which `git -c` sets (git-config(1), git(1)). It reads -# a configuration file from GIT_CONFIG_GLOBAL and GIT_CONFIG_SYSTEM (git-config(1)), 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)), and runs the git commands -# of GIT_EXEC_PATH (git(1)) and the hooks of GIT_TEMPLATE_DIR (git-init(1)). With no GIT_EDITOR -# and no GIT_PAGER it falls back to VISUAL, EDITOR and PAGER (git-var(1)). The Python, Node.js, -# Perl, Ruby and Java keys name a file, a module, a directory or an option that makes the +# (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 @@ -214,9 +226,22 @@ def test_build_subprocess_env_case_insensitivity(monkeypatch: pytest.MonkeyPatch "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", @@ -300,20 +325,19 @@ def test_a_caller_override_outside_the_refused_families_reaches_the_child( @pytest.mark.parametrize("isolate_env", [True, False], ids=["isolated", "not-isolated"]) -def test_a_git_key_that_runs_no_program_reaches_the_child(isolate_env: bool) -> None: - """The author and committer keys, `GIT_TERMINAL_PROMPT`, `GIT_CONFIG_NOSYSTEM` and - `GIT_SSH_VARIANT` run no program, and two names that only contain a refused git name are not - refused, so all of them reach the child with their values (#2483).""" +def test_a_git_key_that_devops_cli_sets_reaches_the_child(isolate_env: bool) -> None: + """The five git keys that callers set and that run no program, a key of git that has no + underscore after `GIT`, 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", - "GIT_TERMINAL_PROMPT": "0", - "GIT_CONFIG_NOSYSTEM": "1", - "GIT_SSH_VARIANT": "ssh", - "GIT_CONFIGURATION": "example", + "GITHUB_STEP_SUMMARY": "/tmp/example-summary", "EXAMPLE_GIT_SSH_COMMAND": "example", + "XDG_CONFIG_HOME": "/tmp/example-config", } env = build_subprocess_env(env=override, isolate_env=isolate_env) @@ -321,6 +345,22 @@ def test_a_git_key_that_runs_no_program_reaches_the_child(isolate_env: bool) -> 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"), From 3144c3fb4083bab6f895ead517e5c3b2b8869ac6 Mon Sep 17 00:00:00 2001 From: Daniel Petty Date: Thu, 29 Oct 2026 14:00:56 +0000 Subject: [PATCH 6/9] fix(security): the guard refuses every git key that devops-cli does not 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. --- .../2483-refuse-git-code-env-keys/tasks.md | 16 ++++---- src/devops_cli/config/constants.py | 39 +++++++++---------- src/devops_cli/core/process.py | 11 +++++- 3 files changed, 38 insertions(+), 28 deletions(-) diff --git a/openspec/changes/2483-refuse-git-code-env-keys/tasks.md b/openspec/changes/2483-refuse-git-code-env-keys/tasks.md index 8791f8ae9c..e7dee0a733 100644 --- a/openspec/changes/2483-refuse-git-code-env-keys/tasks.md +++ b/openspec/changes/2483-refuse-git-code-env-keys/tasks.md @@ -1,28 +1,30 @@ # Tasks -## 1. The guard refuses the git keys that make git run a program +## 1. The guard refuses the git keys that devops-cli does not set -- [x] 1.1 Add failing tests: a caller override of each git key of the design, in upper and lower case, raises `SecurityError` with isolation on and off; with each of them in the environment, the isolated child holds none; `GIT_AUTHOR_NAME`, `GIT_COMMITTER_EMAIL`, `GIT_TERMINAL_PROMPT`, `GIT_CONFIG_NOSYSTEM`, `GIT_SSH_VARIANT`, `GIT_CONFIGURATION` and `EXAMPLE_GIT_SSH_COMMAND` reach the child +- [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 the git block to `CONST_CODE_LOADING_ENV_PATTERNS`, with the manual page of each group above its keys, and keep the comment of the constant at 25 words +- [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.3 Remove `GIT_CONFIG_GLOBAL`, `GIT_CONFIG_SYSTEM`, `GIT_EXEC_PATH`, `EDITOR` and `PAGER` from `DEFAULT_ALLOWED_ENV_VARS` +- [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_cmd` fetches an SSH remote with `-o BatchMode=yes` and raises no `SecurityError`; the fetch has `-c core.sshCommand=ssh -o BatchMode=yes` in its arguments; `CONST_GIT_NONINTERACTIVE_ENV` holds only `GIT_TERMINAL_PROMPT=0` +- [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 the two git defaults in that file and no `.gitconfig` in the home directory +- [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 bullet of `ARCHITECTURE.md` and the purpose of the `subprocess-environment` spec for the git keys, the `-c` option and the `extra_allowed_env` of the `git config --global` calls +- [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 diff --git a/src/devops_cli/config/constants.py b/src/devops_cli/config/constants.py index 8f41471206..6725abc301 100644 --- a/src/devops_cli/config/constants.py +++ b/src/devops_cli/config/constants.py @@ -1074,6 +1074,18 @@ 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).""" @@ -1554,30 +1566,17 @@ class WebhookExposure(StrEnum): "FPATH", "NULLCMD", "READNULLCMD", - # git-config(1), git(1) option -c - "GIT_CONFIG_COUNT", - "GIT_CONFIG_KEY_*", - "GIT_CONFIG_VALUE_*", - "GIT_CONFIG_PARAMETERS", - "GIT_CONFIG_GLOBAL", - "GIT_CONFIG_SYSTEM", - # git(1) - "GIT_SSH", - "GIT_SSH_COMMAND", - "GIT_ASKPASS", - "GIT_EDITOR", - "GIT_SEQUENCE_EDITOR", - "GIT_PAGER", - "GIT_EXTERNAL_DIFF", - "GIT_EXEC_PATH", - # git-config(1), core.gitProxy - "GIT_PROXY_COMMAND", - # git-init(1) - "GIT_TEMPLATE_DIR", + # 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 7b610aa8a9..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, ) @@ -135,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, *, @@ -181,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}'") From 9e59e0ec56ef08a7a09414a68cdc058880884cfc Mon Sep 17 00:00:00 2001 From: Daniel Petty Date: Thu, 29 Oct 2026 14:01:09 +0000 Subject: [PATCH 7/9] docs(openspec): plan the deny-by-default rule for git keys, in short 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. --- ARCHITECTURE.md | 3 +- .../2483-refuse-git-code-env-keys/design.md | 49 +++++++--------- .../2483-refuse-git-code-env-keys/proposal.md | 58 ++++++++++--------- .../specs/subprocess-environment/spec.md | 55 +++++++++++------- 4 files changed, 89 insertions(+), 76 deletions(-) diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index 7030562460..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 holds the keys of git that make git run a program (#2483): the configuration, SSH, askpass, editor, pager, diff and proxy keys. It holds `GIT_EXEC_PATH` and `GIT_TEMPLATE_DIR` too, and `EDITOR`, `VISUAL` and `PAGER`, which git uses when its own keys are not set. 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`). The `git config --global` calls name `GIT_CONFIG_GLOBAL` in `extra_allowed_env`, so that they write the file that the person set. A caller that must give git an option puts it in the arguments, for example `git -c core.sshCommand=...`, and never in the environment. 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 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/2483-refuse-git-code-env-keys/design.md b/openspec/changes/2483-refuse-git-code-env-keys/design.md index 70773e4260..eb9392f3f6 100644 --- a/openspec/changes/2483-refuse-git-code-env-keys/design.md +++ b/openspec/changes/2483-refuse-git-code-env-keys/design.md @@ -2,47 +2,38 @@ ## Decisions -- **The sources are the git manual pages and sudo.** sudo removes `GIT_SSH_COMMAND` and the `GIT_CONFIG_*` family before it runs a program for another user (`initial_badenv_table` of `plugins/sudoers/env.c`). The pages `git(1)`, `git-config(1)`, `git-init(1)` and `git-var(1)` name the other keys. A probe with git 2.55.0 confirms that each refused key makes git run a program (proposal, Feasibility). -- **The refused keys, with their sources.** - - | Group | Keys | Source | - | :--- | :--- | :--- | - | Configuration | `GIT_CONFIG_COUNT`, `GIT_CONFIG_KEY_`, `GIT_CONFIG_VALUE_`, `GIT_CONFIG_GLOBAL`, `GIT_CONFIG_SYSTEM` | `git-config(1)`, sudo, probe | - | Configuration | `GIT_CONFIG_PARAMETERS` | `git(1)` option `-c`, probe | - | Program | `GIT_SSH`, `GIT_SSH_COMMAND`, `GIT_ASKPASS`, `GIT_EDITOR`, `GIT_SEQUENCE_EDITOR`, `GIT_PAGER`, `GIT_EXTERNAL_DIFF`, `GIT_EXEC_PATH` | `git(1)`, sudo for `GIT_SSH_COMMAND`, probe | - | Program | `GIT_PROXY_COMMAND` | `git-config(1)`, `core.gitProxy`, probe | - | Directory | `GIT_TEMPLATE_DIR` | `git-init(1)`, probe | - | Fall-back | `EDITOR`, `VISUAL`, `PAGER` | `git-var(1)`, probe | - -- **Exact names, with a prefix only for the numbered keys.** The constant lists each key by its name, and `GIT_CONFIG_KEY_*` and `GIT_CONFIG_VALUE_*` for the pairs that `GIT_CONFIG_COUNT` counts. sudo refuses the whole `GIT_CONFIG_*` family. That family also holds `GIT_CONFIG_NOSYSTEM`, which makes git skip the system file and runs no program, and a caller can have a reason to set it. #2429 made the same choice for `PYTHONUNBUFFERED` and `NODE_ENV`. The test of the accepted overrides pins `GIT_CONFIG_NOSYSTEM`, `GIT_SSH_VARIANT`, `GIT_TERMINAL_PROMPT`, the author and committer keys, and two names that only contain a refused name. -- **A key that runs a program only in some runs is refused too.** `GIT_ASKPASS` runs only when git asks for a password. The editor keys run only for a commit message or a rebase list, and the pager keys only on a terminal. `GIT_EXEC_PATH` runs a program only for a git command that is not built in. A caller has no reason to set one of these keys, and the value is a program or the place of one, as #2429 decided for `PS4`, `FPATH` and `PYTHONSTARTUP`. -- **`EDITOR`, `VISUAL` and `PAGER` are refused with the git keys.** `git-var(1)` says that git uses `$VISUAL`, then `$EDITOR`, when `GIT_EDITOR` and `core.editor` are not set, and `$PAGER` when `GIT_PAGER` and `core.pager` are not set. The probe ran the program of each. A refusal of `GIT_EDITOR` alone leaves the other keys that name the same program. No file of `src/` sets or reads these keys 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`. Then no allowed key or prefix matches a refused pattern, and the test of #2429 pins this with every refused key in the environment. This is the rule of the spec requirement "An isolated child gets no refused key from the environment", and #2429 removed `PYTHONPATH` and `PYTHONHOME` on the same ground. The default `env_reset` of sudo keeps neither `EDITOR` nor `PAGER` either. A person who wants an ambient value in a child keeps two paths: `isolate_env=False`, and the `extra_allowed_env` of a caller. -- **The own override moves to the argument list of git.** The path of the override is a caller override of `build_subprocess_env`: `render_at_revision` passes `CONST_GIT_NONINTERACTIVE_ENV` as `env` to the runner. 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`, a key that the guard accepts. `-c` is the option of git for a one-run configuration value, and it beats the configuration files. The guard keeps no exception, no flag and no list of trusted values, and the code that chooses the option is the code of devops-cli, not a caller of the guard. The option goes only to the fetch, the one command that opens an SSH connection, and not to `git init`, `git checkout` and `kubectl kustomize`, which the old override reached for no reason. With isolation on, an ambient `GIT_SSH_COMMAND` never reaches the child, so it cannot take precedence over `core.sshCommand`. -- **The `git config --global` calls name `GIT_CONFIG_GLOBAL`.** With the key out of the allowlist, `git config --global` writes `$HOME/.gitconfig`, and git of the person reads `GIT_CONFIG_GLOBAL` alone when it is set. The three calls (the signing keys of `ssh register` and `ssh rotate`, and the two defaults of `devcontainer post-start`) give `extra_allowed_env={"GIT_CONFIG_GLOBAL"}` through `CONST_GIT_GLOBAL_CONFIG_ENV`. 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. The git block adds one short comment above each group of keys, with the pages that name them, for example `# git-config(1)`. Each key has its source next to it. The block sits between the zsh keys and the Python keys, and the test list follows the same order, so a later change that appends a group at the end of the tuple (#2503) 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 in its sentence and scenarios. A MODIFIED copy would conflict with #2503, which changes the same requirement. The new requirements add the git refusal, the accepted git keys, the SSH option of the fetch and the `git config --global` file. The purpose of the spec names the git child, and 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 behaviour file of the guard.** `tests/test_subprocess_env_boundary.py` takes the refused git keys in `REFUSED_OVERRIDE_KEYS`, so the existing tests of the override and of the ambient environment cover them. The fetch test is in `tests/test_k8s_argocd_overrides.py`, and the `git config --global` test is in `tests/test_devcontainer.py` and the existing `tests/test_ssh.py`. +- **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 works on the program name, so it reaches every git child, for example a release push, which #1124 runs with the environment of the person. It replaces the `core.sshCommand` of the person too. A pin that reaches one call needs a flag on `run_subprocess`, which is the bypass below. +- **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 whole `GIT_CONFIG_*` family, as sudo does.** It refuses `GIT_CONFIG_NOSYSTEM`, which runs no program. -- **Refuse every `GIT_*` key that is not on a list.** It refuses `GIT_DIR`, `GIT_INDEX_FILE`, `GIT_WORK_TREE`, `GIT_TRACE` and the other keys that a caller has a reason to set. A new safe key of git then needs a review before it works. The probe shows which keys run a program, so the refusal lists them. +- **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 -- `GIT_DIR`, `GIT_WORK_TREE`, `GIT_COMMON_DIR`, `GIT_INDEX_FILE`, `GIT_OBJECT_DIRECTORY` and `GIT_ALTERNATE_OBJECT_DIRECTORIES` point git at a repository. Git runs a program only through the configuration of a repository that the caller chose, as it does for the `cwd` of the caller. Git hooks set these keys, and a caller that runs git inside a hook needs them. -- `GIT_CONFIG_NOSYSTEM`, `GIT_SSH_VARIANT`, `GIT_TERMINAL_PROMPT`, `GIT_AUTHOR_*` and `GIT_COMMITTER_*` run no program. -- `GIT_TRACE*` writes to a file that the caller names and runs no program. -- `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 for the reason that #2429 gives: a caller must be able to give a child its own home directory. +- `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, and no probe of them ran. +- 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/2483-refuse-git-code-env-keys/proposal.md b/openspec/changes/2483-refuse-git-code-env-keys/proposal.md index 6d4c73591b..738cc01338 100644 --- a/openspec/changes/2483-refuse-git-code-env-keys/proposal.md +++ b/openspec/changes/2483-refuse-git-code-env-keys/proposal.md @@ -2,21 +2,25 @@ ## Why -Issue #2483: the subprocess environment guard accepts the git keys that make a git child run a program that its caller did not choose. +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 loader, gconv, bash, zsh and interpreter keys (#2205, #2433, #2429). It has no git key. -- A caller override of `GIT_CONFIG_COUNT` with `GIT_CONFIG_KEY_` and `GIT_CONFIG_VALUE_` gives git a configuration value. A value such as `core.fsmonitor`, `core.sshCommand`, `core.pager` or an alias that starts with `!` runs a program. `GIT_CONFIG_PARAMETERS`, which `git -c` sets, does the same. -- `GIT_SSH_COMMAND` and `GIT_SSH` name the program that git starts for an SSH remote. `GIT_CONFIG_GLOBAL` and `GIT_CONFIG_SYSTEM` name a configuration file. `GIT_EXEC_PATH` names the directory of the git sub-programs. `GIT_ASKPASS`, `GIT_EDITOR`, `GIT_SEQUENCE_EDITOR`, `GIT_PAGER`, `GIT_EXTERNAL_DIFF` and `GIT_PROXY_COMMAND` name a program. `GIT_TEMPLATE_DIR` names a directory whose hooks git copies into a new repository. `EDITOR`, `VISUAL` and `PAGER` are the fall-back keys of the editor and the pager of git. +- `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` itself, in `render_at_revision` of `src/devops_cli/k8s/argocd_overrides.py`, as a caller override of `build_subprocess_env`. A guard that refuses `GIT_SSH_COMMAND` stops that fetch, so the change moves the option out of the environment. +- 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 -- `CONST_CODE_LOADING_ENV_PATTERNS` in `src/devops_cli/config/constants.py` adds the git group of the design, in its own block with the manual page of each key. A caller override of one of these keys raises the same `SecurityError` as the other refused keys, with isolation on and off. The keys that git documents and that run no program stay accepted: `GIT_AUTHOR_NAME`, `GIT_AUTHOR_EMAIL`, `GIT_COMMITTER_NAME`, `GIT_COMMITTER_EMAIL`, `GIT_TERMINAL_PROMPT`, `GIT_CONFIG_NOSYSTEM` and `GIT_SSH_VARIANT`. -- `DEFAULT_ALLOWED_ENV_VARS` in `src/devops_cli/core/process.py` removes `GIT_CONFIG_GLOBAL`, `GIT_CONFIG_SYSTEM`, `GIT_EXEC_PATH`, `EDITOR` and `PAGER`. Thus no key that the guard refuses reaches an isolated child from the environment of the person. -- `render_at_revision` gives `git fetch` the option `-c core.sshCommand=ssh -o BatchMode=yes` in its argument list, and `CONST_GIT_NONINTERACTIVE_ENV` keeps only `GIT_TERMINAL_PROMPT=0`. The option has the same effect as the old override, and no environment key carries it. -- The three `git config --global` calls (`configure_git_signing` of `src/devops_cli/crypto/ssh_keys.py` and the two git defaults of `src/devops_cli/commands/devcontainer.py`) name `GIT_CONFIG_GLOBAL` in `extra_allowed_env`, so that they write the file that `git config --global` writes in the shell of the person. -- The child environment bullet of `ARCHITECTURE.md` and the purpose of the `subprocess-environment` spec name the git keys as refused keys, and no longer as keys that reach the child. +- 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. @@ -28,7 +32,7 @@ None. ### Modified Capabilities -- `subprocess-environment`: the refused caller overrides add the git keys that make git run a program, and an isolated child gets none of them from the environment unless the caller names it. The change adds requirements and rewrites no existing requirement. +- `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 @@ -40,23 +44,25 @@ None. - 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, a repository made with `git init`, and a key whose value prints a marker. Each printed its marker, so git ran the program: - - `GIT_CONFIG_SYSTEM` with a file that sets `core.fsmonitor`, and `GIT_CONFIG_PARAMETERS='core.fsmonitor=...'`, with `git status`. - - `GIT_SSH_COMMAND`, and `GIT_SSH` with an executable file, with `git ls-remote ssh://host.invalid/x`. - - `GIT_PROXY_COMMAND` with `git ls-remote git://host.invalid/x`. - - `GIT_EXEC_PATH` with a directory that holds `git-frobnicate` (`git frobnicate`) and `git-remote-https` (`git ls-remote https://example.invalid/x`). - - `GIT_ASKPASS` with `git credential fill`. - - `GIT_EDITOR`, `EDITOR` and `VISUAL` (with `TERM=xterm`) with `git commit --allow-empty`, and `GIT_SEQUENCE_EDITOR` with `git rebase -i --root`. - - `GIT_EXTERNAL_DIFF` with `git diff`. - - `GIT_TEMPLATE_DIR` with a `hooks/post-checkout` file, with `git clone`. - - `GIT_PAGER` and `PAGER` with `git log -1` on a pseudo-terminal that `script(1)` made. -- With `GIT_CONFIG_NOSYSTEM=1`, git did not read the `GIT_CONFIG_SYSTEM` file, so that key runs no program. The `git(1)` page lists `GIT_AUTHOR_*`, `GIT_COMMITTER_*`, `GIT_TERMINAL_PROMPT` and `GIT_SSH_VARIANT` with no program. -- The manual pages of git 2.55.0 list the keys: `git(1)`, `git-config(1)`, `git-init(1)` and `git-var(1)`. No page lists `GIT_CONFIG_PARAMETERS`: it is the variable that `git -c` uses for the child processes of git, and the probe shows its effect. +- 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`, that is `_run_cmd` of `src/devops_cli/commands/k8s/cluster_runtime.py`, with `env=dict(CONST_GIT_NONINTERACTIVE_ENV)`. `_run_cmd` calls `run_subprocess`, and `run_subprocess` calls `build_subprocess_env(env=...)`. It is a caller override. It is the only use of `CONST_GIT_NONINTERACTIVE_ENV`. The other callers that set a git key give only `GIT_TERMINAL_PROMPT=0` (`roadmap/refine.py`, `roadmap/refine_investigation.py`, `ai/review/samples.py`). +- 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. 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`, which redirects them to a file below `tmp_path`. +- 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. The `git(1)`, `git-config(1)`, `git-init(1)` and `git-var(1)` pages name the others, and the probes confirm each one. No library publishes the list for import, so the constant copies the keys and 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, so the change builds no pin step and no bypass. The change deletes the five keys from the ambient allowlist and the SSH key from `CONST_GIT_NONINTERACTIVE_ENV`. +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/2483-refuse-git-code-env-keys/specs/subprocess-environment/spec.md b/openspec/changes/2483-refuse-git-code-env-keys/specs/subprocess-environment/spec.md index 2a37b3af98..b14c33a4a9 100644 --- a/openspec/changes/2483-refuse-git-code-env-keys/specs/subprocess-environment/spec.md +++ b/openspec/changes/2483-refuse-git-code-env-keys/specs/subprocess-environment/spec.md @@ -1,45 +1,60 @@ ## ADDED Requirements -### Requirement: A caller override that makes git run a program is refused -`build_subprocess_env` SHALL raise `SecurityError` with the message "Prohibited dangerous environment variable override: ''" and the error code `SECURITY_ERROR` when the upper-case form of a key of the caller override is a git key that a scenario of this requirement names, or starts with `GIT_CONFIG_KEY_` or `GIT_CONFIG_VALUE_`. It SHALL do this with environment isolation on and off. +### 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 value -- **WHEN** a caller builds a child environment with the override `GIT_CONFIG_COUNT`, `GIT_CONFIG_KEY_0`, `GIT_CONFIG_VALUE_0`, `GIT_CONFIG_KEY_12`, `GIT_CONFIG_VALUE_12` or `GIT_CONFIG_PARAMETERS`, in upper or lower case -- **THEN** `build_subprocess_env` raises `SecurityError` that names the key, with the error code `SECURITY_ERROR` - -#### Scenario: A git configuration file -- **WHEN** a caller builds a child environment with the override `GIT_CONFIG_GLOBAL` or `GIT_CONFIG_SYSTEM`, in upper or lower case +#### 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 -- **WHEN** a caller builds a child environment with the override `GIT_EXEC_PATH` or `GIT_TEMPLATE_DIR`, in upper or lower case +#### 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 and the pager that git falls back to -- **WHEN** a caller builds a child environment with the override `EDITOR`, `VISUAL` or `PAGER`, in upper or lower case +#### 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 runs no program reaches the child -`build_subprocess_env` SHALL put each git key of the caller override that runs no program in the child environment with its value, and each key that contains a refused git name but does not start with it. +### 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: Git keys that run no program and keys that look like a refused key -- **WHEN** a caller builds a child environment with the overrides `GIT_AUTHOR_NAME`, `GIT_AUTHOR_EMAIL`, `GIT_COMMITTER_NAME`, `GIT_COMMITTER_EMAIL`, `GIT_TERMINAL_PROMPT`, `GIT_CONFIG_NOSYSTEM`, `GIT_SSH_VARIANT`, `GIT_CONFIGURATION` and `EXAMPLE_GIT_SSH_COMMAND` +#### 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`, and 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`. +`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 the production runner -- **WHEN** `render_at_revision` fetches the SSH remote `ssh://git@example.com/repository.git` through `_run_cmd`, and a stand-in `ssh` program is first on `PATH` +#### 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 of the process holds `GIT_CONFIG_GLOBAL`, each call writes its setting in the file that the key names, as `git config --global` does in a shell. +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 From 8c68ce218bd38f427398d6b064efccb01f3c6d3c Mon Sep 17 00:00:00 2001 From: Daniel Petty Date: Thu, 29 Oct 2026 14:05:18 +0000 Subject: [PATCH 8/9] chore(openspec): archive 2483-refuse-git-code-env-keys (#2483) --- .../.openspec.yaml | 0 .../design.md | 0 .../proposal.md | 0 .../specs/subprocess-environment/spec.md | 0 .../tasks.md | 2 +- openspec/specs/subprocess-environment/spec.md | 65 +++++++++++++++++++ 6 files changed, 66 insertions(+), 1 deletion(-) rename openspec/changes/{2483-refuse-git-code-env-keys => archive/2026-10-29-2483-refuse-git-code-env-keys}/.openspec.yaml (100%) rename openspec/changes/{2483-refuse-git-code-env-keys => archive/2026-10-29-2483-refuse-git-code-env-keys}/design.md (100%) rename openspec/changes/{2483-refuse-git-code-env-keys => archive/2026-10-29-2483-refuse-git-code-env-keys}/proposal.md (100%) rename openspec/changes/{2483-refuse-git-code-env-keys => archive/2026-10-29-2483-refuse-git-code-env-keys}/specs/subprocess-environment/spec.md (100%) rename openspec/changes/{2483-refuse-git-code-env-keys => archive/2026-10-29-2483-refuse-git-code-env-keys}/tasks.md (99%) diff --git a/openspec/changes/2483-refuse-git-code-env-keys/.openspec.yaml b/openspec/changes/archive/2026-10-29-2483-refuse-git-code-env-keys/.openspec.yaml similarity index 100% rename from openspec/changes/2483-refuse-git-code-env-keys/.openspec.yaml rename to openspec/changes/archive/2026-10-29-2483-refuse-git-code-env-keys/.openspec.yaml diff --git a/openspec/changes/2483-refuse-git-code-env-keys/design.md b/openspec/changes/archive/2026-10-29-2483-refuse-git-code-env-keys/design.md similarity index 100% rename from openspec/changes/2483-refuse-git-code-env-keys/design.md rename to openspec/changes/archive/2026-10-29-2483-refuse-git-code-env-keys/design.md diff --git a/openspec/changes/2483-refuse-git-code-env-keys/proposal.md b/openspec/changes/archive/2026-10-29-2483-refuse-git-code-env-keys/proposal.md similarity index 100% rename from openspec/changes/2483-refuse-git-code-env-keys/proposal.md rename to openspec/changes/archive/2026-10-29-2483-refuse-git-code-env-keys/proposal.md diff --git a/openspec/changes/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 similarity index 100% rename from openspec/changes/2483-refuse-git-code-env-keys/specs/subprocess-environment/spec.md rename to openspec/changes/archive/2026-10-29-2483-refuse-git-code-env-keys/specs/subprocess-environment/spec.md diff --git a/openspec/changes/2483-refuse-git-code-env-keys/tasks.md b/openspec/changes/archive/2026-10-29-2483-refuse-git-code-env-keys/tasks.md similarity index 99% rename from openspec/changes/2483-refuse-git-code-env-keys/tasks.md rename to openspec/changes/archive/2026-10-29-2483-refuse-git-code-env-keys/tasks.md index e7dee0a733..5ae90b55db 100644 --- a/openspec/changes/2483-refuse-git-code-env-keys/tasks.md +++ b/openspec/changes/archive/2026-10-29-2483-refuse-git-code-env-keys/tasks.md @@ -29,7 +29,7 @@ ## 4. Archive -- [ ] 4.1 Archive the change +- [x] 4.1 Archive the change - Verification: `uv run devops openspec archive 2483-refuse-git-code-env-keys` ## Workflow follow-up diff --git a/openspec/specs/subprocess-environment/spec.md b/openspec/specs/subprocess-environment/spec.md index 3230a18e3e..f22a54ccd5 100644 --- a/openspec/specs/subprocess-environment/spec.md +++ b/openspec/specs/subprocess-environment/spec.md @@ -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` From 71b1d160448c3edc6315dff205fd9433d4beafe8 Mon Sep 17 00:00:00 2001 From: Daniel Petty Date: Thu, 29 Oct 2026 14:15:28 +0000 Subject: [PATCH 9/9] test(security): use tmp_path, not a /tmp literal, in the git key test (#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. --- tests/test_subprocess_env_boundary.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/test_subprocess_env_boundary.py b/tests/test_subprocess_env_boundary.py index ff8144e998..8c433c30f0 100644 --- a/tests/test_subprocess_env_boundary.py +++ b/tests/test_subprocess_env_boundary.py @@ -325,19 +325,21 @@ def test_a_caller_override_outside_the_refused_families_reaches_the_child( @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) -> None: - """The five git keys that callers set and that run no program, a key of git that has no - underscore after `GIT`, a key that only contains a refused git name, and `XDG_CONFIG_HOME`, - which `devops openspec` sets, reach the child with their values (#2483).""" +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": "/tmp/example-summary", + "GITHUB_STEP_SUMMARY": str(tmp_path / "summary"), "EXAMPLE_GIT_SSH_COMMAND": "example", - "XDG_CONFIG_HOME": "/tmp/example-config", + "XDG_CONFIG_HOME": str(tmp_path / "config"), } env = build_subprocess_env(env=override, isolate_env=isolate_env)