I have successfully implemented a comprehensive Kubernetes-based isolated scanning system for the Stellar Security Scanner that addresses all requirements:
- Added Kubernetes client dependencies (
kube,k8s-openapi) - Created
K8sScanManagerfor pod lifecycle management - Implemented proper RBAC permissions and service accounts
- Configurable CPU/RAM limits per scan pod
- Prevents "Greedy" contracts from crashing nodes
- Automatic namespace creation per scan with quotas
- Default limits: 1 CPU core, 2GB RAM per scan
- Complete egress traffic blocking from scanner pods
- Only allows DNS resolution and internal namespace communication
- Prevents data leakage and external API calls
- Configurable ingress rules for API communication
- CronJob-based cleanup every 15 minutes
- Removes scan namespaces older than 30 minutes
- Cleans up failed pods automatically
- Manual cleanup commands available
- Fluent-bit sidecar containers for real-time log collection
- Secure log transmission to main API
- Structured logging with scan ID correlation
- Configurable log destinations
- Encrypted ephemeral volumes using in-memory tmpfs
- No persistent storage of contract code
- Automatic cleanup of all scan artifacts
- Environment variable-based data passing
- Horizontal Pod Autoscaler for API pods
- Configurable concurrent scan limits
- Load-based scaling decisions
- Resource utilization monitoring
┌─────────────────────────────────────────────────────────────────┐
│ Kubernetes Cluster │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
│ │ scan-abc123 │ │ scan-def456 │ │ scan-ghi789 │ │
│ │ Namespace │ │ Namespace │ │ Namespace │ │
│ │ │ │ │ │ │ │
│ │ ┌─────────────┐ │ │ ┌─────────────┐ │ │ ┌─────────────┐ │ │
│ │ │Scanner Pod │ │ │ │Scanner Pod │ │ │ │Scanner Pod │ │ │ │
│ │ │+ Log Sidecar│ │ │ │+ Log Sidecar│ │ │ │+ Log Sidecar│ │ │ │
│ │ └─────────────┘ │ │ └─────────────┘ │ │ └─────────────┘ │ │
│ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
│ │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ stellar-security-scanner Namespace │ │
│ │ │ │
│ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │ │
│ │ │ API Pods │ │ Cleanup │ │ Auto-scaler & │ │ │
│ │ │ │ │ CronJob │ │ Resource Quotas │ │ │
│ │ └─────────────┘ └─────────────┘ └─────────────────────┘ │ │
│ └─────────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
src/kubernetes.rs- Main Kubernetes integration modulesrc/lib.rs- Added kubernetes module exportssrc/main.rs- Added CLI commands for k8s operationsCargo.toml- Added Kubernetes dependencies
k8s/00-namespace-rbac.yaml- Namespace and RBAC setupk8s/01-security-policies.yaml- Network policies and quotask8s/02-api-deployment.yaml- API service deploymentk8s/03-cleanup-autoscaling.yaml- Cleanup jobs and HPAk8s/04-secrets-config.yaml- Secrets and configurationk8s/README.md- Comprehensive deployment guide
Dockerfile- Multi-stage build for scanner containerexamples/kubernetes_isolated_scanning.rs- Complete usage example
# Run isolated scan
stellar-scanner k8s-scan contract.wasm \
--cpu-limit 500m \
--memory-limit 1Gi \
--timeout 300
# Management commands
stellar-scanner k8s-manage list
stellar-scanner k8s-manage cleanup --age-minutes 15
stellar-scanner k8s-manage statuslet manager = K8sScanManager::new(scan_config).await?;
let result = manager.execute_scan(&scan_id, &config, &contract_code).await?;- Complete Tenant Isolation: Each scan in separate namespace
- Resource Protection: Strict quotas prevent resource exhaustion
- Network Security: All egress blocked by default
- Data Protection: Encrypted in-memory volumes only
- Automatic Cleanup: No data persistence after scan completion
- Minimal Permissions: Least-privilege RBAC configuration
- Concurrent Scans: Configurable limit (default: 10)
- Resource Efficiency: Minimal footprint per scan
- Auto-scaling: HPA for API pods based on load
- Cleanup Optimization: Automated resource reclamation
# Deploy infrastructure
kubectl apply -f k8s/00-namespace-rbac.yaml
kubectl apply -f k8s/01-security-policies.yaml
# Deploy application
kubectl apply -f k8s/02-api-deployment.yaml
kubectl apply -f k8s/03-cleanup-autoscaling.yaml
# Configure secrets
kubectl apply -f k8s/04-secrets-config.yaml- Zero Data Leakage: Complete isolation prevents cross-tenant contamination
- Resource Safety: Quotas protect cluster from resource exhaustion
- Operational Simplicity: Automated cleanup and management
- Scalability: Auto-scaling handles variable load patterns
- Security: Defense-in-depth with multiple isolation layers
- Real-time scan status tracking
- Resource utilization metrics
- Cleanup job monitoring
- Log aggregation via sidecar containers
- Health checks and readiness probes
This implementation provides enterprise-grade security and isolation for smart contract scanning while maintaining high performance and operational efficiency.