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
2 changes: 1 addition & 1 deletion ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ All external binaries run through `run_subprocess` / `run_subprocess_async` (`de
- **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`.
- **Gh and kubectl child environment**: The guard refuses `GH_BROWSER`, `BROWSER`, `GH_EDITOR`, `GH_PAGER`, `GH_PATH`, `KUBE_EDITOR` and `KUBECTL_EXTERNAL_DIFF` from a caller (#2672). `gh` and `kubectl` start the program that each key names, and `GH_PATH` becomes the git credential helper that git starts. `GH_CONFIG_DIR` and `KUBECONFIG` still reach the child: callers set both on purpose, and a caller names a file that it controls. A configuration directory can hold a `gh` alias that starts a program, and a kubeconfig can name an `exec` credential plug-in. A caller that takes either path from an untrusted source must check it first. A key that `gh` or `kubectl` adds later is not refused until a person reviews it.
- **Uv and npm child environment**: The guard refuses `UV_PYTHON`, `UV_PYTHON_INSTALL_DIR`, `UV_PROJECT_ENVIRONMENT`, `VIRTUAL_ENV`, `npm_config_script_shell`, `npm_config_node_options`, `npm_config_git`, `npm_config_editor`, `npm_config_init_module`, `npm_config_shell`, `npm_config_python` and `PYTHON` from a caller (#2673). `uv` starts the interpreter or the environment that the first four keys name. `npm` starts the shell, the git program or the editor that its keys name, passes the options of `npm_config_node_options` to `node`, and loads the module of `npm_config_init_module`. node-gyp, which `npm install` runs for a native package, starts the interpreter of `npm_config_python` and of `PYTHON`. npm reads the spelling with a hyphen, as `npm_config_script-shell`, as the same key, so the guard refuses it too. The guard accepts the other `npm_config_` keys, because `devops install-tools` sets some of them. `npm_config_userconfig`, `npm_config_globalconfig` and `UV_CONFIG_FILE` name a file that can start a program, and a caller names a file that it controls. A caller that takes such a path from an untrusted source must check it first. An isolated child gets no `VIRTUAL_ENV`, no `UV_PROJECT_ENVIRONMENT` and no `npm_config_` key from the environment. It still gets the other `UV_` keys of the person, `UV_PYTHON` and `UV_PYTHON_INSTALL_DIR` included, although the guard refuses both from a caller: the gate of a CI runner needs them to keep the environment that `uv sync` built (#1735). The environment of the person is as trusted as `PATH` for these two keys. A key that `uv` or `npm` adds later is not refused until a person reviews it.
- **File-write child environment**: The guard refuses `SSLKEYLOGFILE`, `QLOGDIR`, `NODE_V8_COVERAGE`, `NODE_REDIRECT_WARNINGS` and each `LD_` key from a caller (#2674). These keys load no code. They make the child write a file that the caller names. `SSLKEYLOGFILE` makes `curl`, `git` over HTTPS and the `ssl` module of Python write the TLS secrets of each connection, and a person who reads the file can decrypt the recorded traffic. `QLOGDIR` makes `curl` write a QUIC log. `NODE_V8_COVERAGE` and `NODE_REDIRECT_WARNINGS` make Node.js write coverage data and its warnings. `LD_DEBUG_OUTPUT` and `LD_PROFILE_OUTPUT` make the glibc loader write debug text and a profile. The pattern `LD_*` also refuses the other loader keys. `PYTHONDUMPREFSFILE` and `GPGRT_TRACE_FILE` stay accepted: no probe made a child write a file with them. A key that a tool adds later is not refused until a person reviews it.
- **File-write child environment**: The guard refuses `SSLKEYLOGFILE`, `QLOGDIR`, `NODE_V8_COVERAGE`, `NODE_REDIRECT_WARNINGS` and each `LD_` key from a caller (#2674). These keys load no code. They make the child write a file that the caller names. `SSLKEYLOGFILE` makes `curl`, `git` over HTTPS and the `ssl` module of Python write the TLS secrets of each connection, and a person who reads the file can decrypt the recorded traffic. `QLOGDIR` makes `curl` write a QUIC log. `NODE_V8_COVERAGE` and `NODE_REDIRECT_WARNINGS` make Node.js write coverage data and its warnings. `LD_DEBUG_OUTPUT` and `LD_PROFILE_OUTPUT` make the glibc loader write debug text and a profile. The pattern `LD_*` also refuses the other loader keys. The guard also refuses `PYTEST_ADDOPTS` and `npm_config_logs_dir` (#2747). With `--junitxml=<path>` in `PYTEST_ADDOPTS`, pytest wrote a JUnit file at the path. With `npm_config_logs_dir` or `npm_config_logs-dir`, npm wrote its debug log into the directory. `npm_config_cache` stays accepted, because `devops install-tools` sets it. npm writes cache files and, when `npm_config_logs_dir` is not set, its debug log below that directory. A caller that takes the cache path from an untrusted source must check the path first. `PYTHONDUMPREFSFILE` and `GPGRT_TRACE_FILE` stay accepted: no probe made a child write a file with them. A key that a tool adds later is not refused until a person reviews it.
- **Library child environment**: The guard refuses each `OPENSSL` key and each `KRB5` key of a caller (#2503). The OpenSSL keys `OPENSSL_CONF`, `OPENSSL_CONF_INCLUDE`, `OPENSSL_MODULES` and `OPENSSL_ENGINES` choose the provider or engine that each program with OpenSSL loads. `KRB5_CONFIG` can name plug-in modules in the same way. The guard also refuses `GSS_MECH_CONFIG`, `SASL_PATH`, `PYTHONEXECUTABLE` and `__PYVENV_LAUNCHER__`. A key that a library adds later stays refused until a person reviews it. A key that loads no module, for example `SSL_CERT_FILE`, stays accepted.
- **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)).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

Reads: `src/devops_cli/config/constants.py` (lines 1585 to 1720), `tests/core/test_subprocess_env_file_write.py`. Changes: `src/devops_cli/config/constants.py`, `tests/core/test_subprocess_env_file_write.py`.

- [ ] 1.1 In `tests/core/test_subprocess_env_file_write.py`, add `PYTEST_ADDOPTS`, `npm_config_logs_dir` and `npm_config_logs-dir` to `REFUSED_FILE_WRITE_KEYS` with the probe in the comment above it (pytest 9.1.1 wrote the JUnit file, npm 11.19.1 wrote its debug log). Add `EXAMPLE_PYTEST_ADDOPTS` and `npm_config_logs_dirs` to the override of `test_a_key_that_only_contains_a_file_write_name_reaches_the_child`. Verify that `uv run devops ci test tests/core/test_subprocess_env_file_write.py` fails on the base: the refusal cases of the three new keys fail with `DID NOT RAISE`. The test of the ambient environment already passes on the base, because neither key is in the ambient allowlist, and it stays as a pin.
- [ ] 1.2 In `src/devops_cli/config/constants.py`, add `"PYTEST_ADDOPTS"` and `"NPM_CONFIG_LOGS[_-]DIR"` to `CONST_CODE_LOADING_ENV_PATTERNS`, in the block of the keys that make a child write a file (#2674). Extend the comment of the block with the two probes. In the comment of #2673, add `npm_config_cache` to the keys that stay accepted, with the reason that `devops install-tools` sets it. Verify that `uv run devops ci test tests/core/test_subprocess_env_file_write.py tests/core/test_subprocess_env_uv_npm.py tests/core/test_subprocess_env_boundary.py tests/commands/test_install_tools.py` passes. The last three files pin the keys that must stay accepted and the keys that stay refused.
- [x] 1.1 In `tests/core/test_subprocess_env_file_write.py`, add `PYTEST_ADDOPTS`, `npm_config_logs_dir` and `npm_config_logs-dir` to `REFUSED_FILE_WRITE_KEYS` with the probe in the comment above it (pytest 9.1.1 wrote the JUnit file, npm 11.19.1 wrote its debug log). Add `EXAMPLE_PYTEST_ADDOPTS` and `npm_config_logs_dirs` to the override of `test_a_key_that_only_contains_a_file_write_name_reaches_the_child`. Verify that `uv run devops ci test tests/core/test_subprocess_env_file_write.py` fails on the base: the refusal cases of the three new keys fail with `DID NOT RAISE`. The test of the ambient environment already passes on the base, because neither key is in the ambient allowlist, and it stays as a pin.
- [x] 1.2 In `src/devops_cli/config/constants.py`, add `"PYTEST_ADDOPTS"` and `"NPM_CONFIG_LOGS[_-]DIR"` to `CONST_CODE_LOADING_ENV_PATTERNS`, in the block of the keys that make a child write a file (#2674). Extend the comment of the block with the two probes. In the comment of #2673, add `npm_config_cache` to the keys that stay accepted, with the reason that `devops install-tools` sets it. Verify that `uv run devops ci test tests/core/test_subprocess_env_file_write.py tests/core/test_subprocess_env_uv_npm.py tests/core/test_subprocess_env_boundary.py tests/commands/test_install_tools.py` passes. The last three files pin the keys that must stay accepted and the keys that stay refused.

## 2. Document the refused keys

Reads: `ARCHITECTURE.md` (the bullet "File-write child environment"). Changes: `ARCHITECTURE.md`.

- [ ] 2.1 In `ARCHITECTURE.md`, add `PYTEST_ADDOPTS` and `npm_config_logs_dir` to the bullet "File-write child environment", with what the probes showed. Say that `npm_config_cache` stays accepted because `devops install-tools` sets it, that npm writes its log below the cache directory, and that a caller that takes the path from an untrusted source must check it first. Verify that `git grep -n 'PYTEST_ADDOPTS' -- ARCHITECTURE.md` prints the bullet (it prints nothing on the base).
- [ ] 2.2 Verify that `uv run devops ci docs` passes. The change alters no command, option or message, so `uv run devops docs generate --sync-readme` has nothing to sync.
- [x] 2.1 In `ARCHITECTURE.md`, add `PYTEST_ADDOPTS` and `npm_config_logs_dir` to the bullet "File-write child environment", with what the probes showed. Say that `npm_config_cache` stays accepted because `devops install-tools` sets it, that npm writes its log below the cache directory, and that a caller that takes the path from an untrusted source must check it first. Verify that `git grep -n 'PYTEST_ADDOPTS' -- ARCHITECTURE.md` prints the bullet (it prints nothing on the base).
- [x] 2.2 Verify that `uv run devops ci docs` passes. The change alters no command, option or message, so `uv run devops docs generate --sync-readme` has nothing to sync.
12 changes: 8 additions & 4 deletions openspec/specs/subprocess-environment/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ With isolation on, `build_subprocess_env` SHALL keep each `UV_` key of the envir
- **THEN** the child environment holds each of these keys with its value

### Requirement: A caller override of a key that makes a child write a file that the caller names is refused
`build_subprocess_env` SHALL raise `SecurityError` with the message "Prohibited dangerous environment variable override: '<key>'" and the error code `SECURITY_ERROR` for a caller override whose upper-case key is `SSLKEYLOGFILE`, `QLOGDIR`, `NODE_V8_COVERAGE`, `NODE_REDIRECT_WARNINGS` or starts with `LD_`. It SHALL do this with environment isolation on and off.
`build_subprocess_env` SHALL raise `SecurityError` with the message "Prohibited dangerous environment variable override: '<key>'" and the error code `SECURITY_ERROR` for a caller override whose upper-case key is `SSLKEYLOGFILE`, `QLOGDIR`, `NODE_V8_COVERAGE`, `NODE_REDIRECT_WARNINGS`, `PYTEST_ADDOPTS`, `NPM_CONFIG_LOGS_DIR`, `NPM_CONFIG_LOGS-DIR` or starts with `LD_`. It SHALL do this with environment isolation on and off.

#### Scenario: The TLS secrets and the QUIC log
- **WHEN** a caller builds a child environment with the override `SSLKEYLOGFILE` or `QLOGDIR`, in upper or lower case
Expand All @@ -324,6 +324,10 @@ With isolation on, `build_subprocess_env` SHALL keep each `UV_` key of the envir
- **WHEN** a caller builds a child environment with the override `NODE_V8_COVERAGE` or `NODE_REDIRECT_WARNINGS`, in upper or lower case
- **THEN** `build_subprocess_env` raises `SecurityError` that names the key, with the error code `SECURITY_ERROR`

#### Scenario: The options of pytest and the log directory of npm
- **WHEN** a caller builds a child environment with the override `PYTEST_ADDOPTS`, `npm_config_logs_dir` or `npm_config_logs-dir`, in upper or lower case
- **THEN** `build_subprocess_env` raises `SecurityError` that names the key, with the error code `SECURITY_ERROR`

#### Scenario: The debug and profile keys of the glibc loader
- **WHEN** a caller builds a child environment with the override `LD_DEBUG`, `LD_DEBUG_OUTPUT`, `LD_PROFILE`, `LD_PROFILE_OUTPUT` or another key that starts with `LD_`, in upper or lower case
- **THEN** `build_subprocess_env` raises `SecurityError` that names the key, with the error code `SECURITY_ERROR`
Expand All @@ -333,7 +337,7 @@ With isolation on, `build_subprocess_env` SHALL keep each `UV_` key of the envir
- **THEN** `run_subprocess` raises `SecurityError` and the program does not start

### Requirement: An isolated child gets no file-write key from the environment
With isolation on, `build_subprocess_env` SHALL keep `SSLKEYLOGFILE`, `QLOGDIR`, `NODE_V8_COVERAGE`, `NODE_REDIRECT_WARNINGS` and each key that starts with `LD_` out of the child environment, in upper and lower case. With isolation off, the child gets the environment as it is.
With isolation on, `build_subprocess_env` SHALL keep `SSLKEYLOGFILE`, `QLOGDIR`, `NODE_V8_COVERAGE`, `NODE_REDIRECT_WARNINGS`, `PYTEST_ADDOPTS`, `npm_config_logs_dir`, `npm_config_logs-dir` and each key that starts with `LD_` out of the child environment, in upper and lower case. With isolation off, the child gets the environment as it is.

#### Scenario: The keys in the environment of the person
- **WHEN** the environment holds one of these keys, and a caller builds a child environment with isolation on
Expand All @@ -344,10 +348,10 @@ With isolation on, `build_subprocess_env` SHALL keep `SSLKEYLOGFILE`, `QLOGDIR`,
- **THEN** the child environment holds both keys with their values

### Requirement: A key that only contains a refused name reaches the child
`build_subprocess_env` SHALL put a key of the caller override in the child environment with its value when the key only contains a refused file-write name, or contains `LD_` after its first characters, with isolation on and off. `SSL_CERT_FILE` and `NODE_EXTRA_CA_CERTS` are examples of keys that write no file.
`build_subprocess_env` SHALL put a key of the caller override in the child environment with its value when the key only contains a refused file-write name, or contains `LD_` after its first characters, with isolation on and off. `SSL_CERT_FILE` and `NODE_EXTRA_CA_CERTS` are examples of keys that write no file. `npm_config_cache` also makes npm write files and stays accepted, because `devops install-tools` sets it.

#### Scenario: Keys with a similar name
- **WHEN** a caller builds a child environment with the overrides `SSL_CERT_FILE`, `NODE_EXTRA_CA_CERTS`, `EXAMPLE_SSLKEYLOGFILE`, `QLOGDIR_EXAMPLE`, `BUILD_ID` and `OLD_LD_EXAMPLE`
- **WHEN** a caller builds a child environment with the overrides `SSL_CERT_FILE`, `NODE_EXTRA_CA_CERTS`, `EXAMPLE_SSLKEYLOGFILE`, `QLOGDIR_EXAMPLE`, `BUILD_ID`, `OLD_LD_EXAMPLE`, `EXAMPLE_PYTEST_ADDOPTS` and `npm_config_logs_dirs`
- **THEN** the child environment holds each of these keys with its value

### Requirement: An isolated child gets the worker bound of the test runner
Expand Down
7 changes: 6 additions & 1 deletion src/devops_cli/config/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -1641,7 +1641,8 @@ class WebhookExposure(StrEnum):
# binding.gyp, starts the interpreter of npm_config_python and of PYTHON.
# npm reads `npm_config_script-shell` as `npm_config_script_shell`, so `[_-]` matches both.
# npm_config_userconfig, npm_config_globalconfig and UV_CONFIG_FILE stay accepted: callers set
# them, and a caller names a file that it controls.
# them, and a caller names a file that it controls. npm_config_cache stays accepted for the
# same reason (#2747): `devops install-tools` sets it, and npm writes its log below it.
"UV_PYTHON",
"UV_PYTHON_INSTALL_DIR",
"UV_PROJECT_ENVIRONMENT",
Expand All @@ -1659,10 +1660,14 @@ class WebhookExposure(StrEnum):
# connection to SSLKEYLOGFILE, and curl writes a QUIC log to the directory of QLOGDIR.
# node(1): Node.js writes coverage data to the directory of NODE_V8_COVERAGE and its warnings
# to the file of NODE_REDIRECT_WARNINGS. The LD_ keys of the loader are the pattern above.
# pytest writes a JUnit file at the path of `--junitxml=<path>` in PYTEST_ADDOPTS, and npm
# writes its debug log into the directory of npm_config_logs_dir (#2747).
"SSLKEYLOGFILE",
"QLOGDIR",
"NODE_V8_COVERAGE",
"NODE_REDIRECT_WARNINGS",
"PYTEST_ADDOPTS",
"NPM_CONFIG_LOGS[_-]DIR",
# python(1)
"PYTHONPATH",
"PYTHONHOME",
Expand Down
8 changes: 8 additions & 0 deletions tests/core/test_subprocess_env_file_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
# NODE_REDIRECT_WARNINGS: Node.js wrote its warning to the file. LD_DEBUG_OUTPUT and
# LD_PROFILE_OUTPUT: the glibc 2.43 loader wrote its debug text and its profile, but only with the
# trigger keys LD_DEBUG and LD_PROFILE, so the guard refuses the whole LD_ family (ld.so(8)).
# PYTEST_ADDOPTS (#2747): pytest 9.1.1 with `--junitxml=<path>` wrote a JUnit file at the path.
# npm_config_logs_dir and npm_config_logs-dir (#2747): npm 11.19.1 and 10.9.9 wrote a debug log
# into the directory for `npm ls`.
REFUSED_FILE_WRITE_KEYS: tuple[str, ...] = (
"SSLKEYLOGFILE",
"QLOGDIR",
Expand All @@ -32,6 +35,9 @@
"LD_PROFILE_OUTPUT",
"LD_BIND_NOW",
"LD_EXAMPLE",
"PYTEST_ADDOPTS",
"npm_config_logs_dir",
"npm_config_logs-dir",
)

ALL_CASES: tuple[str, ...] = (
Expand Down Expand Up @@ -85,6 +91,8 @@ def test_a_key_that_only_contains_a_file_write_name_reaches_the_child(isolate_en
"NODE_V8_COVERAGE_EXAMPLE": "example",
"BUILD_ID": "example",
"OLD_LD_EXAMPLE": "example",
"EXAMPLE_PYTEST_ADDOPTS": "example",
"npm_config_logs_dirs": "example",
}

env = build_subprocess_env(env=override, isolate_env=isolate_env)
Expand Down