Skip to content

feat: resolve op:// secret references for downstream servers (see Consiliency/pmcp#487) - #499

Draft
ViperJuice wants to merge 11 commits into
mainfrom
t3/pmcp-487-p2-op-refs
Draft

ViperJuice wants to merge 11 commits into
mainfrom
t3/pmcp-487-p2-op-refs

Conversation

@ViperJuice

@ViperJuice ViperJuice commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Phase P2 of #487: resolve 1Password op:// secret references for downstream servers, per the approved plan plans/detailed-pmcp-487-op-secret-references-20261108.md (sections 3.1–3.5, 3.7, the secret_refs capability and the gated pmcp secrets set). Builds on P1 (#489). Out of scope: P3 (credential_rejected, auth_check), P4 (migrate-op, doctor --resolve, writer lock), release, dotfiles.

What changes

  • pmcp.secret_refs (new): v1 reference grammar (3.3); the service-account token read on demand from $CREDENTIALS_DIRECTORY → ~/.config/credstore → ~/.config/pmcp. It is never read from the environment, and the read checks the confined walk, O_NOFOLLOW|O_NONBLOCK, fstat owner/mode, the 4 KiB cap and the ops_ prefix (3.1). Also: the trusted op executable with checks on every ancestor and execution of the resolved path, never a PATH search (3.4); op_subprocess_env as its own env builder. op read --no-newline --no-color --cache=false --config <private dir> -- <ref> runs with stdin /dev/null, bounded stdout/stderr, a 10 s timeout and kill+reap on abnormal end. At most two processes run at once, with single-flight. Failures are typed and never echo stderr or argv.
  • Provenance (3.2): lookups return SourcedValue, configs record credential_sources, and the manifest records entry_origin and extra_env_sources. Only user-store credentials resolve, plus the own env of servers that opt in from an operator source (resolve_secret_refs). References from the environment, ~/.env (which still shadows the store), project files, tenants, interpolation, or a remote header (3.2.7) are refused. Own-env op:// values and own OP_SERVICE_ACCOUNT_TOKEN pass through verbatim unless the server opts in. References are never published into os.environ. OP_* control names are never loaded, are stripped from inherited env, and are refused by secrets set/sync and auth_connect.
  • Spawn paths (3.5): resolution happens before teardown and outside the lifecycle lock, with a config-generation re-check (one re-resolve, then config_changed). This applies to connect, connect_all, restart (a failure leaves the running instance), lazy start, reconnect, gateway.refresh (keeps a server whose lookup fails), install-and-run, install_server, verify_installation and the update probe. A missed path fails closed with resolution_required. Typed failures are never retried. The npm identity gate sees key names with empty values. Static failures (grammar, source, token file) are classified at load time without calling op.
  • Redaction (3.7): exact-value redaction of the token and every resolved value, unconditional and before truncation, in raw and JSON-escaped forms. It covers process_output (including the summary), resources/prompts, sanitize_auth_diagnostic, exception_text, last_error, update-probe output, installer output, child stderr, downstream catalog text, and log rendering (getMessage, formatException, Formatter.format, plus a root-logger filter).
  • secret_refs capability (3.10) on /health (names only while HTTP auth is off) and gateway.health, evaluated per request. pmcp secrets set NAME op://... writes only to user scope, only a supported reference, and only once the serving gateway reports the capability and does not answer NAME from env or ~/.env.
  • A reference-shaped PMCP_AUTH_TOKEN stops pmcp --transport http before it binds; other PMCP_* references are dropped with a warning.
  • Docs: README, MIGRATING, SECURITY, CHANGELOG. scripts/op_live_compat.py: the operator-run, value-free live compatibility check (P2 merge gate, not run here).

Verification (dev0, narrow, -n 2, isolated HOME; no full suite)

  • tests/test_secret_refs_487.py: 151 tests using a fake op executable (records argv/env/cwd/stdin; canned values, failures, hang, overflow). Never touches the real op or 1Password.
  • Affected existing suites pass (inventory, parity, rotation, catalog-overlay, child-output, config/manifest, env store, credential, client manager, lifecycle, installer, secrets, transport, policy, log scrubber, exception/file/parse-echo guards, CLI, tools, refresher, auth).
  • Mutation checks (apply from a saved copy, expect failure, restore and verify the hash): 17 killed. Two single-layer log-redaction mutations survive by design (each rendering layer redacts independently); removing both is killed.
  • ruff check, ruff format --check and mypy src/pmcp are clean.

Full suite: hosted CI.

🤖 Generated with Claude Code


Proof this PR
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

ViperJuice and others added 11 commits November 24, 2026 01:12
…unner, redaction registry

Phase P2 of #487 (plan sections 3.1, 3.3, 3.4, 3.7). New
pmcp.secret_refs: reference classification and the v1 grammar, the
service-account token read on demand from CREDENTIALS_DIRECTORY, the
credstore and ~/.config/pmcp (never the environment) with descriptor,
owner, mode, size and prefix checks, the trusted op executable with
ancestor checks, op's own environment builder, and a bounded,
single-flighted resolver (at most two op processes) with typed failures.
New pmcp.secret_registry: unconditional exact-value redaction of the
token and every resolved value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…path

Phase P2 of #487 (plan sections 3.2, 3.5, 3.7, 3.10).
Credential lookups record provenance (credential_sources); configs keep
reference strings and only user-store credentials and opted-in operator
own env (resolve_secret_refs) resolve. Resolution runs before teardown
and outside the lifecycle lock with a config-generation re-check, in
connect, restart, lazy start, reconnect, refresh, install and the update
probe; typed failures are contained and never retried. The npm identity
gate sees key names only. References in remote headers, the environment,
~/.env and repository files are refused; OP_* control names are never
loaded or inherited. Redaction runs before truncation in tool output,
resources, prompts, diagnostics, exception text, catalog text, child
stderr, installer output and logs. /health and gateway.health report the
secret_refs capability; pmcp secrets set writes a reference only once the
serving gateway reports it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#487 plan sections 6 and 7: a fake op executable records
argv, env, cwd and stdin; nothing calls the real op or 1Password. The
inventory, parity and echo guards learn the new builder, lookup and
health call site.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ve check

#487 P2: README, MIGRATING, SECURITY and CHANGELOG, and
scripts/op_live_compat.py, the value-free live compatibility check that
is the P2 merge gate (operator-run; not run in CI).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…reaches the environment

#487 P2 mutation follow-up: O_NONBLOCK on the token open
is now observable (the walk alone refused a FIFO by lstat).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Blocking: exact-value redaction of task metadata on every task surface
and a final recursive redaction of every gateway tool response before
audit and serialization (A1/F2); a skipped ~/.env reference is held at
its layer by environment_holds, the lookup and auth_connect (F1); the
config generation is bumped only by publishing a replacement, never by a
resolution, and a superseded config is never spawned -- the current
published config is re-resolved once, then config_changed, and a
reconnect never respawns a replaced config (G1/N1); pmcp doctor reports
the token paths searched, the one used and differing systemd/credstore
copies, value-free (A3).

Also: ClientManager.refresh keeps a running server whose lookup fails
(A2); agent-registered servers never receive a resolved reference (N3);
an explicit child env base keeps a server's own OP_* (N4); host-class
static reasons are re-checked on demand (N5); doctor reports store and
refused references correctly (F3); a reference-shaped PMCP_AUTH_TOKEN is
removed for every transport (G2); op's exit wait uses the remaining
budget (G3); tokens below the redaction floor are refused (G4);
overlapping registered values leave no residue; bounded_wait instead of
asyncio.wait_for; the op spawn site joins the spawn-env inventory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…en report

#499 round 1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Blocking: a restart always hands its resolution (generation and
fingerprint, empty overlay included) to the connect, so a replacement
published during the teardown is resolved and started, never overwritten
(A4); the restart validates its resolution under the lifecycle lock
BEFORE tearing anything down, resolves the current replacement once
outside the lock, and leaves the running instance up on a second change
or a lookup failure -- the manager-level refresh does the same (A5);
registered values are redacted from non-string scalars and mapping keys
by their JSON rendering, keeping JSON valid, in task metadata and the
final response pass (A7).

Also: a fixed token clears the cached host-only reason so the spawn
proceeds, and a manifest entry keeps a host reason on the entry instead
of being skipped (N5, R2-N1); the dispatcher's exception path is
exact-redacted before its cut (R2-2); pmcp doctor says when the systemd
copy is not visible (R2-N2); tasks_cancel sanitizes before it audits;
redaction has a fail-closed depth bound and a no-match fast path;
reconnect records its typed reason on the status; environment_holds
docstring.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…unit

#499 round 2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…und 3)

#499 r3 R3-N1: one shared helper,
ClientManager.prepare_validated, now carries the pre-teardown discipline
for gateway.refresh, ClientManager.refresh and restart_server: publish,
resolve outside the lifecycle lock, check each resolution under the lock
against the config published now BEFORE any teardown, re-resolve a
replaced config once against the current one, and hold (keep running,
do not start) a name whose replacement fails its lookup or changes
again. Tests drive the real GatewayTools.refresh handler; the lifecycle
recheck of a stored host reason gets a behavioural test (R3-N2), and
prepare_spawn documents that it clears that reason on the shared config
(R3-N3).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…erms (see #487)

The claim checker's R18 rule rejected 'consent and provisioning policy'
outside the claim region; reword without changing the claim.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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