-
Notifications
You must be signed in to change notification settings - Fork 614
[SECURITY]: Add environment isolation warnings and optional environment claim validation #2141
Description
Summary
Improve security posture for multi-environment deployments by adding startup warnings when default JWT configuration is detected in non-development environments, and optionally embedding an environment claim in tokens.
Motivation
When deploying MCP Gateway across multiple environments (DEV, UAT, PROD), administrators must configure unique JWT signing keys and issuer/audience values per environment. If these values are left at defaults or shared, tokens from one environment will be accepted in another.
The gateway already warns about default JWT signing keys, but there is no runtime feedback when default issuer/audience values are used in production-like environments.
Proposed Changes
1. Startup warnings for default JWT values
When ENVIRONMENT is set to staging or production, log warnings if:
JWT_ISSUERis the default value (mcpgateway)JWT_AUDIENCEis the default value (mcpgateway-api)
This helps operators catch misconfiguration during deployment.
2. Optional environment claim in tokens
Add a new configuration option EMBED_ENVIRONMENT_IN_TOKENS (default: false). When enabled:
- Include
"env": settings.environmentin gateway-issued JWTs (login, SSO, API tokens) - Add
VALIDATE_TOKEN_ENVIRONMENToption to reject tokens with mismatched environment claims
Scope: Only gateway-issued tokens are modified. External tokens from IdPs or proxy authentication are unaffected.
Backward compatibility: When VALIDATE_TOKEN_ENVIRONMENT=true, tokens without an env claim are allowed (to support existing tokens and external JWTs). Only tokens with a present but mismatched env claim are rejected.
This provides defense-in-depth for deployments where issuer/audience may not be unique.
3. Documentation updates
- Add explicit guidance to
docs/docs/manage/securing.mdabout per-environment JWT configuration - Update Helm chart comments in
charts/mcp-stack/values.yamlwith examples
Acceptance Criteria
- Startup warning logged when default
JWT_ISSUERused in non-development environment - Startup warning logged when default
JWT_AUDIENCEused in non-development environment -
EMBED_ENVIRONMENT_IN_TOKENSconfig option added (default: false) -
VALIDATE_TOKEN_ENVIRONMENTconfig option added (default: false) - Environment claim added to JWTs when
EMBED_ENVIRONMENT_IN_TOKENS=true - Environment claim validated when
VALIDATE_TOKEN_ENVIRONMENT=true(reject mismatched, allow missing) - Documentation updated with per-environment configuration guidance
Implementation Notes
Files to modify:
mcpgateway/config.py- Add new config optionsmcpgateway/main.py- Add startup warningsmcpgateway/utils/create_jwt_token.py- Embed environment claimmcpgateway/utils/verify_credentials.py- Validate environment claimdocs/docs/manage/securing.md- Add environment isolation sectiondocs/docs/manage/configuration.md- Document new config optionscharts/mcp-stack/values.yaml- Update commentsREADME.md- Add new environment variables to config table