This document outlines the security considerations, best practices, and implemented measures for the GPU Monitor application.
- No Hardcoded Secrets: All sensitive information moved to environment variables
- Default Value Sanitization: Safe fallback values for all configuration options
- Environment Isolation: Separate configurations for development/production
- URL Validation: Proper validation of host URLs before adding
- CORS Protection: Configurable cross-origin resource sharing
- Request Validation: Input sanitization on all API endpoints
- Error Handling: Safe error messages without information leakage
- Docker Isolation: Containerized services with minimal attack surface
- Network Segmentation: Proper container networking with restricted access
- File System Permissions: Appropriate permissions for persistent data
- Secret Management: Environment-based secret management
All security-sensitive configurations use environment variables:
# Required Security Settings
FLASK_SECRET_KEY=your-strong-secret-key-here
CORS_ORIGINS=http://localhost:8080,https://your-domain.com
FLASK_DEBUG=false
# Network Configuration
FLASK_HOST=0.0.0.0 # Consider 127.0.0.1 for localhost-only
FLASK_PORT=5000 # Change default port if needed# Production Environment
FLASK_DEBUG=false
FLASK_SECRET_KEY=generate-strong-random-key-here
CORS_ORIGINS=https://your-production-domain.com
FLASK_HOST=127.0.0.1 # Localhost only if behind reverse proxy
# Security Headers (if using reverse proxy)
SECURE_SSL_REDIRECT=true
SECURE_HSTS_ENABLED=true# Allow only necessary ports
sudo ufw allow 22/tcp # SSH
sudo ufw allow 80/tcp # HTTP (redirect to HTTPS)
sudo ufw allow 443/tcp # HTTPS
sudo ufw deny 5000/tcp # Block direct backend access
sudo ufw deny 8080/tcp # Block direct frontend accessUse nginx or similar for production:
server {
listen 443 ssl http2;
server_name your-domain.com;
ssl_certificate /path/to/cert.pem;
ssl_certificate_key /path/to/key.pem;
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /api/ {
proxy_pass http://localhost:5000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}location / {
auth_basic "GPU Monitor";
auth_basic_user_file /etc/nginx/.htpasswd;
proxy_pass http://localhost:8080;
}Consider integrating with OAuth providers for production:
- Google OAuth
- GitHub OAuth
- Corporate SSO/SAML
- Host configurations stored in localStorage (client-side)
- No sensitive data transmitted or stored on server
- URLs validated before storage
- GPU metrics are system information, not user data
- Consider access restrictions for sensitive environments
- Implement IP allowlisting for internal networks
# Use non-root user
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nodejs -u 1001
USER nodejs
# Minimal base images
FROM node:18-alpine AS production
# Security scanning
RUN npm audit --audit-level=moderateservices:
backend:
security_opt:
- no-new-privileges:true
read_only: true
tmpfs:
- /tmp
cap_drop:
- ALL
cap_add:
- CAP_NET_BIND_SERVICE# Using Let's Encrypt
sudo certbot --nginx -d your-domain.com
# Or generate self-signed for testing
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout /etc/ssl/private/gpu-monitor.key \
-out /etc/ssl/certs/gpu-monitor.crtadd_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline';";# Log all access attempts
log_format security '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" "$request_time"';
access_log /var/log/nginx/gpu-monitor-security.log security;# Install fail2ban
sudo apt install fail2ban
# Configure for nginx
sudo nano /etc/fail2ban/jail.local- β Hardcoding API keys or passwords in source code
- β Using default passwords or weak secrets
- β Exposing backend ports directly to internet
- β Running containers as root user
- β Disabling CORS without understanding implications
- β Logging sensitive data (passwords, tokens)
- β Returning detailed error messages to clients
- β Exposing internal file paths or system information
- β Including debug information in production builds
- All default passwords changed
- Environment variables configured properly
- CORS origins restricted to trusted domains
- Debug mode disabled in production
- Strong secret keys generated
- Input validation implemented
- Error handling sanitized
- Firewall configured to block unnecessary ports
- HTTPS enabled with valid certificates
- Reverse proxy configured (if applicable)
- Internal network segmentation implemented
- VPN access configured for remote monitoring
- Containers running as non-root users
- Security scanning performed on images
- Regular updates scheduled for dependencies
- Backup and recovery procedures tested
- Monitoring and alerting configured
- Authentication mechanism implemented
- User access levels defined
- Regular access reviews scheduled
- Session management configured
- Password policies enforced
-
Immediate Response
- Isolate affected systems
- Preserve evidence and logs
- Document timeline of events
-
Assessment
- Determine scope of compromise
- Identify affected data/systems
- Assess potential impact
-
Containment
- Stop ongoing attack
- Patch vulnerabilities
- Reset compromised credentials
-
Recovery
- Restore from clean backups
- Verify system integrity
- Monitor for reinfection
-
Lessons Learned
- Document incident details
- Update security procedures
- Implement additional controls
- IT Security Team: [contact-info]
- System Administrator: [contact-info]
- Incident Response Lead: [contact-info]
# Frontend dependencies
npm audit
npm audit fix
# Backend dependencies
pip-audit
safety check
# Docker image scanning
docker scout cves- Critical Patches: Within 24 hours
- Security Updates: Within 1 week
- Regular Updates: Monthly maintenance window
- Dependency Audit: Weekly automated scans
- Vulnerability Scanning: Nessus, OpenVAS, Qualys
- Container Security: Clair, Anchore, Twistlock
- Web Application Scanning: OWASP ZAP, Burp Suite
- Dependency Checking: Snyk, WhiteSource, FOSSA
Security is an ongoing process. Regular reviews and updates are essential for maintaining a secure system.