MCP authentication #1

Closed
opened 2026-06-04 07:43:55 +00:00 by iannuzzelli · 3 comments
iannuzzelli commented 2026-06-04 07:43:55 +00:00 (Migrated from gitlab.com)

When exposing this server to the internet, implement FastMCP native OAuth2 Bearer token auth
so the server is MCP-spec compliant and supports per-client token revocation.

Approach: BearerAuthProvider on each FastMCP sub-app (sipri_app, navco_app,
nuclear_app) in server.py.

from fastmcp.server.auth import BearerAuthProvider

auth = BearerAuthProvider(
    public_key="...",   # or jwks_uri=
    issuer="https://auth.peacelink.it",
    audience="mcp-peacedata",
)
sipri_app = FastMCP("sipri", auth=auth)

Token storage (HMAC/HS256 — simplest option):

  • Server: one k8s Secret with the signing key (MCP_PEACEDATA_SIGNING_KEY), generated via
    openssl rand -base64 32.
  • Per external client: mint a JWT with a small script and store it in the client's k8s Secret
    (MCP_PEACEDATA_TOKEN):
    import jwt, os
    print(jwt.encode(
        {"sub": "assistant", "iss": "peacelink", "aud": "mcp-peacedata"},
        os.environ["MCP_PEACEDATA_SIGNING_KEY"],
        algorithm="HS256",
    ))
    
  • To revoke a client: re-mint their token (add exp + jti blocklist for tighter control).

Internal callers (webapp) are unaffected: auth is enforced at the ingress on the public
hostname only. The webapp calls the server via cluster-internal DNS and bypasses the ingress
entirely — no token needed, no code changes required.

Not needed while the server stays internal (cluster-only, no ingress).

When exposing this server to the internet, implement FastMCP native OAuth2 Bearer token auth so the server is MCP-spec compliant and supports per-client token revocation. **Approach:** `BearerAuthProvider` on each FastMCP sub-app (`sipri_app`, `navco_app`, `nuclear_app`) in `server.py`. ```python from fastmcp.server.auth import BearerAuthProvider auth = BearerAuthProvider( public_key="...", # or jwks_uri= issuer="https://auth.peacelink.it", audience="mcp-peacedata", ) sipri_app = FastMCP("sipri", auth=auth) ``` **Token storage (HMAC/HS256 — simplest option):** - Server: one k8s `Secret` with the signing key (`MCP_PEACEDATA_SIGNING_KEY`), generated via `openssl rand -base64 32`. - Per external client: mint a JWT with a small script and store it in the client's k8s `Secret` (`MCP_PEACEDATA_TOKEN`): ```python import jwt, os print(jwt.encode( {"sub": "assistant", "iss": "peacelink", "aud": "mcp-peacedata"}, os.environ["MCP_PEACEDATA_SIGNING_KEY"], algorithm="HS256", )) ``` - To revoke a client: re-mint their token (add `exp` + jti blocklist for tighter control). **Internal callers (webapp) are unaffected:** auth is enforced at the ingress on the public hostname only. The webapp calls the server via cluster-internal DNS and bypasses the ingress entirely — no token needed, no code changes required. **Not needed while the server stays internal** (cluster-only, no ingress).
iannuzzelli commented 2026-06-04 07:44:23 +00:00 (Migrated from gitlab.com)

changed the description

changed the description
iannuzzelli commented 2026-06-04 07:44:33 +00:00 (Migrated from gitlab.com)

assigned to @iannuzzelli

assigned to @iannuzzelli
iannuzzelli (Migrated from gitlab.com) closed this issue 2026-06-20 15:29:35 +00:00
iannuzzelli commented 2026-06-20 15:30:20 +00:00 (Migrated from gitlab.com)
see https://gitlab.com/peacelink/ai/mcp-peacedata/-/commit/019b23dc1ffa0f438e5f4a55308dcc84b370ee72
francesco added this to the (deleted) project 2026-08-05 15:12:12 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
peacelink/mcp-peacedata#1
No description provided.