feat: accept Cloudflare Access assertions on the HTTP MCP server
Cloudflare Access (Managed OAuth) runs the OAuth flow for clients such as ChatGPT; the origin verifies the signed Cf-Access-Jwt-Assertion itself -- RS256 in stdlib by construct-and-compare, issuer, AUD, expiry. Co-Authored-By: Claude Mythos 5.2 <[email protected]>
This commit is contained in:
1 parent
3909c35565
commit
57bc05ea7c
6 files changed
+488
-8
No files matched your search
@@ -79,7 +79,8 @@ src/wodify/
|
||||
service.py cache-through data access -- all fetches go through here
|
||||
render.py compact text output (token-efficient, not a DOM dump)
|
||||
listcmd.py the `list date` / `list workout` / `list mine` commands
|
||||
mcpserver.py `wodify mcp` -- the same commands as a stdio MCP server (stdlib)
|
||||
mcpserver.py `wodify mcp` -- the same commands as an MCP server, stdio or HTTP (stdlib)
|
||||
accessjwt.py verifies Cloudflare Access assertions for the HTTP server (stdlib)
|
||||
cli.py python -m wodify <cmd>
|
||||
```
|
||||
|
||||
@@ -151,6 +152,38 @@ session and other members' names. Rules that must stay:
|
||||
- Bodies over 1 MB are refused on the declared length, before reading. Logs carry the
|
||||
request line and status only -- never headers, so never the token.
|
||||
|
||||
#### OAuth: Cloudflare Access does it, the origin verifies it
|
||||
|
||||
The server implements no OAuth. `wodify.luci.ooo` is a Cloudflare Access self-hosted
|
||||
application ("Wodify MCP") with **Managed OAuth** on: Access answers an unauthenticated
|
||||
MCP client with a 401 pointing at its discovery metadata, runs registration, login
|
||||
(passkey) and token exchange itself, and forwards allowed requests to the origin with a
|
||||
signed `Cf-Access-Jwt-Assertion` header. The client's own `Authorization` header is an
|
||||
opaque `oauth:…` token that means nothing to the origin.
|
||||
|
||||
`accessjwt.py` verifies that assertion, and it must: the origin is reachable without
|
||||
Cloudflare (home IP + the right SNI), so anything that trusts the edge alone, or a plain
|
||||
header like `Cf-Access-Authenticated-User-Email`, is an open door. Checked on every
|
||||
request: RS256 signature against the team's published keys, issuer, the application's
|
||||
AUD tag, expiry, and (with `--access-email`) the identity.
|
||||
|
||||
- RS256 is verified in stdlib: one `pow()` with the public key, then the expected
|
||||
PKCS#1 v1.5 block is **constructed and compared whole**, never parsed. Cross-checked
|
||||
against an OpenSSL signature when written. The algorithm is pinned, not read from
|
||||
the token.
|
||||
- Keys are cached; an unknown `kid` triggers at most one refetch a minute. A failed
|
||||
fetch refuses the request.
|
||||
- The bearer token still works beside it -- but only on the LAN address, since Access
|
||||
now intercepts everything arriving through Cloudflare.
|
||||
- Who may log in is decided by the Access policy on the application (the account's
|
||||
reusable "Allow emails" policy). `--access-email` is not set on the deployed unit, so
|
||||
loosening that policy loosens this endpoint.
|
||||
- The service's AUD tag and team domain are flags on `wodify-mcp.service`. If the Access
|
||||
application is ever deleted and recreated, its AUD changes and the unit must follow.
|
||||
- Dynamic client registration only accepts redirect URIs on `chatgpt.com`, `claude.ai`,
|
||||
`claude.com` and localhost. Another client needs its callback added to the Access
|
||||
application's Managed OAuth settings.
|
||||
|
||||
Path on the wire: Cloudflare (proxied A record `wodify.luci.ooo`, kept current by
|
||||
`home-ddns` on luhpe, which follows every A record holding the home IP -- no per-record
|
||||
config) -> home router :443 -> Caddy on the NAS (`wodify.luci.ooo` block, `/mcp` only)
|
||||
|
||||
Reference in new issue
Block a user