π‘οΈ Warracker is an open source, self-hostable warranty tracker to monitor expirations, store receipts, files. You own the data, your rules!
Soften #221: deprecate built-in DB credential defaults instead of removing them
Omega (QA)fb0fc7e990a9
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 623ea82..0310ba1 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -4,7 +4,7 @@- **Dependency and runtime updates:** gunicorn 24.1.1 β 26.2.0 and gevent 24.11.1 β 26.9.0 (the new gevent ships Python 3.15 wheels, ending the from-source compile that slowed multi-arch Docker builds), python-dateutil 2.9.0 β 3.0.0, setuptools 84.0.0 β 84.2.1, and the Python 3.15 slim base image digest refreshed.-- **Database credentials have no built-in defaults anymore (#221, by Nam0101) β breaking for non-compose installs:** `DB_USER`, `DB_PASSWORD`, `DB_ADMIN_USER`, and `DB_ADMIN_PASSWORD` no longer fall back to the values that used to be printed in this repository, and the app refuses to start in production mode when any of them is missing, naming the missing variables. Both shipped Docker Compose files set all four explicitly (the Docker/ variant was missing the admin pair and relied on the removed defaults β it has been completed with the same values), so compose installs are unaffected; the Unraid app template has likewise been completed with the two admin variables; anyone running the app another way (bare metal, LXC) must make sure all four are set in the environment. The root `env.example` now lists all four (it previously lacked `DB_USER` and `DB_ADMIN_USER`).+- **Database credential defaults deprecated (#221, by Nam0101):** `DB_USER`, `DB_PASSWORD`, `DB_ADMIN_USER`, and `DB_ADMIN_PASSWORD` should now be set explicitly. The built-in defaults still work in this release, but the app logs a deprecation warning at startup naming any of the four that are not set, and the defaults will be removed in 1.0.6, when all four become required. Both shipped Docker Compose files set all four explicitly, the Unraid app template includes all four as well, and the root `env.example` now lists all four (it previously lacked `DB_USER` and `DB_ADMIN_USER`), so installs that follow the shipped templates need no action beyond checking for the warning.- **Mobile photo capture with client-side downscaling (#249, by canni):** a new "Take Photo" button opens the camera directly on mobile β the photo never enters the phone's gallery β and product photos are downscaled in the browser to at most 2048px (JPEG) before upload, so a multi-megabyte phone photo stops inflating storage and slowing uploads. Downscaling is EXIF-orientation-safe, renders transparency on white, never produces a larger file, passes animated GIFs through untouched, and falls back to the original file on any error. Applies to the add and edit photo inputs on the main and status pages.diff --git a/backend/config.py b/backend/config.pyindex 8edd4d8..72cd2fc 100644--- a/backend/config.py+++ b/backend/config.py@@ -38,10 +38,10 @@ class Config:# Database ConfigurationDB_HOST = os.environ.get('DB_HOST', 'warrackerdb')DB_NAME = os.environ.get('DB_NAME', 'warranty_db')- DB_USER = os.environ.get('DB_USER')- DB_PASSWORD = os.environ.get('DB_PASSWORD')- DB_ADMIN_USER = os.environ.get('DB_ADMIN_USER')- DB_ADMIN_PASSWORD = os.environ.get('DB_ADMIN_PASSWORD')+ DB_USER = os.environ.get('DB_USER', 'warranty_user')+ DB_PASSWORD = os.environ.get('DB_PASSWORD', 'warranty_password')+ DB_ADMIN_USER = os.environ.get('DB_ADMIN_USER', 'warracker_admin')+ DB_ADMIN_PASSWORD = os.environ.get('DB_ADMIN_PASSWORD', 'default_admin_password')# File Upload ConfigurationUPLOAD_FOLDER = os.environ.get('UPLOAD_FOLDER', '/data/uploads')@@ -81,10 +81,30 @@ class Config:MAX_COOKIE_SIZE = 4093 # Slightly under 4KB limitUSE_X_SENDFILE = False # Serve files directly via Flask; nginx is not configured to handle X-Sendfile+ @staticmethod+ def _warn_unset_db_vars(app):+ # Built-in DB credential defaults are deprecated: installs should set+ # all four variables explicitly. Warn for one release cycle (1.0.5);+ # the defaults are removed and the variables become required in 1.0.6.+ if app.config.get('TESTING'):+ return+ unset_vars = [+ var for var in ('DB_USER', 'DB_PASSWORD', 'DB_ADMIN_USER', 'DB_ADMIN_PASSWORD')+ if not os.environ.get(var)+ ]+ if unset_vars:+ logger.warning(+ "DEPRECATION WARNING: %s not set explicitly, so built-in default "+ "database credentials are in use. These defaults are deprecated and "+ "will be removed in version 1.0.6, when all four variables will be "+ "required. Set them in your environment or .env file.",+ ', '.join(unset_vars))+@staticmethoddef init_app(app):"""Initialize configuration-specific settings."""Config._check_secret_key()+ Config._warn_unset_db_vars(app)if not os.path.exists(Config.UPLOAD_FOLDER):try:@@ -118,13 +138,6 @@ class ProductionConfig(Config):@staticmethoddef init_app(app):- missing_db_vars = [- var for var in ('DB_USER', 'DB_PASSWORD', 'DB_ADMIN_USER', 'DB_ADMIN_PASSWORD')- if not app.config.get(var)- ]- if missing_db_vars:- raise RuntimeError(f"Missing required database environment variables: {', '.join(missing_db_vars)}")-Config.init_app(app)logger.info("Production configuration loaded")diff --git a/env.example b/env.exampleindex 3f8917f..0af119f 100644--- a/env.example+++ b/env.example@@ -2,9 +2,10 @@# Copy this file to .env and modify the values as needed# Database Configuration-# All four variables are REQUIRED: the application has no built-in-# defaults for database credentials and refuses to start in-# production mode when any of them is missing.+# Set all four variables explicitly. Built-in defaults still apply+# when they are unset, but those defaults are deprecated: the app+# logs a warning naming any that are missing, and they will be+# removed in 1.0.6, when all four become required.DB_USER=warranty_userDB_PASSWORD=your_secure_database_passwordDB_ADMIN_USER=warracker_admindiff --git a/unraid/warracker.xml b/unraid/warracker.xmlindex 71ed863..a397d7c 100644--- a/unraid/warracker.xml+++ b/unraid/warracker.xml@@ -51,11 +51,11 @@Display="always" Required="true" Mask="true"></Config><Config Name="DB_ADMIN_USER" Target="DB_ADMIN_USER" Default="warracker_admin" Mode=""- Description="PostgreSQL admin username, used for database migrations. Required since 1.0.5 (the app no longer assumes it). Pre-filled with the value Warracker used to assume; change it if your PostgreSQL admin user differs." Type="Variable"+ Description="PostgreSQL admin username, used for database migrations. Set it explicitly: the built-in default is deprecated and will be removed in 1.0.6. Pre-filled with the value Warracker assumes by default; change it if your PostgreSQL admin user differs." Type="Variable"Display="always" Required="true" Mask="false">warracker_admin</Config><Config Name="DB_ADMIN_PASSWORD" Target="DB_ADMIN_PASSWORD" Default="default_admin_password" Mode=""- Description="PostgreSQL admin password, used for database migrations. Required since 1.0.5 (the app no longer assumes it). Pre-filled with the value Warracker used to assume; change it to your PostgreSQL admin password." Type="Variable"+ Description="PostgreSQL admin password, used for database migrations. Set it explicitly: the built-in default is deprecated and will be removed in 1.0.6. Pre-filled with the value Warracker assumes by default; change it to your PostgreSQL admin password." Type="Variable"Display="always" Required="true" Mask="true">default_admin_password</Config><Config Name="SECRET_KEY" Target="SECRET_KEY" Default="" Mode=""