Harden: Sentry budget + Cache-Control opt-in + Postgres migration CI - #53
Merged
Conversation
…e migrations on Postgres - sentry.py / logging.py: floor the metered Sentry Logs stream at WARNING (enable_logs=True was unfloored) and quiet httpx — its per-request INFO lines from OAuth calls were the firehose, and logs are a separately-billed budget. Pin transient upstream failures (OAuth provider / DB briefly unreachable) to one `upstream-unavailable` fingerprint so an outage is one rising-count issue rather than a storm (Sentry never samples errors). - main.py: add a default `no-store` Cache-Control middleware (caching is now opt-in) so per-user/token-bearing responses can't be cached by a proxy; the JWKS endpoint opts in to `public, max-age=3600` so verifiers keep caching keys. - ci.yml: add a `migrate` job that applies migrations against real Postgres 16 with a full downgrade->upgrade round-trip — the test suite builds its schema on SQLite and never runs Alembic. Validated locally against postgres:16. - add CLAUDE.md (conventions + production-hardening checklist).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #52.
Applies the production-hardening lessons from the aoe2-live-standings-api launch audit. (Prune, pool sizing, and CF-IP rate limiting were already in place — this covers the rest.)
Changes
app/sentry.pyfloors the metered Logs stream withLoggingIntegration(sentry_logs_level=WARNING)andapp/logging.pyquietshttpx/httpcore.enable_logs=Truewas unfloored, and httpx emits one INFO line per OAuth call — the dominant volume against a separately-billed budget.before_sendpins transient upstream failures (OAuth provider / DB briefly unreachable, matched by exception class name) to a singleupstream-unavailablefingerprint. Errors are never sampled, so a short outage under load would otherwise flood the errors budget with near-duplicates. It only re-groups; it never drops.app/main.pyadds a middleware defaulting every response tono-store(caching opt-in), so this auth service can't have per-user/token-bearing responses cached by a proxy./auth/jwksopts in topublic, max-age=3600so verifiers keep caching public keys.ci.ymlgains amigratejob running migrations against real Postgres 16 (apply head + a full downgrade→upgrade round-trip). The suite is SQLite-only and never runs Alembic, so a Postgres-specific DDL/backfill issue would otherwise first surface at deploy.Test plan
uv run ruff check ./ruff format --check .— passuv run pytest— 152 passed, 1 skippedpostgres:16(upgrade head → downgrade base → upgrade head, all clean) — this is exactly what the new CImigratejob runs.