|
| 1 | +# Securing MCP Gateway |
| 2 | + |
| 3 | +This guide provides essential security configurations and best practices for deploying MCP Gateway in production environments. |
| 4 | + |
| 5 | +## ⚠️ Critical Security Notice |
| 6 | + |
| 7 | +**MCP Gateway is currently in early beta (v0.3.1)** and requires careful security configuration for production use: |
| 8 | + |
| 9 | +- The **Admin UI is development-only** and must be disabled in production |
| 10 | +- MCP Gateway is **not a standalone product** - it's an open source component to integrate into your solution |
| 11 | +- **No official support** is provided - security is your responsibility |
| 12 | +- Expect **breaking changes** between versions until 1.0 release |
| 13 | +- Do not use it with insecure MCP servers. |
| 14 | + |
| 15 | +## 🚨 Production Security Checklist |
| 16 | + |
| 17 | +### 1. Disable Development Features |
| 18 | + |
| 19 | +```bash |
| 20 | +# Required for production - disable all admin interfaces |
| 21 | +MCPGATEWAY_UI_ENABLED=false |
| 22 | +MCPGATEWAY_ADMIN_API_ENABLED=false |
| 23 | + |
| 24 | +# Disable unused features |
| 25 | +MCPGATEWAY_ENABLE_ROOTS=false # If not using roots |
| 26 | +MCPGATEWAY_ENABLE_PROMPTS=false # If not using prompts |
| 27 | +MCPGATEWAY_ENABLE_RESOURCES=false # If not using resources |
| 28 | +``` |
| 29 | + |
| 30 | +### 2. Enable Authentication |
| 31 | + |
| 32 | +```bash |
| 33 | +# Configure strong authentication |
| 34 | +MCPGATEWAY_AUTH_ENABLED=true |
| 35 | +MCPGATEWAY_AUTH_USERNAME=custom-username # Change from default |
| 36 | +MCPGATEWAY_AUTH_PASSWORD=strong-password-here # Use secrets manager |
| 37 | +``` |
| 38 | + |
| 39 | +### 3. Network Security |
| 40 | + |
| 41 | +- [ ] Configure TLS/HTTPS with valid certificates |
| 42 | +- [ ] Implement firewall rules and network policies |
| 43 | +- [ ] Use internal-only endpoints where possible |
| 44 | +- [ ] Configure appropriate CORS policies |
| 45 | +- [ ] Set up rate limiting per endpoint/client |
| 46 | + |
| 47 | +### 4. Container Security |
| 48 | + |
| 49 | +```bash |
| 50 | +# Run containers with security constraints |
| 51 | +docker run \ |
| 52 | + --read-only \ |
| 53 | + --user 1001:1001 \ |
| 54 | + --cap-drop ALL \ |
| 55 | + --security-opt no-new-privileges \ |
| 56 | + mcpgateway:latest |
| 57 | +``` |
| 58 | + |
| 59 | +- [ ] Use minimal base images (UBI Micro) |
| 60 | +- [ ] Run as non-root user |
| 61 | +- [ ] Enable read-only filesystem |
| 62 | +- [ ] Set resource limits (CPU, memory) |
| 63 | +- [ ] Scan images for vulnerabilities |
| 64 | + |
| 65 | +### 5. Secrets Management |
| 66 | + |
| 67 | +- [ ] **Never store secrets in environment variables directly** |
| 68 | +- [ ] Use a secrets management system (Vault, AWS Secrets Manager, etc.) |
| 69 | +- [ ] Rotate credentials regularly |
| 70 | +- [ ] Restrict container access to secrets |
| 71 | +- [ ] Never commit `.env` files to version control |
| 72 | + |
| 73 | +### 6. MCP Server Validation |
| 74 | + |
| 75 | +Before connecting any MCP server: |
| 76 | + |
| 77 | +- [ ] Verify server authenticity and source code |
| 78 | +- [ ] Review server permissions and data access |
| 79 | +- [ ] Test in isolated environment first |
| 80 | +- [ ] Monitor server behavior for anomalies |
| 81 | +- [ ] Implement rate limiting for untrusted servers |
| 82 | + |
| 83 | +### 7. Database Security |
| 84 | + |
| 85 | +- [ ] Use TLS for database connections |
| 86 | +- [ ] Configure strong passwords |
| 87 | +- [ ] Restrict database access by IP/network |
| 88 | +- [ ] Enable audit logging |
| 89 | +- [ ] Regular backups with encryption |
| 90 | + |
| 91 | +### 8. Monitoring & Logging |
| 92 | + |
| 93 | +- [ ] Set up structured logging without sensitive data |
| 94 | +- [ ] Configure log rotation and secure storage |
| 95 | +- [ ] Implement monitoring and alerting |
| 96 | +- [ ] Set up anomaly detection |
| 97 | +- [ ] Create incident response procedures |
| 98 | + |
| 99 | +### 9. Integration Security |
| 100 | + |
| 101 | +MCP Gateway should be integrated with: |
| 102 | + |
| 103 | +- [ ] API Gateway for auth and rate limiting |
| 104 | +- [ ] Web Application Firewall (WAF) |
| 105 | +- [ ] Identity and Access Management (IAM) |
| 106 | +- [ ] SIEM for security monitoring |
| 107 | +- [ ] Load balancer with TLS termination |
| 108 | + |
| 109 | +### 10. Downstream Application Security |
| 110 | + |
| 111 | +Applications consuming MCP Gateway data must: |
| 112 | + |
| 113 | +- [ ] Validate all inputs from the gateway |
| 114 | +- [ ] Implement context-appropriate sanitization |
| 115 | +- [ ] Use Content Security Policy (CSP) headers |
| 116 | +- [ ] Escape data for output context (HTML, JS, SQL) |
| 117 | +- [ ] Implement their own authentication/authorization |
| 118 | + |
| 119 | +## 🔐 Environment Variables Reference |
| 120 | + |
| 121 | +### Security-Critical Settings |
| 122 | + |
| 123 | +```bash |
| 124 | +# Core Security |
| 125 | +MCPGATEWAY_UI_ENABLED=false # Must be false in production |
| 126 | +MCPGATEWAY_ADMIN_API_ENABLED=false # Must be false in production |
| 127 | +MCPGATEWAY_AUTH_ENABLED=true # Enable authentication |
| 128 | +MCPGATEWAY_AUTH_USERNAME=custom-user # Change from default |
| 129 | +MCPGATEWAY_AUTH_PASSWORD=<from-secrets> # Use secrets manager |
| 130 | + |
| 131 | +# Feature Flags (disable unused features) |
| 132 | +MCPGATEWAY_ENABLE_ROOTS=false |
| 133 | +MCPGATEWAY_ENABLE_PROMPTS=false |
| 134 | +MCPGATEWAY_ENABLE_RESOURCES=false |
| 135 | + |
| 136 | +# Network Security |
| 137 | +MCPGATEWAY_CORS_ALLOWED_ORIGINS=https://your-domain.com |
| 138 | +MCPGATEWAY_RATE_LIMIT_ENABLED=true |
| 139 | +MCPGATEWAY_RATE_LIMIT_PER_MINUTE=100 |
| 140 | + |
| 141 | +# Logging (no sensitive data) |
| 142 | +MCPGATEWAY_LOG_LEVEL=INFO # Not DEBUG in production |
| 143 | +MCPGATEWAY_LOG_SENSITIVE_DATA=false # Never log sensitive data |
| 144 | +``` |
| 145 | + |
| 146 | +## 🚀 Deployment Architecture |
| 147 | + |
| 148 | +### Recommended Production Architecture |
| 149 | + |
| 150 | +``` |
| 151 | +┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ |
| 152 | +│ │ │ │ │ │ |
| 153 | +│ WAF/CDN │────▶│ Load Balancer │────▶│ API Gateway │ |
| 154 | +│ │ │ (TLS Term) │ │ (Auth/Rate) │ |
| 155 | +└─────────────────┘ └─────────────────┘ └────────┬────────┘ |
| 156 | + │ |
| 157 | + ▼ |
| 158 | + ┌─────────────────┐ |
| 159 | + │ │ |
| 160 | + │ MCP Gateway │ |
| 161 | + │ (Internal) │ |
| 162 | + └────────┬────────┘ |
| 163 | + │ |
| 164 | + ┌───────────────────────────┼───────────────────────────┐ |
| 165 | + │ │ │ |
| 166 | + ▼ ▼ ▼ |
| 167 | + ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ |
| 168 | + │ │ │ │ │ │ |
| 169 | + │ Trusted MCP │ │ Database │ │ Redis │ |
| 170 | + │ Servers │ │ (TLS/Auth) │ │ (TLS/Auth) │ |
| 171 | + └─────────────────┘ └─────────────────┘ └─────────────────┘ |
| 172 | +``` |
| 173 | + |
| 174 | +## 🔍 Security Validation |
| 175 | + |
| 176 | +### Pre-Production Checklist |
| 177 | + |
| 178 | +1. **Run Security Scans** |
| 179 | + ```bash |
| 180 | + make security-all # Run all security tools |
| 181 | + make security-report # Generate security report |
| 182 | + make trivy # Scan container vulnerabilities |
| 183 | + ``` |
| 184 | + |
| 185 | +2. **Validate Configuration** |
| 186 | + - Review all environment variables |
| 187 | + - Confirm admin features disabled |
| 188 | + - Verify authentication enabled |
| 189 | + - Check TLS configuration |
| 190 | + |
| 191 | +3. **Test Security Controls** |
| 192 | + - Attempt unauthorized access |
| 193 | + - Verify rate limiting works |
| 194 | + - Test input validation |
| 195 | + - Check error handling |
| 196 | + |
| 197 | +4. **Review Dependencies** |
| 198 | + ```bash |
| 199 | + make pip-audit # Check Python dependencies |
| 200 | + make sbom # Generate software bill of materials |
| 201 | + ``` |
| 202 | + |
| 203 | +## 📚 Additional Resources |
| 204 | + |
| 205 | +- [Security Policy](https://github.com/IBM/mcp-context-forge/blob/main/SECURITY.md) - Full security documentation |
| 206 | +- [Deployment Options](index.md) - Various deployment methods |
| 207 | +- [Environment Variables](../configuration/environment-variables.md) - Complete configuration reference |
| 208 | + |
| 209 | +## ⚡ Quick Start Security Commands |
| 210 | + |
| 211 | +```bash |
| 212 | +# Development (with security checks) |
| 213 | +make security-all && make test && make run |
| 214 | + |
| 215 | +# Production build |
| 216 | +make docker-prod |
| 217 | + |
| 218 | +# Security audit |
| 219 | +make security-report |
| 220 | +``` |
| 221 | + |
| 222 | +Remember: **Security is a shared responsibility**. MCP Gateway provides *some* security controls, but you must properly configure and integrate it within a comprehensive security architecture. |
0 commit comments