mcpproxy-go icon indicating copy to clipboard operation
mcpproxy-go copied to clipboard

[Bug]: macOS secrets set hides required Keychain write opt-in behind misleading keyring unavailable error

Open algis-dumbris opened this issue 2 weeks ago • 0 comments

What happened?

On macOS, the documented standalone CLI command for storing/replacing a secret asks for the secret and then fails:

Error: failed to store secret: keyring unavailable (backend not usable on this system — refusing to write to avoid OS modal prompts)

In this case the error is caused by MCPProxy's macOS write opt-in being absent, not evidence of a broken Keychain. mcpproxy secrets set --help and the keyring-integration guide do not explain the opt-in. This blocks recovery from an expired GitHub PAT using the documented CLI flow.

Please preserve the intended protection against unexpected macOS Keychain modal dialogs. The bug is the missing write-eligibility preflight, misleading error, and incomplete CLI documentation, rather than the existence of the safety gate itself.

Environment

  • Installed binary: MCPProxy v0.73.0 (personal) darwin/arm64.
  • macOS 26.5.2, build 25F84, Apple Silicon.
  • DMG installation: /usr/local/bin/mcpproxy resolves to /Applications/mcpproxy.app/Contents/Resources/bin/mcpproxy.
  • MCPPROXY_KEYRING_WRITE is absent in the diagnostic shell.
  • Source references below are pinned to v0.73.0, commit f8b3c598263f4d5a2ac851819e21d8c9194ddec3.

Reproduction and evidence

  1. On macOS, leave MCPPROXY_KEYRING_WRITE unset.

  2. Run the documented mcpproxy secrets set <name> and enter a value, or reproduce with a non-sensitive placeholder:

    printf '%s\n' 'diagnostic-placeholder-not-a-credential' |
      env -u MCPPROXY_KEYRING_WRITE mcpproxy secrets set keyring-gate-probe --from-stdin
    
  3. Observe exit code 1 and the error above. The CLI prints Enter secret value: even with --from-stdin.

Locally reproduced on November 17, 2026 with the installed binary and a unique diagnostic name, using only a placeholder. The process returned in approximately 0.05 seconds:

MCPPROXY_KEYRING_WRITE set in this shell: False
Exit code: 1
stdout: Enter secret value:
stderr: [usage output omitted]
Error: failed to store secret: keyring unavailable (backend not usable on this system — refusing to write to avoid OS modal prompts)

The write gate rejects the operation before keyring.Set, so the failed probe does not store a test item. No real credential was overwritten and no opt-in write was attempted during diagnosis.

The retained main logs for November 17 contain no matching failed to store secret / keyring unavailable records; the standalone CLI's stderr is the relevant evidence. The user also reported difficulty with a web flow, but this report does not claim a verified cause for that separate UI failure.

Source-level cause

  1. secrets set obtains the value first, creates secret.NewResolver(), and calls resolver.Store(). It does not check write eligibility with a reason before prompting, nor document the macOS opt-in in its help.

  2. Resolver.Store calls provider.IsAvailable(), a read-only backend probe, before provider.Store().

  3. KeyringProvider.Store has a separate Darwin gate at lines 198–200. When opt-in is absent it returns ErrKeyringUnavailable, the same error used for an actually unavailable backend. writesEnabled accepts MCPPROXY_KEYRING_WRITE=1, true, or yes.

  4. A more accurate check already exists: IsAvailableWithReason. For this condition it returns:

    OS keychain writes require opting in on macOS outside the tray app (set MCPPROXY_KEYRING_WRITE=1, or use the tray, which opts in automatically)
    

    The standalone secrets set path does not use this explanation.

  5. The keyring guide's Store a Secret examples present the unprefixed command; macOS troubleshooting suggests Keychain should work out of the box and focuses on unlocking it, omitting the CLI write opt-in.

Why the safety gate exists

The provider's comments explain that a missing/locked/unusual macOS Keychain can cause an uncancellable system modal, potentially with a destructive reset default. The timeout wrapper only releases the calling goroutine; it cannot cancel the underlying OS interaction. The tray intentionally opts in because it is an interactive GUI context. A terminal CLI is a separate process and does not inherit the tray core's environment.

This policy should be communicated as disabled write permission, separately from backend failure. An explicit secret-store command should either guide the user to a scoped opt-in or implement an intentional interactive consent flow while retaining noninteractive protections.

Expected behavior / suggested fix

  • Check write eligibility before requesting the secret value.

  • Distinguish opt-in-disabled, headless execution, and unavailable/locked/unresponsive backend states.

  • Explain MCPPROXY_KEYRING_WRITE=1 in the error/help and macOS documentation, including why OS prompts may occur.

  • Offer the one-command opt-in pattern for users deliberately using the CLI:

    MCPPROXY_KEYRING_WRITE=1 mcpproxy secrets set <name>
    

    This follows the existing source contract; a successful opt-in write was not independently tested in this investigation.

  • Add tests with fake keyring functions covering a usable read backend + absent macOS opt-in, truthful actionable diagnostics before the input prompt, enabled opt-in, and an actually unavailable backend.

  • Do not silently fall back to plaintext credential storage or unconditionally disable the protection.

Related reports

  • #409 / merged #413 fixed the same gate for tray-launched core by setting the environment variable in the macOS launcher. This issue is the remaining standalone CLI diagnostics/documentation path; #413 explicitly documents that CLI users can manually set the variable.
  • #1922 is a separate GitHub OAuth sign-in eligibility bug. Here, replacing an expired static PAT via secrets set is blocked by the keyring policy instead of the OAuth flow.

Checks

  • Searched existing issues for keyring unavailable and MCPPROXY_KEYRING_WRITE; no matching open standalone-CLI report found.
  • Reproduced the exact error with a non-secret placeholder and captured exit code, elapsed time, and stderr.
  • Inspected the installed CLI help and pinned implementation. No real secrets are included in this report.

algis-dumbris avatar Nov 17 '26 07:11 algis-dumbris