Skip to content

fix(cloud): probe with a minimal subprocess env#51

Merged
sourcehawk merged 1 commit into
feature/cloud-context-mcpfrom
feature/cloud-context-mcp--probe-env
May 30, 2026
Merged

fix(cloud): probe with a minimal subprocess env#51
sourcehawk merged 1 commit into
feature/cloud-context-mcpfrom
feature/cloud-context-mcp--probe-env

Conversation

@sourcehawk
Copy link
Copy Markdown
Owner

Description

Towards #44

The cloud identity probe built its RunFunc with a nil cmd.Env, which in Go makes the gcloud/aws whoami subprocess inherit the entire launcher environment — leaking the launcher's ambient secrets into the probe used by session_status, preflight, and the connections panel. This contradicted the spec's "explicit minimal cmd.Env" requirement (Security model → "Pinned binary and minimal env") and diverged from Server.run, which already filtered the subprocess env. This PR closes that gap.

Changes

  • Extract a package-level minimalEnv(passthrough []string) helper: os.Environ() filtered to the base passthrough (PATH, HOME) plus the provider-declared names, everything else dropped. Both the run_cli harness and the probe now build their subprocess env through this one home.
  • Probe forwards minimalEnv(p.EnvPassthrough()) to execCLI instead of nil, so the whoami still receives the credential/impersonation env it needs and nothing more.
  • Server.subprocessEnv() delegates to minimalEnv(s.provider.EnvPassthrough()) rather than re-implementing the filter inline.

Testing

New failing-first TestProbeUsesMinimalSubprocessEnv drives the probe through a real subprocess (/usr/bin/env, which prints the env it was handed) via a fake provider, then asserts a t.Setenv parent canary never crosses the process boundary while a declared-passthrough var survives. Confirmed RED before the fix, GREEN after. The existing TestSubprocessEnvDropsParentSecretsKeepsPassthrough still passes against the refactored helper. make test-go is race-clean and green; make lint reports 0 issues. frontend/ untouched.

🤖 Generated with Claude Code

… the parent

Probe built its RunFunc with a nil cmd.Env, which makes the gcloud/aws whoami
subprocess inherit the entire launcher environment — leaking ambient secrets
into the identity probe used by session_status, preflight, and connections.
This contradicted the spec's "explicit minimal cmd.Env" requirement and
diverged from Server.run, which already filters the env.

Extract a package-level minimalEnv helper (os.Environ filtered to the base
passthrough plus the provider-declared names) so both the run_cli harness and
the probe build their subprocess env through one home. Server.subprocessEnv now
delegates to it, and Probe forwards minimalEnv(p.EnvPassthrough()) instead of
nil — the whoami still gets the credential/impersonation env it needs, nothing
more.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@sourcehawk sourcehawk merged commit 16aca72 into feature/cloud-context-mcp May 30, 2026
4 checks passed
@sourcehawk sourcehawk deleted the feature/cloud-context-mcp--probe-env branch May 30, 2026 03:54
sourcehawk added a commit that referenced this pull request May 30, 2026
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant