Repository navigation
feat(security): isolate subprocess environment and enforce credential boundary - #46
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
There are a few concrete cross-platform correctness and test determinism issues (case-sensitive env key filtering; tests assuming PATH/HOME exist) that should be fixed before approval.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR hardens subprocess execution by defaulting to a sanitized child-process environment (credential boundary) and adds a dedicated test suite to lock in the behavior, with supporting documentation updates.
Changes:
- Added
build_subprocess_env()plus allow/deny environment policies and wired them intorun_subprocess,run_subprocess_async, andrun_json_subprocess. - Added comprehensive tests validating isolation, opt-out, explicit overrides, async parity, and JSON parity.
- Updated roadmap/log/task docs to reflect completion and tracking for Issue #41.
File summaries
| File | Description |
|---|---|
src/devops_cli/core/process.py |
Implements sanitized subprocess environment construction and applies it across sync/async/JSON subprocess helpers. |
tests/test_subprocess_env_boundary.py |
Adds unit/integration-style tests validating environment isolation behavior and constants. |
src/devops_cli/core/__init__.py |
Re-exports the new environment isolation helpers/constants for public use. |
docs/ROADMAP.md |
Marks the subprocess environment isolation roadmap item as complete. |
docs/LOG.md |
Records the security milestone and verification details in the changelog-style log. |
docs/agent/task.md |
Updates task tracking to reflect Phase 48.1 completion and Phase 48.2 progress. |
Review details
Suppressed comments (3)
tests/test_subprocess_env_boundary.py:109
- This test asserts PATH/HOME are present in the child environment but does not ensure they exist in the parent environment for the test run. Set a baseline PATH/HOME via monkeypatch so the assertion is deterministic across CI/platforms.
def test_run_subprocess_isolates_real_child_process(monkeypatch: pytest.MonkeyPatch) -> None:
"""Verify real child process executed via run_subprocess does not inherit ambient secrets."""
monkeypatch.setenv("GITHUB_TOKEN", "leak_test_github_token")
monkeypatch.setenv("OPENAI_API_KEY", "leak_test_openai_key")
monkeypatch.setenv("MY_CUSTOM_SECRET", "leak_test_custom_secret")
monkeypatch.setenv("ALLOWLISTED_TEST_MARKER", "should_be_stripped_if_not_in_allowlist")
cmd = [sys.executable, "-c", "import os, json; print(json.dumps(dict(os.environ)))"]
proc = run_subprocess(cmd)
tests/test_subprocess_env_boundary.py:142
- This async test asserts PATH is present in the child environment but does not ensure PATH exists in the parent environment for the test run. Set a baseline PATH (and HOME for parity with the sync test) via monkeypatch.
@pytest.mark.anyio
async def test_run_subprocess_async_isolates_child_process(monkeypatch: pytest.MonkeyPatch) -> None:
"""Verify run_subprocess_async also enforces environment isolation."""
monkeypatch.setenv("VAULT_TOKEN", "hvs.async_leak_test")
monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "aws_async_leak_test")
cmd = [sys.executable, "-c", "import os, json; print(json.dumps(dict(os.environ)))"]
proc = await run_subprocess_async(cmd)
assert proc.returncode == 0
tests/test_subprocess_env_boundary.py:158
- This JSON subprocess test asserts PATH is present in the child environment but does not ensure PATH exists in the parent environment for the test run. Set a baseline PATH via monkeypatch so the assertion is deterministic.
def test_run_json_subprocess_inherits_isolation(monkeypatch: pytest.MonkeyPatch) -> None:
"""Verify run_json_subprocess benefits from the same environment isolation."""
monkeypatch.setenv("SLACK_WEBHOOK_URL", "https://hooks.slack.com/services/leak")
cmd = [sys.executable, "-c", "import os, json; print(json.dumps({'env': dict(os.environ)}))"]
result = run_json_subprocess(cmd)
child_env = result["env"]
assert "PATH" in child_env
- Files reviewed: 6/6 changed files
- Comments generated: 3
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
… and ensure test determinism
Copilot Review Remediation Addressed in commit
|
* feat(devcontainer): automate PR devcontainer cleanup on PR merge in GHCR (#44) * feat(devcontainer): automate PR devcontainer cleanup on PR merge in GHCR - Add GitHub Actions workflow .github/workflows/cleanup-devcontainer.yml triggered on pull_request [closed] and workflow_dispatch - Scope GHCR image pruning to pr-<number> or wildcard tags while preserving release tags (latest, v*, main) - Reclaim multi-architecture storage via delete-untagged and delete-ghost-images - Pin dataaxiom/ghcr-cleanup-action to commit SHA for supply chain security - Enhance devops_cli.commands.gh token resolution (Keyring github.token and gh auth token) and use REST API for milestones - Update agent instructions in AGENTS.md, ROUTINE_TASKS.md, docs/agent/README.md to leverage GitHub project integrations and issue tracking - Sync roadmap milestones and track Phase 47.4 deliverables Closes #39 * docs(task): update Phase 47.4 tracking with PR 44 and commit 21711bd * fix(gh): support DEVOPS_CLI_GITHUB_TOKEN and add pagination to milestone api - Address Copilot review comments on PR #44 - Check DEVOPS_CLI_GITHUB_TOKEN in _get_github_client() - Pass --paginate and per_page=100 in _get_repo_milestones() - Add regression tests in tests/test_gh_cmd.py * feat(ci): pin GitHub Actions to immutable commit SHAs (#45) * feat(ci): pin GitHub Actions to immutable commit SHAs * docs(task): update Phase 48.1 tracking with PR 45 * docs(roadmap): update action SHA pinning status to completed * docs(task): record Copilot review resolution on PR 45 * feat(security): isolate subprocess environment and enforce credential boundary (#46) * feat(security): isolate subprocess environment and enforce credential boundary * fix(security): normalize env var key case for cross-platform matching and ensure test determinism * docs(task): update Phase 48.2 tracking with PR #46 and Copilot review resolution * feat(k8s): cluster default-deny NetworkPolicies for monitoring and argocd namespaces (#47) * feat(k8s): cluster default-deny NetworkPolicies for monitoring and argocd namespaces * fix(k8s): address Copilot review on NetworkPolicy ingress comments, API server egress selector, and test assertions * docs(task): record PR #47 and Copilot review remediation in Phase 48.3 tracking * feat(security): qdrant vector database api key secret protection and clusterip default (#48) * feat(security): qdrant vector database api key secret protection and clusterip default * fix(review): address Copilot findings for stdin secret apply, fail-fast lifecycle, and debug logging * docs(agent): update task tracking for PR #48 and Copilot review resolutions * docs(agent): record Phase 48.4 PR #48 squash-merge and issue #43 closure * feat(review): review finding remediation, github project automation, and runtime duration formatting (#49) * refactor(review): address session 164259 findings and harden self-improvement loop * docs(agent): mark Phase 48.5 task completed and PR 49 verified * feat(github): remote project sync, automated milestone closure, and submodule test grouping * feat(devcontainer): enhance mcp lifecycle sync and enforce commit message hygiene * feat(output): format command elapsed duration in human readable units Upgrade format_duration to support microsecond, millisecond, second, minute, hour, and day formatting across CLI command completion, CI summaries, AI reviews, and benchmarks. * refactor(github): omit status from milestone description Ensure milestone descriptions extracted from roadmap use strictly the feature name without appending status strings in parentheses. * feat(valkey): valkey workstation caching, rate limiting, and v0.2.12 release preparation - Implement pure-Python RESP2/RESP3 encoder and stream parser without C dependencies - Add TCP socket client (ValkeyClient) with connection pooling, timeouts, and zero-trust SSRF validation - Implement atomic token bucket rate limiter with embedded Lua script - Implement distributed AI cache provider (ValkeyCacheProvider) for embeddings and review findings - Implement devops valkey CLI command group (ping, info, stats, keys, get, set, flush, backup, cli) - Register 6 FastMCP Valkey tools and dynamic system resource resource://valkey/status - Bump package version to 0.2.12 and synchronize release documentation - Pass all 10 devops ci quality gates with 95% test coverage * docs(agents): codify strict release PR title convention feat(release): v<version> * fix(review): remediate pull request review findings across valkey, output, and github subsystems
Summary
This pull request implements Subprocess Environment Isolation & Credential Boundary (Issue #41) to enforce zero ambient credential leakage to external child processes by default.
Problem Solved
Previously, child processes executed via
run_subprocess,run_subprocess_async, andrun_json_subprocessinherited the entire parent processos.environunless an explicit dictionary was supplied. In workstations, CI/CD runners, and agentic workflows, ambient secrets such asGITHUB_TOKEN,VAULT_TOKEN, cloud credentials (AWS_SECRET_ACCESS_KEY), LLM API keys (OPENAI_API_KEY,ANTHROPIC_API_KEY), and database passwords could inadvertently leak into untrusted child binaries, scripts, or debug tools.Key Changes
build_subprocess_env):src/devops_cli/core/process.pywhen spawning child processes (isolate_env=Trueby default).DEFAULT_DENIED_ENV_PATTERNS:*TOKEN*,*SECRET*,*KEY*,*PASSWORD*,*CREDENTIAL*,*AUTH*,*PRIVATE*).DEFAULT_ALLOWED_ENV_VARS(PATH,HOME,USER,TMPDIR,VIRTUAL_ENV,LANG,LC_*,OTEL_*,W3C_*,DEVOPS_CLI_*,KUBECONFIG,DOCKER_*,GIT_*).envoverrides on top of the sanitized base, ensuring that when a caller intentionally passes a specific token to a tool (e.g.gh), explicit caller intent is honored.isolate_env=Falseand selective extensionextra_allowed_env.run_subprocess,run_subprocess_async, andrun_json_subprocess.build_subprocess_env,DEFAULT_ALLOWED_ENV_VARS,DEFAULT_ALLOWED_ENV_PREFIXES, andDEFAULT_DENIED_ENV_PATTERNSinsrc/devops_cli/core/__init__.py.tests/test_subprocess_env_boundary.pycovering allowlists, denylists, caller overrides, isolation disabling, real child execution viasys.executable, async parity, and JSON parity.uv run devops ci).Closes #41