Skip to content

fix(rosetta-mcp-server): require FERNET_KEY when REDIS_URL is set - #537

Open
zooqueen wants to merge 1 commit into
griddynamics:mainfrom
zooqueen:fix/issue-485-require-fernet-key-for-redis-oauth
Open

zooqueen wants to merge 1 commit into
griddynamics:mainfrom
zooqueen:fix/issue-485-require-fernet-key-for-redis-oauth

Conversation

@zooqueen

@zooqueen zooqueen commented Dec 3, 2026

Copy link
Copy Markdown

Summary

When REDIS_URL was set without FERNET_KEY, _build_oauth_client_storage() in src/rosetta-mcp-server/rosetta_mcp/server.py returned the bare RedisStore. Because FastMCP only applies its built-in encryption when client_storage is None, passing an unwrapped RedisStore disabled encryption and stored OAuth state—including users' upstream access_token and refresh_token in mcp-upstream-tokens—in plaintext in Redis without any error or warning.

This PR enforces encryption at rest for Redis-backed OAuth storage:

  • _build_oauth_client_storage() now raises ValueError at startup when _REDIS_STORE is configured and FERNET_KEY is unset/empty, matching the fail-fast security-by-default pattern in build_oauth_provider().
  • Removes the unreachable except ImportError fallback in _build_oauth_client_storage() (cryptography>=43.0.0 is a required package dependency).
  • Evaluates _build_oauth_client_storage() only in HTTP transport mode (_CONFIG.transport == TRANSPORT_HTTP), keeping STDIO mode unaffected even if REDIS_URL is present in the environment.
  • Updates Helm values.yaml and values-dev.example.yaml to move FERNET_KEY out of the optional section and drop optional: true when Redis is configured.
  • Updates the Docker Compose samples (docs/mcp/DEPLOYMENT_GUIDE.md, docs/web/docs/deployment.md) and src/rosetta-mcp-server/README.md to include FERNET_KEY alongside REDIS_URL.
  • Bumps rosetta-mcp to 3.0.9 and the Helm chart to 0.4.8 (appVersion: "3.0.9") to stay in sync with CI release checks.
  • Adds regression tests in src/rosetta-mcp-server/tests/test_oauth_storage.py covering missing/invalid FERNET_KEY, encrypted-at-rest storage verification, HTTP startup failure/success, and STDIO startup isolation.

AI assistance disclosure: This PR was drafted with AI coding assistance; all changes, security behavior, and test runs were reviewed and verified locally.

Closes #485

Type of change

  • MCP server, CLI, or tooling (src/rosetta-mcp-server, src/rosetta-cli, src/ims-mcp-server, src/rosettify, src/curiocity)
  • Documentation or website (docs/, *.md, docs/web/)
  • Bug fix
  • Breaking change (migration path described below)

Behavior impact

Before After
HTTP mode with REDIS_URL set and FERNET_KEY unset started silently and persisted OAuth tokens in Redis in plaintext JSON. HTTP mode with REDIS_URL set and FERNET_KEY unset fails fast at startup with ValueError instructing the operator to set FERNET_KEY. Deployments without REDIS_URL or running in STDIO mode are unaffected.

Migration path: Any existing HTTP deployment using REDIS_URL without FERNET_KEY must generate and configure FERNET_KEY (python -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())") before upgrading. Previously stored plaintext entries in Redis will be treated as cache misses on decryption (raise_on_decryption_error=False), prompting clients to re-authenticate cleanly.

Validation

  • src/validate-types.sh: Python mypy --config-file mypy.ini passed (0 errors; JS/TS packages skipped because node_modules not installed).
  • PYTHONPATH=src/rosetta-mcp-server ./venv/bin/pytest src/rosetta-mcp-server/tests/ -v: 398 passed (including 8 new tests in tests/test_oauth_storage.py, 3 of which failed before the fix).
  • PYTHONPATH=src/rosetta-cli ./venv/bin/pytest src/rosetta-cli/tests/ -q: 188 passed.
  • python3 scripts/pre_commit.py --only verify-structure --only verify-crossrefs --only verify-hooks-content --only verify-counts --only verify-links: all passed.
  • helm lint src/helm-charts/rosetta-mcp-server and helm template (default and values-dev.example.yaml): 0 errors; Chart.yaml appVersion (3.0.9) matches src/rosetta-mcp-server/pyproject.toml (3.0.9).
  • python -m build and twine check dist/* in src/rosetta-mcp-server: PASSED.

Risk and rollback

  • Blast radius: Auth/token storage startup check in rosetta-mcp-server HTTP mode when REDIS_URL is configured. Default chart deployments (no Redis) and values-prod.example.yaml (which already requires FERNET_KEY) are unaffected. Any misconfigured deployment that previously stored plaintext OAuth tokens in Redis will now fail startup until FERNET_KEY is provided.
  • Rollback: Revert the commit to restore prior behavior.

Checklist

  • Scope is narrow and explicit: one concern per PR
  • No secrets, credentials, or PII in the description, diff, or logs
  • No duplicate rules or ambiguous wording introduced
  • Safety, privacy, and approval checkpoints preserved
  • Local validation passes (see Validation above)
  • PR description explains why, not just what

When REDIS_URL was configured without FERNET_KEY, _build_oauth_client_storage()
returned the bare RedisStore instead of wrapping it with FernetEncryptionWrapper.
Because FastMCP only applies its own encryption when client_storage is None,
passing an unwrapped store caused OAuth state (including upstream access and
refresh tokens in mcp-upstream-tokens) to be stored in Redis in plaintext.

Fail fast at startup with ValueError when REDIS_URL is set without FERNET_KEY
in HTTP mode, and remove the dead ImportError fallback branch since
cryptography is a required dependency. Only construct OAuth client_storage in
HTTP transport mode so STDIO usage is unaffected.

Update Helm values (values.yaml, values-dev.example.yaml), Docker Compose
deployment examples (docs/mcp/DEPLOYMENT_GUIDE.md, docs/web/docs/deployment.md),
and src/rosetta-mcp-server/README.md to mark FERNET_KEY required whenever
REDIS_URL is configured. Bump rosetta-mcp to 3.0.9 and the Helm chart to 0.4.8
(appVersion 3.0.9).

Closes griddynamics#485

Signed-off-by: zooqueen <a@zoo.ngo>

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.

[Bug]: rosetta-mcp-server stores OAuth tokens in Redis unencrypted when FERNET_KEY is unset

1 participant