Skip to content

fix(installer+docker): launch tray with clean env, harden docker probe - #420

Merged
Dumbris merged 1 commit into
mainfrom
fix/installer-clean-env-docker-probe
Apr 26, 2026
Merged

Dumbris merged 1 commit into
mainfrom
fix/installer-clean-env-docker-probe

Conversation

@Dumbris

@Dumbris Dumbris commented Apr 26, 2026

Copy link
Copy Markdown
Member

Summary

  • Postinstall scripts now launch the tray via launchctl asuser <uid> env -i … so the app starts in the user's GUI bootstrap with a clean PATH instead of inheriting the PKInstallSandbox env (PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/libexec, SHELL=/bin/sh, INSTALLER_*).
  • shellwrap.ResolveDockerPath replaces sync.Once with a TTL'd cache (success cached forever, failure 60s) so a transient install-time failure self-heals instead of poisoning the daemon for its lifetime.
  • New well-known-paths probe between the exec.LookPath fast path and the slow login-shell fallback. Probes Docker Desktop's bundle binary first, then /usr/local/bin/docker, ~/.docker/bin/docker, Apple Silicon Homebrew, OrbStack, snap.
  • Revert tooltip-left → tooltip-bottom on the Scan Now button (PR fix(webui): prevent Scan Now tooltip clipping at right edge #407 over-corrected; the button is on the LEFT of the security tab content so tooltip-left ended up under the sidebar).

Why this matters

Users installing v0.26.x via the PKG were ending up with a long-running mcpproxy core that could not find Docker even though Docker Desktop was running. Symptoms:

  • Web UI's "Scan Now" button disabled with the explanation tooltip hidden under the left sidebar.
  • mcpproxy security scan <server> returned all scanners failed in ~1s with per-scanner error Docker image ... is not available locally — even when every image was present in docker images.
  • /api/v1/diagnostics showed docker_status.error: exec: "docker": executable file not found in $PATH.

Root cause was a chain: PKG postinstall → open -a MCPProxy.app propagated installer env → tray app → forked mcpproxy serve with no Docker locations on PATH → first ResolveDockerPath call failed → sync.Once cached the failure for the lifetime of the daemon. Restarting via the tray (normal user session) fixed it but the user shouldn't have to know that.

Apple's recommended pattern (per launchctl(1), packaging guidelines, and prior art in Tailscale / Colima / OrbStack) is to launch under launchctl asuser with EnvironmentVariables.PATH set explicitly so children never inherit the sandbox env. That's what this PR does for the postinstall path; the Go-side TTL cache + well-known-paths probe is defense-in-depth in case any other context (LaunchAgent, manual launchctl, etc.) ends up with a similarly minimal PATH.

Files

  • frontend/src/views/ServerDetail.vue — tooltip-left → tooltip-bottom
  • internal/shellwrap/shellwrap.go — TTL cache + well-known-paths probe
  • internal/shellwrap/shellwrap_test.go — new tests for retry + well-known fallback
  • packaging/macos/postinstall.sh — clean-env launch via launchctl asuser
  • scripts/postinstall.sh — clean-env launch via launchctl asuser

Test plan

  • go test ./internal/shellwrap/... -count=1 -race — all tests pass including new TestResolveDockerPath_NegativeTTLRetry and TestResolveDockerPath_WellKnownPathFallback
  • go build ./cmd/mcpproxy (personal) and go build -tags server ./cmd/mcpproxy (server) — both clean
  • bash -n syntax check on both postinstall scripts
  • Frontend builds clean
  • Manual verification on macOS post-install: re-install PKG, confirm mcpproxy security scan works immediately and Web UI's "Scan Now" is enabled
  • CI green

🤖 Generated with Claude Code

The PKG postinstall script ran `open -a /Applications/MCPProxy.app` which
propagated the entire PKInstallSandbox environment (PATH=/bin:/sbin:/usr/bin:
/usr/sbin:/usr/libexec, SHELL=/bin/sh, INSTALLER_*) into the launched tray
and every child process it spawned, including the long-running mcpproxy core.
With no Docker locations on PATH, the core's docker probe failed; sync.Once
then permanently cached that failure for the lifetime of the daemon — so
the Web UI's "Scan Now" button stayed disabled, the security scan CLI
returned "all scanners failed" with "Docker image is not available locally"
even when every image was present, and `docker_status.error` showed `exec:
"docker": executable file not found in $PATH`.

Apple's recommended fix (per launchctl docs and packaging guidelines) is to
launch the app in the user's GUI bootstrap context with a clean env. Both
postinstall scripts now use:

    /bin/launchctl asuser <uid> /usr/bin/env -i \
        HOME=... USER=... LOGNAME=... \
        PATH=/usr/local/bin:/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin \
        /usr/bin/open -a "$APP" --env MCPPROXY_LAUNCHED_BY=installer

This mirrors what users get when they double-click the app from Finder.

Defense-in-depth in shellwrap.ResolveDockerPath:

  - Replace sync.Once with a TTL'd cache. Successful resolutions still
    cache forever; failures cache only 60s so a transient install-time
    failure self-heals instead of poisoning the daemon.
  - Add well-known-paths probe between the exec.LookPath fast path and
    the login-shell slow path. Probes the canonical Docker Desktop bundle
    binary first (always present when Docker Desktop is installed),
    /usr/local/bin/docker, ~/.docker/bin/docker (Docker's documented
    fallback when /usr/local/bin is not writable), Apple Silicon Homebrew,
    OrbStack, snap. Cheap (just os.Stat) and bypasses the fragile
    login-shell dance entirely for the common case.

Web UI: revert the tooltip-left fix from #407 to tooltip-bottom. The Scan
Now button sits on the LEFT of the security tab content (`flex sm:justify-
between`) inside drawer-content with `lg:pl-64`, so tooltip-left pushed
the long tooltip text under the sidebar. Bottom orientation has plenty of
vertical room and is free of horizontal viewport edges.

Tests: TestResolveDockerPath_NegativeTTLRetry covers the self-heal path,
TestResolveDockerPath_WellKnownPathFallback covers the new probe.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

📦 Build Artifacts

Workflow Run: View Run
Branch: fix/installer-clean-env-docker-probe

Available Artifacts

  • archive-darwin-amd64 (26 MB)
  • archive-darwin-arm64 (23 MB)
  • archive-linux-amd64 (15 MB)
  • archive-linux-arm64 (13 MB)
  • archive-windows-amd64 (26 MB)
  • archive-windows-arm64 (23 MB)
  • frontend-dist-pr (0 MB)
  • installer-dmg-darwin-amd64 (19 MB)
  • installer-dmg-darwin-arm64 (18 MB)

How to Download

Option 1: GitHub Web UI (easiest)

  1. Go to the workflow run page linked above
  2. Scroll to the bottom "Artifacts" section
  3. Click on the artifact you want to download

Option 2: GitHub CLI

gh run download 24958550571 --repo smart-mcp-proxy/mcpproxy-go

Note: Artifacts expire in 14 days.

@Dumbris
Dumbris merged commit f010ffb into main Apr 26, 2026
24 checks passed
@Dumbris
Dumbris deleted the fix/installer-clean-env-docker-probe branch April 26, 2026 14:20
Dumbris added a commit that referenced this pull request Apr 26, 2026
…421)

When mcpproxy is launched from a sandboxed PATH (PKInstallSandbox or a
GUI launchd context that strips /usr/local/bin), the source resolver's
bare exec.CommandContext("docker", ...) fails silently. The resolver
returns "no Docker container found" with no diagnostic logging, and the
scan falls through to SourceMethod=tool_definitions_only. That makes the
Web UI render the misleading "Local (no Docker)" badge for servers that
ARE running in Docker, and triggers MCP-MC-001 false positives because
the scanner sees only the synthetic tools.json instead of real source.

PR #420 fixed the same class of bug for the docker IMAGE probe in
internal/security/scanner/docker.go but missed source_resolver.go,
which has 15 separate bare "docker" invocations (ps/diff/cp/exec).

This commit:
  - Adds (*SourceResolver).dockerCmd that resolves the binary via
    shellwrap.ResolveDockerPath, mirroring the helper already used
    in scanner/docker.go.
  - Routes all 15 docker invocations (including dockerExecCapture,
    converted to a method) through the helper.
  - Adds a Warn log when findServerContainer fails so users can see
    why source extraction fell back to tool_definitions_only —
    previously this was a silent path that produced misleading UI.

Verified manually against the running mcpproxy-obsidian-pilot-9179
container with PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/libexec":
the resolver now finds docker at /Applications/Docker.app/Contents/
Resources/bin/docker, returns Method=docker_extract, ContainerID set,
and extracts 21 files of obsidianpilot source. Previously this exact
scenario produced "could not resolve source... no Docker container
found" and SourceMethod=tool_definitions_only.

Tests:
  - TestDockerCmdUsesResolvedBinary: dockerCmd produces *exec.Cmd
    with absolute resolved Path, never a bare relative "docker" that
    would silently rely on $PATH.
  - TestDockerCmdFallbackWhenShellwrapFails: helper never returns nil
    or empty Path, mirroring the documented fallback in docker.go.

Co-authored-by: Claude Code <[email protected]>
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.

2 participants