Harden config: no credentials in code (REVIEW SEC-001, SEC-006)

SEC-006: database_url had a working default carrying a real username and
password. Removed. Absence is now reported by 'poorbird check' as a problem
(exit 1) and raised by db.py with a message that names the variable and the
example file, instead of SQLAlchemy's "Could not parse URL from string ''"
three frames down.

SEC-001: enroll_secret stays environment-only and keeps its empty default so
the Phase 1 commands still run on a fresh clone. The device endpoints will
refuse to serve without it when they land.

Both fields now reject unedited placeholders (CHANGE_ME and friends), so a
copied .example cannot boot as though it were configured.

Tests: 12 -> 17. New cases cover the absent default, the readable failure,
and placeholder rejection for both fields.

Note: 6 files unrelated to this change are not clean under 'ruff format'
(the repo is wrapped at 88, pyproject sets line-length 100). Left alone to
keep this diff reviewable.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Thomas KarnerandClaude Opus 5 committed 2026-09-21 12:11:34 +02:00
1 parent 2188bed633
commit 3344a9e9b1
5 files changed
+125 -17

No files matched your search

+10
View File
@@ -18,6 +18,16 @@ from .config import get_settings
_settings = get_settings()
if not _settings.database_url_is_set:
# create_engine("") raises "Could not parse SQLAlchemy URL from string ''",
# which sends people looking in the wrong place. Say what to actually do.
raise RuntimeError(
"POORBIRD_DATABASE_URL is not set. Export it, or put it in server/.env:\n"
" POORBIRD_DATABASE_URL=postgresql+psycopg://poorbird:<password>"
"@127.0.0.1:5432/poorbird\n"
"See server/deploy/poorbird.env.example. Run 'poorbird check' to verify."
)
engine = create_engine(
_settings.database_url,
pool_size=_settings.db_pool_size,