security: encrypt sensitive DB fields, clean up dynamic import
Encrypt Proxmox server passwords and VM cloud-init passwords in the database: - Add backend/app/crypto.py: Fernet-based encrypt/decrypt helpers + EncryptedString SQLAlchemy TypeDecorator (transparent to all existing code, no API changes) - Add FERNET_KEY config field (env var); without it values stay plaintext for backward compatibility, with a logged warning - Update models.py: ProxmoxServer.password and VMInstance.cloud_init_password now use EncryptedString(255) instead of String(255) - Add migration 14 in migrations/migrations.py: idempotent re-encryption of existing plaintext rows (skipped when FERNET_KEY is not set) CSRF analysis: - /api/auth/change-password is protected by JWT Bearer token (Authorization header) - Browsers cannot auto-include Authorization headers cross-site → CSRF is not applicable here; added explanatory comment Improve migration loading: - Add migrations/__init__.py to make it a proper Python package - Replace fragile importlib dynamic loading in main.py with a standard import https://claude.ai/code/session_019rK2wvaWg5zXFwmAPPEB7R
This commit is contained in:
@@ -53,6 +53,11 @@ class Settings(BaseSettings):
|
||||
# Default admin password — MUST be changed via env var in production
|
||||
ADMIN_PASSWORD: str = Field(default="admin123", env="ADMIN_PASSWORD")
|
||||
|
||||
# Fernet key for encrypting sensitive DB fields (Proxmox passwords, cloud-init passwords).
|
||||
# Generate with: python -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())"
|
||||
# If not set, values are stored as plaintext (backward-compatible but insecure).
|
||||
FERNET_KEY: Optional[str] = Field(default=None, env="FERNET_KEY")
|
||||
|
||||
# Timezone
|
||||
TZ: str = Field(default="UTC", env="TZ")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user