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,8 +178,9 @@ 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, 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`.
- **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 and ssh keys below. 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.
- **Ssh child environment**: The guard refuses each `SSH_` key of a caller, and `SHELL` (#2633). `ssh`, `ssh-add`, `ssh-keygen` and git start the program of `SSH_ASKPASS`. `SSH_SK_PROVIDER`, `SSH_SK_HELPER` and `SSH_PKCS11_HELPER` load a library or start a helper. `SSH_AUTH_SOCK` names the agent that gets a private key, and `SHELL` names the program that `ssh` runs for a `ProxyCommand`. A key that OpenSSH adds later stays refused until a person reviews it. `DISPLAY`, `HOME` and `XAUTHORITY` still reach the child: they name no program for `ssh`.
- **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,41 @@
# Design

## Decisions

- **The sources are the OpenSSH manuals and source.** The pages `ssh(1)`, `ssh-add(1)`, `ssh-keygen(1)` and `ssh-agent(1)` name five keys. The `getenv` calls of the OpenSSH source name two more: `SSH_SK_HELPER` and `SSH_PKCS11_HELPER`. A probe with OpenSSH 10.6p1 and a temporary `HOME` confirms each key that the guard refuses (proposal, Feasibility).
- **An `SSH_` key is refused.** The constant holds the pattern `SSH_*`. The git change (#2483) found a list of names incomplete, because two helper keys are in no page. The same holds here, and OpenSSH adds keys with each release.
- **The guard keeps no accepted set for `SSH_` keys.** #2483 needed `CONST_GIT_ACCEPTED_ENV` because five callers set a git key. No file of `src/` or `tests/` sets an `SSH_` key as a caller override, so an accepted set would be dead code. A caller that needs one adds the set in the review that the new key needs.
- **`SSH_AUTH_SOCK` is refused.** A caller that names the socket chooses the agent. `ssh-add` gives the private key to that agent, and `ssh` asks it to sign. The `*AUTH*` pattern of `DEFAULT_DENIED_ENV_PATTERNS` already keeps the key out of an isolated child, so no ambient use is lost. With `isolate_env=False` the key of the person reaches the child as before.
- **`SHELL` is refused, and the allowlist drops it.** `ssh` starts the program of `SHELL` to run a `ProxyCommand`, a `LocalCommand` and a `Match exec` test. A `ProxyJump` becomes a `ProxyCommand`, so a jump host in the configuration is enough. A key of the allowlist is never a refused key (the requirement of #2483), so the key leaves the allowlist. #2429 and #2483 removed `PYTHONPATH`, `PYTHONHOME`, `EDITOR` and `PAGER` on the same ground. No file of `src/` or `tests/` reads or sets `SHELL` for a child.
- **An isolated child runs without `SHELL`.** `ssh` then uses `/bin/sh` for a `ProxyCommand`, because the source falls back to `_PATH_BSHELL`. The installer script of `uv` reads `SHELL` only when `/proc/self/exe` is missing. A probe ran `claude install` in a temporary home with no `SHELL`: it exited 0 and installed the launcher. It printed the PATH hint with "your shell config file" and no profile name. A person who wants the ambient value uses `isolate_env=False` or the `extra_allowed_env` of a caller.
- **The constant keeps the length rule of #2433.** The comment above `CONST_CODE_LOADING_ENV_PATTERNS` is not edited. The ssh block has one short comment for each pattern. The block sits between the git keys and the Python keys. 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, and #2503 changes it. The new requirements add the ssh refusal, the keys that stay accepted and the isolated child. A delta cannot change a purpose, so the change edits the purpose line of `openspec/specs/subprocess-environment/spec.md` directly, as #2429 and #2483 did.
- **The tests are in the file of the behavior.** `tests/test_subprocess_env_boundary.py` takes the refused keys in `REFUSED_OVERRIDE_KEYS`. The tests of the override, of the case and of the ambient environment then cover them. The test of the allowlist fails for a key that a refused pattern matches.

## Rejected alternatives

- **Refuse the ten keys by name.** The first idea. It misses `SSH_SK_HELPER` and `SSH_PKCS11_HELPER` if the author reads only the pages, and it misses the next key that OpenSSH adds.
- **Add `CONST_SSH_ACCEPTED_ENV` with `SSH_AUTH_SOCK`.** The issue guessed that the socket is "probably ambient and needed". The probe shows that a caller socket gets the private key of `ssh-add`. The key is not ambient for an isolated child. No caller needs it.
- **Keep `SHELL` in the allowlist and leave it accepted.** A caller could then run any program in a child `ssh` that reads a `ProxyJump`. The only reason to keep it is that nothing was found to need it.
- **Refuse `SHELL` as an override only, and keep it in the allowlist.** A refused key would then reach an isolated child from the environment. The requirement and its test forbid that.
- **Check the value of `SSH_ASKPASS`.** The value is a path, and a new option or another program name passes such a check.

## Keys considered and accepted

- `HOME`: `ssh` reads its configuration, its known hosts and its keys from the home directory of the account, not from `HOME`. A probe with a `ProxyCommand` in `$HOME/.ssh/config` changed nothing. `HOME` stays accepted, for the reason in #2483. A `HOME` override still lets git read `$HOME/.gitconfig`, where `core.sshCommand` names a program: #2483 accepted this case.
- `DISPLAY` and `WAYLAND_DISPLAY`: they let `ssh` use an askpass program, but they name none. With `SSH_ASKPASS` refused, the program is the compile-time default `/usr/bin/ssh-askpass`. Every X11 client trusts the display, and `devops devcontainer` gives them to a child on purpose.
- `XAUTHORITY`: `xauth` reads a cookie file from it. The file holds data, not code.
- `TMPDIR`: `ssh` makes its temporary directories below it. It names a place for files, not a program.
- `PATH`: `ssh` finds `xauth` and the program of a `ProxyCommand` with it. Each child needs `PATH`, so the guard accepts it for every program.
- `TERM`, `LANG` and `LC_*`: `ssh` sends them to the server, and the locale code reads them. They run nothing.
- `LISTEN_PID`, `LISTEN_FDS` and `NOTIFY_SOCKET`: only `ssh-agent` reads them, when systemd starts it. devops-cli never starts an agent, and the keys name no program.
- `KRB5CCNAME`, `AUTHSTATE`, `XDG_RUNTIME_DIR` and `TZ`: only `sshd` reads them. devops-cli never starts `sshd`.
- `${VAR}` in a configuration value: the person writes the name in the configuration. The key is not special.
- `SSHPASS` and any other key that starts with `SSH` and has no underscore after it: the pattern is `SSH_*`. The key of the `sshpass` tool is not an OpenSSH key.
- `COMSPEC`: it is the Windows counterpart of `SHELL`. No probe on Windows was possible, and devops-cli CI runs on Linux and macOS only.

## Non-goals

- The library keys that make a library of the child load a module, for example `OPENSSL_CONF` and `KRB5_CONFIG` (`ssh` links GSSAPI): #2503.
- The keys of `gh` and `kubectl` that name a program or a file with a program, for example `GH_BROWSER`, `GH_CONFIG_DIR` and `KUBECONFIG`: #2672. The probes of that issue ran a program with each of the three keys. Some of these keys name a file that callers set on purpose, so that issue needs its own design.
- The keys that make a child write a file that the caller names, and the `LD_` keys that the guard does not name, such as `LD_DEBUG` and `LD_DEBUG_OUTPUT`: #2674. A probe of `ssh -V` wrote a loader log to the file that `LD_DEBUG_OUTPUT` names.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Proposal

## Why

Issue #2633: the subprocess environment guard accepts the ssh keys that make an ssh child run a program that its caller did not choose.

- `build_subprocess_env` in `src/devops_cli/core/process.py` refuses a caller override that `CONST_CODE_LOADING_ENV_PATTERNS` matches. The patterns hold the loader, gconv, bash, zsh, interpreter and git keys (#2205, #2429, #2483). They hold no `SSH_` key.
- `SSH_ASKPASS` names the program that `ssh`, `ssh-add` and `ssh-keygen` start to ask for a passphrase. `SSH_ASKPASS_REQUIRE=force` makes them start it with a terminal present. Git also starts the program of `SSH_ASKPASS` when it needs a password.
- The probes found more keys of the same kind. `SSH_SK_PROVIDER` makes `ssh-keygen` and `ssh-add` load a library. `SSH_SK_HELPER` and `SSH_PKCS11_HELPER` name a helper program. `SHELL` names the program that `ssh` starts to run a `ProxyCommand`.
- `SSH_AUTH_SOCK` names the agent that gets the private key from `ssh-add`. `SSH_AGENT_PID` names the process that `ssh-agent -k` ends.
- `SHELL` is in `DEFAULT_ALLOWED_ENV_VARS`. A key of the allowlist must not be a refused key, so the guard cannot refuse `SHELL` while the allowlist holds it.

## What Changes

- The guard refuses each `SSH_` key and `SHELL` as a caller override. Each raises the same `SecurityError` as the other refused keys, with isolation on and off.
- No `SSH_` key has an exception. No caller sets one, and the design says why the guard keeps no accepted set for them.
- `DEFAULT_ALLOWED_ENV_VARS` removes `SHELL`. Thus no refused key reaches an isolated child from the environment.
- `ARCHITECTURE.md` and the purpose of the `subprocess-environment` spec name the `SSH_` keys and `SHELL` as refused keys.
- The refusal and the isolated environment are what a consumer sees, so the change adds requirements to the `subprocess-environment` spec.
- The change fits one pull request.

## Capabilities

### New Capabilities

None.

### Modified Capabilities

- `subprocess-environment`: the guard refuses the `SSH_` keys and `SHELL`, and an isolated child gets none of them from the environment. The change adds requirements and rewrites no existing requirement.

## Impact

- Code: `src/devops_cli/config/constants.py` and `src/devops_cli/core/process.py`.
- Tests: `tests/test_subprocess_env_boundary.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 `ca9c1ad7`, step 1 of the issue printed `['SSH_ASKPASS', 'SSH_ASKPASS_REQUIRE']` with no `SecurityError`. Step 3, with OpenSSH 10.6p1, printed `SSH-ASKPASS-RAN`.
- Each probe below ran in a temporary directory. It used `env -i PATH=/usr/bin:/bin HOME=<dir>`, a fake value and a marker. The marker is a program or a library that prints a line. Each marker printed, so the program ran or the library loaded.
- `ssh-keygen -y -f <key> </dev/null` ran the program of `SSH_ASKPASS` with `SSH_ASKPASS_REQUIRE=force`. It ran it with `DISPLAY` set and no `SSH_ASKPASS_REQUIRE`. It did not run it with neither.
- `ssh` ran the program of `SSH_ASKPASS` for the host key question, with `StrictHostKeyChecking=ask`. The server was a throwaway SSH server on the loopback address. `git fetch` over SSH ran it too.
- `git credential fill` ran the program of `SSH_ASKPASS` with git 2.55.0. Thus a git child with no SSH remote also runs it.
- `SSH_SK_HELPER` ran with `ssh-keygen -K` and with `ssh-keygen -t ed25519-sk`.
- `SSH_SK_PROVIDER` made `ssh-keygen -K` and `ssh-add -K` load a library. OpenSSH loads only a library that holds the symbol `sk_api_version`, and the constructor of the test library printed.
- `SSH_PKCS11_HELPER` in the environment of `ssh-agent` ran when `ssh-add -s` added a PKCS#11 library. The log of `ssh-agent -d` shows `starting <program> -vvv`.
- `SSH_AUTH_SOCK` made `ssh-add` give a private key to a second agent. `ssh-add -l` on that agent then listed the key. `SSH_AGENT_PID` made `ssh-agent -k` end a `sleep` process.
- `SHELL` ran the program as the shell of a `ProxyCommand`. It ran for `ssh -o ProxyCommand=...`, for `ssh -o ProxyJump=...` and for a `ProxyCommand` in a file given with `ssh -F`. It ran for a `Match exec` line too. It did not run without one of these.
- `SSH_CONNECTION`, `SSH_ORIGINAL_COMMAND`, `SSH_TTY`, `SSH_TUNNEL`, `SSH_USER_AUTH`, `SSH_CLIENT`, `SSH_ASKPASS_PROMPT` and `SSH_USE_STRONG_RNG` ran nothing with `ssh -G`, `ssh-keygen -y` and `ssh-add -l`.
- `HOME` with a `ProxyCommand` in `$HOME/.ssh/config` changed nothing: `ssh -G` showed no proxy command. `ssh` reads its configuration from the home directory of the account.
- The `getenv` calls of the OpenSSH source on branch `master` name the keys. The files are `readpass.c`, `ssh-sk-client.c`, `ssh-pkcs11-client.c`, `ssh-agent.c`, `ssh-add.c`, `ssh-keygen.c`, `authfd.c`, `sshconnect.c` and `readconf.c`. The `strings` of the installed `ssh`, `ssh-add`, `ssh-agent` and `ssh-keygen` programs show the same `SSH_` names.
- The pages `ssh(1)`, `ssh-add(1)`, `ssh-keygen(1)` and `ssh-agent(1)` list `SSH_ASKPASS`, `SSH_ASKPASS_REQUIRE`, `SSH_AUTH_SOCK`, `SSH_SK_PROVIDER` and `SSH_AGENT_PID`. No page lists `SSH_SK_HELPER` or `SSH_PKCS11_HELPER`. A list of names stays incomplete when OpenSSH adds a key.
- The callers: no file of `src/` or `tests/` gives an `SSH_` key or `SHELL` as a caller override. `src/devops_cli/sandbox/engine.py` reads `SSH_AUTH_SOCK` from `os.environ` to guard a mount. That read is not a caller override.
- The pattern `*AUTH*` of `DEFAULT_DENIED_ENV_PATTERNS` already keeps `SSH_AUTH_SOCK` out of an isolated child. No file of `src/` reads `SHELL` for a child, and `git log -S` gives no reason for it in the allowlist.

## 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 lists no OpenSSH key. No library publishes a list for import, so the constant names the sources, as #2205, #2429 and #2483 decided. The match keeps `fnmatch.fnmatchcase` of the standard library. The change builds no new code path: it adds two patterns and deletes one key from the ambient allowlist.
Loading
Loading