Authentication Overview
The Secure MCP Gateway uses a multi-layered authentication system that maps API keys to projects and users, ensuring secure access control and proper request routing.Authentication Architecture
Core Concepts
1. API Keys (Gateway Keys)
Purpose: Authenticate clients and identify their project and user context. Location in config:- 34+ characters
- URL-safe characters (alphanumeric,
_,-) - Generated by
secure_mcp_gateway.utils.generate_custom_id() - Example:
2W8UupCkazk4SsOcSu_1hAbiOgPdv0g-nN9NtfZyg-rvYGat
API keys are automatically generated when you run
secure-mcp-gateway generate-config.2. Users
Purpose: Represent individual users of the gateway. Location in config:3. Projects
Purpose: Group users with a shared MCP configuration. Multiple users can belong to the same project and share access to the same set of MCP servers. Location in config:4. MCP Configs
Purpose: Define the set of MCP servers, their configurations, and guardrail policies. Location in config:Authentication Flow
Step 1: Client Provides API Key
stdio mode (Claude Desktop, Cursor):Step 2: Gateway Extracts Credentials
Location:src/secure_mcp_gateway/gateway.py:253
-
Environment variables (stdio mode):
ENKRYPT_GATEWAY_KEYENKRYPT_PROJECT_ID(optional)ENKRYPT_USER_ID(optional)
-
HTTP headers (HTTP mode):
Authorization: Bearer <API_KEY>X-Project-Id: <PROJECT_UUID>(optional)X-User-Id: <USER_UUID>(optional)
-
Request context (FastMCP):
ctx.request_context.request.headers
Step 3: Validate API Key
Location:src/secure_mcp_gateway/plugins/auth/config_manager.py
- Extract
gateway_keyfrom context - Check if key exists in
apikeyssection - If not found, return authentication error
- If found, retrieve
project_idanduser_id
Step 4: Resolve Project and User
Step 5: Load MCP Configuration
Step 6: Cache Configuration
Location:src/secure_mcp_gateway/client.py:667
Admin API Authentication
Purpose: Secure REST API endpoints for administrative operations. Admin API Key:/api/v1/configs/*- Configuration management/api/v1/projects/*- Project management/api/v1/users/*- User management/api/v1/api-keys/*- API key management/api/v1/system/*- System operations
/health- Health check (no auth required)/docs- Swagger documentation (no auth required)
Security Best Practices
API Key Rotation
API Key Rotation
Rotate API keys regularly to minimize exposure:
Least Privilege Principle
Least Privilege Principle
Create separate projects for different access levels:
Audit Logging
Audit Logging
Enable telemetry to track all authentication attempts:Review logs regularly:
Secure Key Storage
Secure Key Storage
Never hardcode API keys in code or commit them to version control:Good:Bad:
Multi-Factor Authentication
Multi-Factor Authentication
For production environments, consider implementing additional authentication layers:
- Network-level: Use VPN or IP whitelisting
- TLS certificates: Enable mutual TLS (mTLS)
- OAuth integration: Use Enkrypt’s OAuth provider for centralized auth
Common Scenarios
Scenario 1: Single User, Single Project
Use case: Personal development environmentScenario 2: Team Project, Multiple Users
Use case: Shared production environmentScenario 3: Multi-Environment, Same User
Use case: One user accessing dev, staging, and productionScenario 4: Service Accounts
Use case: Automated tools/CI/CD accessing the gatewayTroubleshooting
Error: “Invalid API key”
Cause: API key not found inapikeys section.
Solution:
Error: “Project not found”
Cause:project_id referenced by API key doesn’t exist.
Solution:
Error: “User not authorized for project”
Cause: User exists but is not in project’s user list. Solution:Error: “MCP configuration not found”
Cause:mcp_config_id referenced by project doesn’t exist.
Solution:
Next Steps
Configuration
Learn about MCP configs and server settings
API Keys Management
CLI commands for managing API keys
Projects
CLI commands for managing projects
Users
CLI commands for managing users