-
✅ Process Monitoring (
internal/daemon/process.go)- Actual process lifecycle management
- Wait for instance health
- Monitor process exit status
-
✅ Enhanced Health Checker (
internal/daemon/health.go)- Real CPU/memory monitoring with gopsutil
- HTTP health checks
- Load balancer integration
- 30-second check interval
-
✅ Encryption Queue Worker (
internal/encryption/worker.go)- Processes encryption jobs from Redis queue
- Automatic file cleanup after encryption
- Duration tracking
-
✅ SFTP Subsystem (
internal/gateway/sftp.go)- Full SFTP server implementation
- File read/write operations
- Directory listing
- File commands (remove, rename, mkdir)
-
✅ JWT Authentication (
pkg/auth/auth.go)- Token generation with 24h expiry
- Token validation
- Gin middleware for protected routes
- Optional auth middleware
-
✅ Rate Limiting (
pkg/middleware/ratelimit.go)- Per-IP rate limiting
- 10 requests/second with burst of 20
- Automatic cleanup
-
✅ API Authentication
/api/auth/token- Get JWT token- All
/api/*routes require Bearer token - User ID extracted from token
-
✅ Prometheus Metrics (
pkg/metrics/metrics.go)pastebox_boxes_created_total- Total boxes createdpastebox_boxes_active- Currently active boxespastebox_files_uploaded_total- Files uploaded per boxpastebox_encryption_duration_seconds- Encryption timepastebox_http_request_duration_seconds- HTTP latenciespastebox_http_requests_total- Total HTTP requests
-
✅ Metrics Endpoint
/metrics- Prometheus scrape endpoint- No authentication required
- Integrated into router
- ✅ Integration Tests (
tests/integration/)- Box creation and lifecycle
- Concurrent box creation (10 boxes)
- Status and listing operations
GET /health- Health checkGET /metrics- Prometheus metricsPOST /api/auth/token- Get JWT token
POST /api/pastebox/create- Create new pasteboxPOST /api/pastebox/kill/:boxId- Kill pasteboxGET /api/pastebox/:boxId/status- Get statusGET /api/pasteboxes- List all boxes
# 1. Get token
curl -X POST http://localhost:8080/api/auth/token \
-H "Content-Type: application/json" \
-d '{"user_id": "alice"}'
# Response: {"token": "eyJhbGc..."}
# 2. Use token for API calls
curl -X POST http://localhost:8080/api/pastebox/create \
-H "Authorization: Bearer eyJhbGc..." \
-H "Content-Type: application/json" \
-d '{
"encryption": true,
"passphrase": "secret",
"ttl": 3600
}'# HELP pastebox_boxes_active Number of currently active pasteboxes
# TYPE pastebox_boxes_active gauge
pastebox_boxes_active 5
# HELP pastebox_boxes_created_total Total number of pasteboxes created
# TYPE pastebox_boxes_created_total counter
pastebox_boxes_created_total 42
# HELP pastebox_http_request_duration_seconds HTTP request latencies
# TYPE pastebox_http_request_duration_seconds histogram
pastebox_http_request_duration_seconds_bucket{endpoint="/api/pastebox/create",method="POST",status="201",le="0.005"} 10
# Build
make build
# Start router (with all features)
./bin/router --config config.yaml
# In another terminal - test health
curl http://localhost:8080/health
# Get metrics
curl http://localhost:8080/metrics
# Get auth token
curl -X POST http://localhost:8080/api/auth/token \
-H "Content-Type: application/json" \
-d '{"user_id": "test"}'
# Create box (with token)
curl -X POST http://localhost:8080/api/pastebox/create \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{"encryption": true, "passphrase": "test", "ttl": 3600}'# Unit tests
go test -v ./tests/...
# Integration tests
go test -v ./tests/integration/...
# All tests with coverage
go test -cover ./...github.com/golang-jwt/jwt/v5 # JWT authentication
golang.org/x/time/rate # Rate limiting
github.com/prometheus/client_golang # Prometheus metrics
github.com/shirou/gopsutil/v3 # Process monitoring
github.com/pkg/sftp # SFTP server
Add to config.yaml:
server:
port: 8080
ssh_port: 2222
auth_secret: "change-this-in-production" # JWT secret
daemon:
max_instances: 100
health_check_interval: 30s
instance_timeout: 10m
rate_limit:
requests_per_second: 10
burst: 20- Change JWT Secret: The auth secret is hardcoded - use environment variable in production
- HTTPS: Add TLS configuration for production
- SSH Keys: Implement proper SSH key management
- Input Validation: Add more comprehensive validation
- CORS: Configure CORS if needed for web clients
- ✅ Process spawning and monitoring
- ✅ Health checks with resource usage
- ✅ JWT authentication
- ✅ Rate limiting
- ✅ Prometheus metrics
- ✅ SFTP file operations
- ✅ Encryption queue worker
- ✅ Integration tests
- TLS/HTTPS support
- Distributed tracing (Jaeger)
- Load testing (100+ concurrent boxes)
- Security testing
- Admin dashboard
- Docker containerization
- Kubernetes manifests
- CI/CD pipeline
The Pastebox Engine now has production-grade features:
- Security: JWT auth, rate limiting
- Monitoring: Prometheus metrics, health checks
- Performance: Resource monitoring, load balancing
- Reliability: Process monitoring, graceful shutdown
- Testing: Unit + integration tests
Ready for staging deployment!