Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ All external binaries run through `run_subprocess` / `run_subprocess_async` (`de
- Explicit bounded timeouts (default 1800 s) with standardized `TimeoutExpired` domain error translation.
- An audit-record writer (`devops_cli.core.audit.record_audit_event`, `.data/logs/audit.jsonl`) records each write of a config file (`save_settings`). It is not yet called from command or subprocess execution.
- Deterministic mock isolation protocols for fast offline unit testing, dry-run reporting, environment isolation, and OpenTelemetry spans.
- **Child environment**: With `isolate_env=True`, the default, `build_subprocess_env` gives a child the allowed keys of the environment, without credentials. With `isolate_env=False`, it gives the full environment, credentials included. It puts the `env` of the caller on top. It refuses with `SecurityError` a caller key that `CONST_CODE_LOADING_ENV_PATTERNS` lists. The list holds the loader keys of glibc and macOS, `GCONV_PATH`, and the keys of bash and zsh that run code. It also holds the keys of Python, Node.js, Perl, Ruby and Java that load code. An isolated child gets none of these keys from the environment, unless the caller names the key in `extra_allowed_keys` (`extra_allowed_env` of `run_subprocess`). Some keys that make a child run code still reach the child. `HOME` is one: zsh and Python read start-up files below it, so a caller that sets `HOME` gives a directory that it controls. The git keys that make git run a program are others, for example `GIT_SSH_COMMAND` and `GIT_CONFIG_GLOBAL` (#2483). The library keys that make a library load a module are others, for example `OPENSSL_CONF` (#2503). `build_subprocess_env` also refuses a null byte in a caller key or value. Give a child only the keys that it needs, never a copy of `os.environ`.
- **Child environment**: With `isolate_env=True`, the default, `build_subprocess_env` gives a child the allowed keys of the environment, without credentials. With `isolate_env=False`, it gives the full environment, credentials included. It puts the `env` of the caller on top. It refuses with `SecurityError` a caller key that `CONST_CODE_LOADING_ENV_PATTERNS` lists. The list holds the loader keys of glibc and macOS, `GCONV_PATH`, and the keys of bash and zsh that run code. It also holds the keys of Python, Node.js, Perl, Ruby and Java that load code, and the git keys of the next bullet. An isolated child gets none of these keys from the environment, unless the caller names the key in `extra_allowed_keys` (`extra_allowed_env` of `run_subprocess`). Some keys that make a child run code still reach the child. `HOME` is one: zsh and Python read start-up files below it, so a caller that sets `HOME` gives a directory that it controls. `XDG_CONFIG_HOME` is another: git reads its configuration below it, and `devops openspec` sets it. The library keys that make a library load a module are others, for example `OPENSSL_CONF` (#2503). `build_subprocess_env` also refuses a null byte in a caller key or value. Give a child only the keys that it needs, never a copy of `os.environ`.
- **Git child environment**: The guard refuses each `GIT_` key of a caller, but `GIT_TERMINAL_PROMPT` and the author and committer keys (#2483). Git reads configuration, programs and hooks from the other keys. A key that git adds later stays refused until a person reviews it. The guard also refuses `EDITOR`, `VISUAL`, `PAGER` and `LESSOPEN`, which a git child uses. A caller that must give git an option puts it in the arguments, for example `git -c core.sshCommand=...`, and never in the environment. The `git config --global` calls name `GIT_CONFIG_GLOBAL` in `extra_allowed_env`, so that they write the file that the person set.
- **Subprocess spans**: A subprocess span holds the program and the number of its arguments. It holds the arguments only when `telemetry.capture_command_args` turns them on ([docs/TELEMETRY.md](docs/TELEMETRY.md)).
- **LLM inference spans**: AI inference spans omit prompt and response previews by default, and Logfire scrubs private host patterns. They record previews only when `telemetry.capture_llm_content` turns them on ([docs/TELEMETRY.md](docs/TELEMETRY.md)).
- **Process groups**: Start a child with `start_new_session=True`, and stop it by its process group (`os.killpg`), as `_terminate_process_group` in `src/devops_cli/sandbox/host.py` does. Do not signal a pid below 2, the own process group (`os.getpgrp()`) or a process group below 2.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-10-29
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Design

## Decisions

- **The sources are the git manuals, the git source and sudo.** The sudo table removes `GIT_SSH_COMMAND` and the `GIT_CONFIG_*` family before sudo runs a program for another user. The table is `initial_badenv_table` of `plugins/sudoers/env.c`. The pages `git(1)`, `git-config(1)`, `git-init(1)`, `git-var(1)` and `less(1)` name more keys. The source of git names the keys that only its tests and scripts use. A probe with git 2.55.0 and a temporary `HOME` confirms each refused key (proposal, Feasibility).
- **A `GIT_` key is refused unless the guard accepts it.** The first list had 21 names, and a review found five more keys that run a program. A list of names stays incomplete when git adds a key. The constant now holds the pattern `GIT_*`, and `CONST_GIT_ACCEPTED_ENV` names the exceptions. The refine of #2483 rejected this rule, because it blocks a safe key until a review. That review is the wanted effect, and a new key costs one line.
- **Five git keys are accepted.** They are the keys that callers set and that run no program: `GIT_TERMINAL_PROMPT` and the author and committer keys. `roadmap/refine.py`, `roadmap/refine_investigation.py`, `ai/review/samples.py` and `CONST_GIT_NONINTERACTIVE_ENV` set `GIT_TERMINAL_PROMPT`. A tool request sets the author and the committer in `tests/test_tool_executor_contract.py`. `GIT_SSH_VARIANT` and `GIT_CONFIG_NOSYSTEM` run no program, but no caller sets them. Thus the guard refuses them until a caller needs one.
- **The trace keys are refused.** `GIT_TRACE`, `GIT_TRACE2` and `GIT_TRACE_CURL` append to a file that the caller names. The trace line holds the arguments of the git command. A newline in an argument then puts a line of the caller into an existing file. A caller has no reason to set these keys.
- **The other refused keys are in the constant by name.** `EDITOR`, `VISUAL` and `PAGER` are the keys that git uses when `GIT_EDITOR`, `core.editor`, `GIT_PAGER` and `core.pager` are not set (`git-var(1)`). `LESSOPEN` and `LESSCLOSE` make `less`, the default pager, run a filter program (`less(1)`). `MERGE_TOOLS_DIR` names the directory from which `git-mergetool--lib` reads a shell file. Each key ran a program in a probe. No file of `src/` sets or reads them for a child, and no test sets one.
- **No refused key reaches an isolated child from the environment.** `DEFAULT_ALLOWED_ENV_VARS` removes `GIT_CONFIG_GLOBAL`, `GIT_CONFIG_SYSTEM`, `GIT_EXEC_PATH`, `EDITOR` and `PAGER`. A test gives each allowed key as an override, so a key that a refused pattern matches fails it. #2429 removed `PYTHONPATH` and `PYTHONHOME` on the same ground. The default `env_reset` of sudo keeps neither `EDITOR` nor `PAGER`. A person who wants an ambient value uses `isolate_env=False` or the `extra_allowed_env` of a caller.
- **`XDG_CONFIG_HOME` stays accepted.** `src/devops_cli/openspec/tool.py` sets it as a caller override, to a scratch directory that holds the configuration of `openspec`. The ambient lists for `gh` and for `go` hold it too (`CONST_GH_LOGIN_ENV_VARS`, `CONST_GO_HOST_ENV_VARIABLES`). A probe shows that git reads `$XDG_CONFIG_HOME/git/config`, so the key has the effect of the refused `GIT_CONFIG_GLOBAL`. It is the case of `HOME` below: a caller must be able to give a child its own configuration directory.
- **The own override moves to the argument list of git.** `render_at_revision` passes `CONST_GIT_NONINTERACTIVE_ENV` as a caller override of `build_subprocess_env`. After the change the fetch is `git -C <dir> -c core.sshCommand=ssh -o BatchMode=yes fetch ...`, and the environment holds only `GIT_TERMINAL_PROMPT=0`. The option `-c` beats the configuration files. The guard keeps no exception and no flag. With isolation on, an ambient `GIT_SSH_COMMAND` never reaches the child, so it cannot take precedence.
- **This replaces criterion 3 of the issue.** The criterion asks for a child whose environment holds `GIT_SSH_COMMAND`, set by a post-guard step. It names a mechanism, not the result. The result is that `ssh` starts with `-o BatchMode=yes`, and a probe shows that `-c core.sshCommand` gives the same arguments. A post-guard step needs a flag or a program-wide pin, as the rejected alternatives show. The test of this change asserts the result with a stand-in `ssh` program.
- **The `git config --global` calls name `GIT_CONFIG_GLOBAL`.** With the key out of the allowlist, `git config --global` writes `$HOME/.gitconfig`. Git of the person reads `GIT_CONFIG_GLOBAL` alone when it is set. The three calls give `extra_allowed_env=CONST_GIT_GLOBAL_CONFIG_ENV`: the signing keys of `ssh register` and `ssh rotate`, and the two defaults of `devcontainer post-start`. The value is the one that the person set, as the design of #2429 says for `extra_allowed_keys`. The `global_git_config` fixture of `tests/test_ssh.py` keeps working with no change.
- **The constant keeps the length rule of #2433.** The comment above `CONST_CODE_LOADING_ENV_PATTERNS` stays at 25 words, and the change does not edit it. Each group of the git block has one short comment with its pages, for example `# less(1)`. The block sits between the zsh keys and the Python keys, and the test list follows the same order. A later change that appends a group at the end of the tuple (#2503) then merges with no conflict.
- **The spec change only adds requirements.** The requirement "A caller override that loads code into the child is refused" names the loader and interpreter keys. A MODIFIED copy would conflict with #2503, which changes the same requirement. The new requirements add the git refusal, the accepted keys, the fetch, the global file and the allowlist rule. A delta cannot change a purpose, so the change edits the purpose line of `openspec/specs/subprocess-environment/spec.md` directly, as #2429 did.
- **The tests are in the file of the behaviour.** `tests/test_subprocess_env_boundary.py` takes the refused keys in `REFUSED_OVERRIDE_KEYS`, so the tests of the override and of the ambient environment cover them. The fetch tests are in `tests/test_k8s_argocd_overrides.py`, and they start git with the public `run_subprocess`. The `git config --global` tests are in `tests/test_devcontainer.py` and the existing `tests/test_ssh.py`.

## Rejected alternatives

- **Pin `GIT_SSH_COMMAND` after the guard, as `_pin_github_token` pins `GH_TOKEN`.** The pin acts on the program name (`_github_client_name`), so it reaches every git child that `run_subprocess` starts, for example `git status` and `git config`. It replaces the `core.sshCommand` of the person in each of them. A pin for one call needs a flag on `run_subprocess`, which is the next alternative.
- **Add a flag or a trusted-environment parameter to `build_subprocess_env`.** It weakens the guard for every caller, and a reviewer must audit each use of the flag.
- **Accept `GIT_SSH_COMMAND` when its value is the exact constant of devops-cli.** It keeps one path, but the guard then holds an exception that the next caller extends. The argument list needs none.
- **Check the value of `GIT_SSH_COMMAND`.** A new ssh option or another program name passes such a check, and the value is a shell command line.
- **Refuse the git keys by name only.** The first version did so. A review found five keys that it missed, and git adds keys with each release.
- **Keep `EDITOR` and `PAGER` in the allowlist and refuse them only as caller overrides.** A refused key then reaches an isolated child from the environment, which the spec requirement and its test forbid. No code needs the ambient keys.
- **Find the global configuration file in Python for the `git config --global` calls.** It copies the lookup that git does (`GIT_CONFIG_GLOBAL`, then `$XDG_CONFIG_HOME/git/config`, then `~/.gitconfig`). `extra_allowed_env` lets git do the lookup.

## Keys considered and accepted

- `HOME` makes git read `$HOME/.gitconfig`, which can set `core.fsmonitor`. It has the effect of the refused `GIT_CONFIG_GLOBAL`. The guard accepts it, because a caller must be able to give a child its own home directory. `src/devops_cli/telemetry/semconv.py` sets it for `weaver`.
- `XDG_CONFIG_HOME` is accepted for the reason in Decisions.
- The five keys of `CONST_GIT_ACCEPTED_ENV` run no program and write no file.

## Non-goals

- The library keys that make a library of the child load a module, for example `OPENSSL_CONF`: #2503.
- The keys of `ssh` that name a program, `SSH_ASKPASS` and `SSH_ASKPASS_REQUIRE`: #2633.
- The keys of `gh` and `kubectl` that name a program, for example `GH_EDITOR` and `KUBE_EDITOR`: #2633 names them as candidates. No probe of them ran.
Loading
Loading