Commit Graph
15 Commits
Author SHA1 Message Date
ruvnet e7aa82b52c fix(plugin): add ChatGPT federation manifest 2026-09-12 10:09:05 -04:00
ruv b329f0937c feat(gateway): OAuth 2.1 on x.ruv.io/mcp, and no credentials as tool arguments
Two changes, one per service.

**Connector:** `callerToken` is gone from the public tool schema. A credential
passed as a tool argument is model-generated — it lands in the model's context
and in tool-call transcripts, and makes authority something the model can be
talked into supplying. Authentication belongs to the transport; the tool should
receive an already-authenticated identity. A test now asserts NO tool exposes an
argument matching token/secret/password/credential.

**Gateway:** OAuth 2.1 as an additive second credential, so x.ruv.io/mcp can be
used by an MCP host that authenticates rather than one holding a shared secret.

  * RFC 9728 discovery at both probed paths, `resource` echoing the identifier
    the client asked about
  * bearer validation against the issuer's JWKS, audience pinned to this
    resource's own client_id
  * `swarm:read` / `swarm:publish` — deliberately NOT `federation:*`. Isolation
    comes from audience pinning, not scope exclusivity (correcting an earlier
    overstatement of mine), but distinct scopes keep a consent screen honest
    about what this resource grants
  * CORS preflight, and WWW-Authenticate exposed so a browser-origin client can
    read the challenge at all
  * reads stay open and adminToken keeps working — this is the federation's open
    front door and closing it would strand every existing participant

Three defects the tests caught, each of which would have shipped looking correct:

  * `adminToken` was REQUIRED in the schema, so every OAuth-authorised write was
    rejected at validation before the handler could consider the token. OAuth
    writes were impossible. Now optional; the handler enforces, and an existing
    test that encoded the old contract was updated to assert the refusal at the
    handler rather than simply dropped.
  * no audience guard: without RUFLO_OAUTH_CLIENT_ID the gateway would have
    honoured any token this issuer ever minted, for any Cognitum app. It now
    refuses bearer tokens entirely rather than accepting them unpinned.
  * a bearer that fails verification is refused, never silently downgraded to
    anonymous — which would hand a caller that believes it is authenticated the
    quieter anonymous permission set.

NOT YET DEPLOYED to x.ruv.io: the `ruflo-x-gateway` client does not exist on
auth.cognitum.one, so OAuth would be inert (and, without the guard above, would
have been worse than inert). It needs an upstream migration first.

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_013u4pmL9ZUAXb6usVQgNo67
2026-09-11 09:56:56 -04:00
ruv c6b825897b test(federation): make e2e correct in the enforced world
With CGF_OAUTH_REQUIRED=true an unauthenticated tools/list is SUPPOSED to 401,
so the script reported two failures for the system working as designed. A test
that goes red when the thing it tests starts working correctly is worse than no
test: the next person learns to ignore it.

It now reads the enforcement state first and asserts accordingly:

  * enforced, no token — checks the surface via the public service-info document
    (which is unauthenticated by design), asserts the challenge is issued, and
    reports the MCP-surface checks as PENDING rather than failed;
  * enforced, CGF_ACCESS_TOKEN supplied — exercises the real MCP surface and the
    publish/read-back/dedupe path with that token;
  * not enforced — the previous behaviour, via x-caller-token.

Two assertions added that only mean anything now: an unauthenticated call is
challenged, and the retired caller token no longer authorises publishing — the
transitional door is shut, not merely unadvertised.

PENDING is deliberately distinct from FAIL throughout. "We did not exercise
this" and "this is broken" must not look alike.

Against production with OAuth enforced: 11 passed, 0 failed, 2 pending.

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_013u4pmL9ZUAXb6usVQgNo67
2026-09-11 08:24:58 -04:00
ruv 005dbf186f fix(federation): point the 401 challenge at the metadata for the requested path
RFC 9728 §5.1: resource_metadata must name the metadata document for the
resource the client actually requested. A client using <base>/mcp was being sent
to the bare document, whose `resource` is <base> — an identifier it never asked
about. That is the same mismatch already fixed inside the documents themselves,
and it stalls setup silently rather than erroring.

The challenge now carries the /mcp suffix when /mcp was requested, so the
pointer and the document agree with what the client is using.

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_013u4pmL9ZUAXb6usVQgNo67
2026-09-11 08:17:23 -04:00
ruv 25d4718004 feat(federation): log the auth mode per call, without token material
"Is OAuth actually being used?" was unanswerable: Cloud Run request logging is
off for this service and the app logged nothing per request, so the only
evidence of a connector working was the user saying so.

One line per /mcp call now records the mode (oauth / legacy / denied), the
granted scopes, and a 12-hex-char SHA-256 prefix of the subject — enough to
correlate calls from one identity, not enough to identify or replay anyone.
Never the token, and the denied case records only the error code. Logging is
wrapped so it can never break a request.

A test asserts the line contains neither the token nor the raw subject.

Verified in production: an anonymous call logs auth=legacy, an invalid bearer
logs auth=denied reason=invalid_token.

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_013u4pmL9ZUAXb6usVQgNo67
2026-09-11 08:11:05 -04:00
ruv 62609d77ab fix(federation): CORS preflight and the RFC 9728 resource identifier
Two defects that would each break connector setup with nothing but a generic
"something went wrong" at the client.

**Preflight returned 405.** Only GET / and POST /mcp were routed, so OPTIONS fell
through. A browser-origin connector must preflight before it may POST, so it
could never reach the MCP endpoint at all. Now answers 204 with the methods and
headers it needs — including `authorization` — and exposes `www-authenticate`,
without which the client cannot read the challenge and so never learns where to
authenticate.

Origin is `*` deliberately: authority here comes from the bearer token, not from
where the request originated.

**The resource identifier did not match what the client asked about.** RFC 9728
§3 requires `resource` to be the identifier the client used. A client given
`<base>/mcp` fetches the path-suffixed document and expects `<base>/mcp` back;
we answered with the bare origin for both paths. That is a mismatch a client is
entitled to reject — silently, during setup. The suffixed document now returns
`<base>/mcp` and the bare one `<base>`.

Neither was caught by the existing tests because both were tested only through a
non-browser client that never preflights and never compares the resource value.
Two tests added for exactly those gaps.

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_013u4pmL9ZUAXb6usVQgNo67
2026-09-11 08:08:02 -04:00
ruv 7013988bb6 fix(federation): make the client-existence probe actually distinguish anything
The probe reported "client row not deployed" after the migration had in fact
deployed. Two defects, and the second is the one worth remembering.

It read the page TITLE. Every rejection from /oauth/authorize is a 400 titled
"Invalid OAuth Request", so the title cannot tell a registered client from an
unknown one. The reason is in the body: an unknown client says "Unknown
client_id"; a registered one renders its consent page naming the app.

And the probe omitted `state`, which the endpoint requires in practice — so even
a known-good client was rejected, which reads exactly like "not registered".

I only found both because I controlled the probe against a client that certainly
exists: `music-cognitum-one` returned the identical 400. A check that reports the
same thing for a client that exists and one that does not is measuring nothing.

Now matches on the reason, and runs a permanent control against a client that
cannot exist — so if the error page ever changes, the check fails loudly instead
of quietly becoming one that always passes.

Against production after the deploy: 16 passed, 0 failed, 2 pending (the
interactive sign-in and the CGF_OAUTH_REQUIRED flip).

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_013u4pmL9ZUAXb6usVQgNo67
2026-09-10 20:02:43 -04:00
ruv 5900dc5681 test(federation): repeatable post-deployment e2e for the connector
Turns the acceptance bar into something runnable instead of a sequence of curl
commands reconstructed each time:

  * exactly three tools, and federation_identity returns the pinned pubkey
  * protected-resource metadata names the AS and both scopes
  * the AS advertises both scopes (fails until console#345 deploys)
  * /oauth/authorize accepts client_id=chatgpt-federation — distinguishes
    "client row landed" from "not deployed yet" WITHOUT a sign-in, by telling a
    real OAuth error page apart from outright rejection
  * an unverifiable bearer is refused with a discovery pointer
  * publish, then read the event back over a SEPARATE authenticated connection
    and verify it from scratch — hash binds to content, signature verifies,
    pubkey is the connector
  * the marker appears exactly once (no duplicates on rerun)

The interactive authorization-code flow and the CGF_OAUTH_REQUIRED flip are
reported as PENDING rather than skipped, so an incomplete run cannot read as a
complete one.

Two things this got wrong first, both now fixed and worth keeping in mind:

  * the read-back originally used a freshly generated key. relay.ruv.io is
    membership-gated, so that key fails NIP-42 and the read returns nothing —
    indistinguishable from "the event is not there". It now uses an admitted
    verifier key (CGF_VERIFY_KEY), which is what "independent" has to mean on a
    gated relay: a different admitted member, not an unknown one.
  * a missing verifier key used to fail opaquely; it now names the path and what
    to set.

Current state against production: 13 passed, 2 failed, 2 pending. Both failures
are the merge-blocked items (AS scopes, client row), which is the calibration
this script needs to be trusted after the merge.

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_013u4pmL9ZUAXb6usVQgNo67
2026-09-10 18:27:23 -04:00
ruv d9934d55bf test(federation): assert the stated acceptance bar for the three token classes
One test, three tokens signed by the same key with valid signatures, separated
only by what they are addressed to:

  * a browser-session-shaped token (no iss, no aud — the shape auth_web.rs mints)
    gets 401, and the challenge names the missing claims;
  * a well-formed OAuth token for another Cognitum client (aud=music-cognitum-one)
    gets 401;
  * ours (correct issuer, aud=chatgpt-federation) succeeds, carrying exactly
    federation:read and federation:publish and nothing else.

Also states the deviation plainly in the README rather than leaving it implied:
this is client-audience binding, not RFC 8707 resource binding; it is accepted
for a single-tenant connector with its own OAuth client, is not a pattern to
copy into a multi-resource service, and stops being safe the moment these scopes
are granted to a second client.

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_013u4pmL9ZUAXb6usVQgNo67
2026-09-10 17:25:07 -04:00
ruv 6f68246729 docs(federation): record the client-id audience binding and the two traps around it
Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_013u4pmL9ZUAXb6usVQgNo67
2026-09-10 17:13:44 -04:00
ruv 3bd12277c7 fix(federation): bind the access token to the client_id, not the resource URL
The previous commit's retraction was itself based on stale information, and
reading the authorization server settled it.

auth.cognitum.one's `issue_oauth_access_token` (console services/identity/src/
jwt.rs) sets BOTH `iss` and `aud` — with `aud` = the requesting client_id. The
"neither iss nor aud" measurement in minimax-music's gateway is about a
different code path: `auth_web.rs` mints browser-session tokens through the
unbound `issue_access_token`, and that gateway verifies session tokens. The
OAuth flow has been binding all along.

So the audience to expect is this connector's client_id, not its resource URL.
That is client-audience binding rather than RFC 8707 resource binding (still
open per console ADR-038), and it closes the same confused-deputy hole here
because this connector is the only resource its client_id is registered for.
That one-client-one-resource assumption is load-bearing, which is why the
upstream migration says federation:* must never be granted to another client.

Also refuses to start when CGF_OAUTH_REQUIRED=true without CGF_OAUTH_CLIENT_ID.
Enforcing OAuth with no audience to bind to would accept any token this issuer
ever minted for any Cognitum app — strictly worse than the transitional caller
token it replaces, and far too quiet a way to get there.

Upstream client registration: cognitum-one/console#345.

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_013u4pmL9ZUAXb6usVQgNo67
2026-09-10 17:12:58 -04:00
ruv f29945e580 fix(federation): name the reason when an unbound access token is refused
auth.cognitum.one is measured to issue access tokens carrying neither an `iss`
nor an `aud` claim (minimax-music services/gateway/src/jwks.rs, citing freetokens
ADR-0017 — and that file carries an explicit warning against adding those checks
without confirming the tokens have started sending them).

This resource server checks both, so every real Cognitum token would be refused —
correctly, because an aud-less token is not bound to this resource and any
Cognitum-integrated app holding a user's token could present it here and publish
as the federation identity. That is a confused-deputy hole, and it is worse here
than elsewhere because the capability being borrowed is an identity other
participants trust.

The refusal stays. What changes is that it now says why: on failure the token is
re-verified for SIGNATURE ONLY, purely to diagnose, and a validly-signed token
missing iss/aud is reported as "signature is valid but carries no iss or aud
claim, so it is not bound to this resource". Every path still returns ok:false —
nothing is granted by the diagnostic.

Without this the symptom is a bare "invalid_token" that looks like a bad key.

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_013u4pmL9ZUAXb6usVQgNo67
2026-09-10 17:01:20 -04:00
ruv 51f3a0a22e feat(federation): OAuth 2.1 resource server, and retract the Cloud Run header claim
Two things, and the second one corrects me.

**OAuth.** Cognitum already runs an OAuth 2.1 authorization server at
https://auth.cognitum.one — authorization_code + refresh_token, PKCE S256, JWKS at
the usual path. There was no reason to build one. This adds the resource-server
half against it:

  - RFC 9728 protected-resource metadata, served at both /.well-known paths that
    clients probe, naming the issuer and both scopes.
  - Bearer validation against the issuer's JWKS, with the audience checked rather
    than merely parsed — a token minted for another Cognitum resource must not be
    able to act on the federation identity just because the same issuer signed it.
  - federation:read gates the two reads, federation:publish gates the write.
  - 401 + WWW-Authenticate: Bearer resource_metadata="…" on an absent or
    unverifiable token, which is what starts discovery.

CGF_OAUTH_REQUIRED is the switch. Unset, reads stay open and x-caller-token still
authorises publish so the connector keeps working while the authorization server
side is registered; set, both transitional doors close. It is the last step.

Note that server is public-client only (token_endpoint_auth_methods_supported:
["none"]), so there is no client secret anywhere in this design.

**Retraction.** Earlier commits and the README claimed Cloud Run consumes the
Authorization header and answers 401 before the container sees it. That is wrong.
Retested on a live allow-unauthenticated service across every header shape —
absent, opaque garbage, JWT-shaped, non-Bearer scheme, and the real application
token — on both GET / and POST /mcp. All 200, header delivered. The single 401 that
produced the claim never reproduced and its cause was never established. The claim
would have forced a pointless authentication facade and argued against putting the
OAuth bearer where the specs require it.

x-caller-token survives as the transitional door, but on its own merits now, not on
that false premise.

Also fixes the service-info block, whose OAuth advertisement silently missed its
patch anchor and shipped without it. There is now a test for it.

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_013u4pmL9ZUAXb6usVQgNo67
2026-09-10 16:54:32 -04:00
ruv 8666c5d74a fix(federation): pin the signing-key version and refuse an unexpected identity
Mounting `chatgpt-federation-nostr-sk:latest` makes `gcloud secrets versions add`
an identity change on the next cold start: the connector comes back as a pubkey the
relay has not admitted, every publish fails with `restricted:`, and readers tracking
the old identity see it go quiet rather than change names. Nothing in that sequence
produces a signal until publishing is already broken.

Two changes:

  - The deploy and rotation docs pin an explicit secret version. Rotation becomes
    add-version, admit the new pubkey, deploy a pinned revision with --no-traffic,
    verify a probe independently, then route traffic, then disable the old version.
    Admitting after traffic moves leaves a window where every publish fails;
    disabling before the probe passes strands the connector with no way back.

  - CGF_EXPECTED_PUBKEY, checked at startup, is the backstop for the deploy that
    forgets to pin. The container refuses to boot under an identity other than the
    one it was deployed for, so the rollover fails the deploy instead of happening
    silently.

Verified in production against the real image: a revision deployed with a
deliberately wrong CGF_EXPECTED_PUBKEY failed to start, logged the refusal, never
received the traffic tag, and left the serving revision untouched.

An earlier attempt at that control passed vacuously — it reused the pre-existing
image, which had no pin code in it, and a --no-traffic revision reports Ready once
the image imports without ever starting the container. Both had to be corrected
before the control meant anything.

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_013u4pmL9ZUAXb6usVQgNo67
2026-09-10 16:36:40 -04:00
ruv 506b3b90eb feat(federation): give ChatGPT Federation its own key and its own relay connection
buzz-relay refuses any EVENT whose pubkey differs from the NIP-42 identity that
authenticated the connection, so "sign it here, let the gateway relay it" is not a
policy we chose against — it is impossible. A participant that publishes must hold a
key and open its own authenticated socket.

This adds the smallest service that does that for the ChatGPT Federation connector:
three tools, no resources, public channels only.

Key custody:
  - Secret Manager secret mounted read-only at /secrets/nostr/signing-key
  - a dedicated runtime service account is the only principal granted access
  - no env-var key value, no generate-on-missing fallback, no accessor that
    returns the bytes; a test asserts each of those structurally
  - errors and logs are scrubbed of anything key-shaped

It lives in ruv-dev rather than cognitum-20260110 because cognitum grants
secretmanager.secretAccessor to the default compute service account project-wide,
and the x.ruv.io gateway runs as that account — so no per-secret binding there can
keep the gateway out. ruv-dev grants that account only roles/editor, which does not
include versions.access.

The caller token travels as x-caller-token, not Authorization: Cloud Run consumes
Authorization for its own IAM check and answers 401 before the container sees it.

Tests run a local NIP-42 relay that enforces the same identity binding as
buzz-relay, so publish is exercised end to end, including the case the whole design
turns on — an event signed by a key other than the authenticated one is refused.

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_013u4pmL9ZUAXb6usVQgNo67
2026-09-10 16:25:44 -04:00