MCP Authentication
The Kubiya MCP server supports multiple authentication methods to secure your tools and protect API access.
Authentication Methods
1. API Key Authentication (Default)
The simplest and most common approach - use your Kubiya API key:
Environment Variable (Recommended)
# Set your API key
export KUBIYA_API_KEY="your-kubiya-api-key"
# Start the MCP server
kubiya mcp serve
Configuration File
Add to your MCP server configuration (~/.kubiya/mcp-server.json
):
{
"api_key": "your-kubiya-api-key",
"enable_runners": true,
"allow_platform_apis": false
}
Claude Desktop Configuration
{
"mcpServers": {
"kubiya": {
"command": "kubiya",
"args": ["mcp", "serve"],
"env": {
"KUBIYA_API_KEY": "your-kubiya-api-key"
}
}
}
}
2. Session-Based Authentication
For production environments, enable session management:
# Start with session management
kubiya mcp serve --production --require-auth --session-timeout 3600
This enables:
- User session management
- Session timeout (default: 30 minutes)
- Authentication middleware
- Access logging
3. Token-Based Authentication
Use temporary tokens for enhanced security:
# Generate a temporary token
kubiya auth token generate --expires 1h
# Use the token
export KUBIYA_AUTH_TOKEN="your-temporary-token"
kubiya mcp serve --require-auth
Configuration Options
Basic Configuration
{
"enable_runners": true,
"allow_platform_apis": false,
"enable_opa_policies": false,
"verbose_logging": false,
"require_auth": false,
"session_timeout": 1800
}
Enterprise Configuration
{
"enable_runners": true,
"allow_platform_apis": true,
"enable_opa_policies": true,
"verbose_logging": true,
"require_auth": true,
"session_timeout": 3600,
"whitelisted_tools": [
{
"name": "kubectl",
"description": "Kubernetes CLI tool",
"type": "docker",
"image": "kubiya/kubectl-light:latest"
}
]
}
Security Features
1. OPA Policy Enforcement
Enable Open Policy Agent (OPA) for policy-based access control:
# Enable OPA policies
kubiya mcp serve --enable-opa-policies
# Or via environment variable
export KUBIYA_OPA_ENFORCE=true
kubiya mcp serve
Restrict which tools can be executed:
{
"whitelisted_tools": [
{
"name": "kubectl",
"description": "Kubernetes commands",
"type": "docker",
"image": "kubiya/kubectl-light:latest"
},
{
"name": "terraform",
"description": "Infrastructure as code",
"type": "docker",
"image": "hashicorp/terraform:latest"
}
]
}
3. Runner Restrictions
Control which runners can be used:
# Disable runners entirely
kubiya mcp serve --disable-runners
# Or limit to specific runners
kubiya mcp serve --allowed-runners runner1,runner2
API Key Management
Creating API Keys
- Go to Kubiya Settings
- Navigate to “API Keys”
- Click “Create New Key”
- Set appropriate permissions
- Copy the key securely
Key Rotation
# Create a new key
kubiya auth key create --name "mcp-server-key" --expires 30d
# Update your configuration
export KUBIYA_API_KEY="new-api-key"
# Revoke old key
kubiya auth key revoke old-key-id
Key Permissions
Configure API key permissions:
Permission | Description |
---|
tools:execute | Execute tools and workflows |
tools:list | List available tools |
runners:read | View runner status |
runners:manage | Create/delete runners |
agents:read | View agents |
agents:manage | Create/modify agents |
Access Control
Role-Based Access
Define roles for different users:
{
"roles": {
"developer": {
"permissions": ["tools:execute", "tools:list", "runners:read"],
"allowed_tools": ["kubectl", "docker", "git"]
},
"admin": {
"permissions": ["*"],
"allowed_tools": ["*"]
}
}
}
IP Whitelisting
Restrict access by IP address:
{
"allowed_ips": [
"192.168.1.0/24",
"10.0.0.0/8"
]
}
Monitoring and Logging
Authentication Logs
Enable detailed authentication logging:
# Enable verbose logging
kubiya mcp serve --verbose
# Or via environment
export LOG_LEVEL=DEBUG
kubiya mcp serve
Audit Trail
All authenticated actions are logged:
{
"timestamp": "2024-01-15T10:30:00Z",
"user_id": "user123",
"action": "execute_tool",
"tool_name": "kubectl",
"parameters": {"command": "get pods"},
"result": "success"
}
Security Best Practices
1. Environment Security
- Use environment variables for sensitive data
- Never commit API keys to version control
- Rotate keys regularly
- Use separate keys for different environments
2. Network Security
- Use HTTPS/TLS for all communications
- Implement IP whitelisting
- Use VPN for remote access
- Monitor network traffic
3. Access Control
- Implement least privilege principle
- Use role-based access control
- Enable OPA policies for fine-grained control
- Regular access reviews
4. Monitoring
- Enable comprehensive logging
- Set up alerts for failed authentications
- Monitor API key usage
- Track tool execution patterns
Troubleshooting
Common Issues
”Authentication failed” Error
Check:
- API key is valid and not expired
- Environment variable is set correctly
- Key has required permissions
- Network connectivity to Kubiya API
”Insufficient permissions” Error
Verify:
- API key has necessary permissions
- Tool is whitelisted (if using whitelist)
- OPA policies allow the action
- User role includes required permissions
”Session expired” Error
Solutions:
- Extend session timeout
- Re-authenticate with fresh token
- Check system clock synchronization
- Verify token expiration time
Debug Mode
Enable debug mode for detailed troubleshooting:
# Start with debug logging
kubiya --debug mcp serve
# Or set environment variable
export DEBUG=true
kubiya mcp serve
Migration Guide
From Basic to Secure Setup
-
Enable Authentication:
kubiya mcp serve --require-auth
-
Add OPA Policies:
kubiya mcp serve --enable-opa-policies
-
Configure Whitelisting:
{
"whitelisted_tools": ["kubectl", "terraform"]
}
-
Test Thoroughly:
- Verify all tools work
- Test authentication flows
- Validate policy enforcement
Next Steps
Responses are generated using AI and may contain mistakes.