Authentication and Access Control
API Key Authentication
Always enable API key authentication in production:- Use a strong, randomly generated API key (minimum 32 characters)
- Store keys in a secrets manager (Vault, AWS Secrets Manager, etc.)
- Never commit keys to version control
- Rotate keys regularly
- Use different keys for different environments
- Local development
- Trusted internal networks
- Testing environments
api_key is set. If empty or missing, all API endpoints (except /health, /docs, /redoc) are accessible without authentication.
Client Request Authentication
All authenticated requests must include theOPEN-SANDBOX-API-KEY header:
- Use HTTPS/TLS for all API communication
- Avoid logging API keys in application logs
- Monitor for unauthorized access attempts
- Implement rate limiting at the reverse proxy level
Container Security Hardening
Drop Dangerous Capabilities
Linux capabilities control privileged operations. Drop unnecessary capabilities:SYS_ADMIN: Prevents container escape vulnerabilitiesNET_ADMIN: Blocks network spoofing and routing attacksSYS_MODULE: Prevents kernel module injectionSYS_PTRACE: Prevents process memory inspectionNET_RAW: Prevents packet crafting and sniffing
Block Privilege Escalation
Prevent processes from gaining new privileges:- Setuid/setgid binary exploitation
- Privilege escalation via file capabilities
- sudo/su within containers
Process Limits
Limit process creation to prevent fork bombs:- Light workloads: 256-512 processes
- Heavy workloads: 1024-2048 processes
- Unlimited:
null(not recommended)
Seccomp Profiles
Seccomp filters system calls to reduce the attack surface:- Empty string: Docker default seccomp profile (recommended)
- Absolute path: Custom seccomp JSON profile
- unconfined: Disable seccomp (not recommended)
clonewith dangerous flagsrebootswapon/swapoffmount/umount- Keyring manipulation
AppArmor Profiles
AppArmor provides mandatory access control:"": No AppArmor profile (default)"docker-default": Docker’s default AppArmor profile- Custom profile name: Your organization’s profile
Network Security
Network Isolation
Use bridge mode for network isolation:- Sandboxes cannot directly access each other
- Host network is isolated from sandboxes
- Port conflicts eliminated
- Network policies enforceable
- No network isolation
- Port conflicts possible
- Direct access to host network
- Better performance but less secure
Network Policy Enforcement
Control outbound traffic with network policies:- Bridge network mode only
- Egress sidecar image configured
- Main container drops
NET_ADMINcapability - Sidecar retains
NET_ADMINfor iptables management
- Default deny all egress traffic
- Allowlist only required destinations
- Block private IP ranges (RFC 1918)
- Block cloud metadata endpoints (169.254.169.254)
- Log denied connections for monitoring
TLS/HTTPS
Run OpenSandbox behind a reverse proxy with TLS:Resource Limits
Enforce resource quotas to prevent resource exhaustion:| Workload Type | CPU | Memory |
|---|---|---|
| Light (web servers) | 100m-500m | 128Mi-512Mi |
| Medium (build tasks) | 500m-2000m | 512Mi-2Gi |
| Heavy (ML inference) | 2000m-4000m | 2Gi-8Gi |
- Prevent single sandbox from consuming all host resources
- Enable fair resource sharing
- Predictable performance
- Protection against resource exhaustion attacks
Storage Security
Host Path Restrictions
Limit bind mount access to trusted paths:- Empty list: All paths allowed (dangerous in production)
- Non-empty list: Only prefixes in list are allowed
- Prevents access to sensitive host directories
/etc: System configuration/root: Root user home/var/run/docker.sock: Docker daemon socket/proc,/sys: Kernel interfaces- User home directories
Read-Only Filesystems
Mount root filesystem as read-only when possible:- Prevents malware persistence
- Protects against container modification
- Forces use of volumes for state
Image Security
Use Trusted Images
Only allow vetted container images:- Use official images from trusted registries
- Pin specific image tags (avoid
latest) - Scan images for vulnerabilities
- Review Dockerfiles before use
- Use minimal base images (alpine, distroless)
Image Scanning
Scan images for vulnerabilities:Private Registry Authentication
Configure Docker credential helpers:Kubernetes Security
Pod Security Standards
Apply Pod Security Standards to the opensandbox namespace:Network Policies
Restrict pod network access:RBAC Configuration
Minimize service account permissions:Monitoring and Auditing
Enable Logging
Collect logs for security monitoring:- Authentication failures
- Sandbox creation/deletion
- Resource quota violations
- Network policy denials
- Container exits and crashes
Centralized Logging
Forward logs to a SIEM or log aggregator:Audit Trail
Track all API operations:Incident Response
Sandbox Compromise Detection
Monitor for indicators of compromise:- Unexpected network connections
- High CPU/memory usage
- Failed authentication attempts
- Unusual process executions
- Container escapes
Emergency Procedures
Immediate Actions:-
Delete compromised sandboxes:
-
Rotate API keys:
- Review logs for attack patterns
- Update security policies
- Patch vulnerabilities
Production Security Checklist
Enable API Key Authentication
- Set strong
server.api_key - Store keys in secrets manager
- Enable TLS/HTTPS with reverse proxy
Harden Container Security
- Drop dangerous capabilities
- Enable
no_new_privileges - Set process limits (
pids_limit) - Apply seccomp profile
- Configure AppArmor (if available)
Configure Network Isolation
- Use bridge network mode
- Enable egress sidecar for network policies
- Block private IP ranges
- Configure ingress gateway
Restrict Storage Access
- Set
allowed_host_pathsallowlist - Avoid binding sensitive host directories
- Use read-only root filesystems
Implement Resource Controls
- Set CPU/memory limits on all sandboxes
- Configure appropriate quotas per workload
Secure Image Supply Chain
- Use trusted registries only
- Pin specific image tags
- Scan images for vulnerabilities
- Review Dockerfiles
Enable Monitoring
- Configure centralized logging
- Set up audit trails
- Monitor for security events
- Set up alerting
Further Reading
- Docker Security Best Practices
- Kubernetes Security Documentation
- OWASP Container Security
- CIS Docker Benchmark
- CIS Kubernetes Benchmark