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

+18 -14
View File
@@ -81,23 +81,27 @@ def cmd_check(_args: argparse.Namespace) -> int:
print(f" python {sys.version.split()[0]}")
# Never print the password.
url = settings.database_url
if "@" in url:
scheme, _, rest = url.partition("://")
url = f"{scheme}://***@{rest.rpartition('@')[2]}"
print(f" database_url {url}")
if not settings.database_url_is_set:
print(" database_url NOT SET (POORBIRD_DATABASE_URL)")
problems.append("POORBIRD_DATABASE_URL not set")
else:
url = settings.database_url
if "@" in url:
scheme, _, rest = url.partition("://")
url = f"{scheme}://***@{rest.rpartition('@')[2]}"
print(f" database_url {url}")
try:
from sqlalchemy import text
try:
from sqlalchemy import text
from .db import engine
from .db import engine
with engine.connect() as conn:
version = conn.execute(text("SHOW server_version")).scalar()
print(f" database reachable (PostgreSQL {version})")
except Exception as exc: # noqa: BLE001
print(f" database UNREACHABLE: {type(exc).__name__}: {exc}")
problems.append("database unreachable")
with engine.connect() as conn:
version = conn.execute(text("SHOW server_version")).scalar()
print(f" database reachable (PostgreSQL {version})")
except Exception as exc: # noqa: BLE001
print(f" database UNREACHABLE: {type(exc).__name__}: {exc}")
problems.append("database unreachable")
try:
from alembic import command