Skip to content

生产上线前加固:关闭 API 文档 + 移除测试登录旁路 + deploy-prod - #47

Merged
zfqxuz merged 11 commits into
mainfrom
feat/prod-deploy
Oct 29, 2026
Merged

zfqxuz merged 11 commits into
mainfrom
feat/prod-deploy

Conversation

@zfqxuz

@zfqxuz zfqxuz commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

生产上线前加固 + 首次生产部署流水线。

改动

  • P-1 关闭 API 文档:新增 Settings.expose_api_docs(EXPOSE_API_DOCS,默认 false);/docs、/redoc、/openapi.json 与 GraphiQL IDE 一并关闭,POST /graphql 不受影响。回归用例 tests/unit/test_expose_api_docs.py。
  • P-4 移除测试登录旁路:删除 test_bypass.py、两个 consume 短路、两个配置字段与单测;测试/生产 Nacos 已删键。假号 + 固定码不再能登录。
  • CI:新增 deploy_prod 手动开关与 deploy-prod job(needs: [build-backend, deploy-test]),生产复用测试验证过的同一 digest;依赖(redis/nacos)由生产机 docker-compose.deps.yml 单独维护。
  • 文档:CHANGELOG、上线清单 P-1/P-4 打勾、旁路设计稿归档。

验证

  • 本地:flake8 src/ 通过;pytest tests/ 除既有环境依赖型失败(integration 需真实 Postgres/Redis、test_whitelist_converter 基线即失败)外全绿。
  • 生产机:redis/nacos 已起,prod_db 连接与 alembic 0021 已核对。
  • 部署后冒烟:/docs 404、旁路登录非 200(CI 脚本内置断言)。

上线影响

  • 合并后 main 推送会自动重建并部署测试环境(现有行为),生产仍需手动 dispatch 勾选 deploy_prod。
  • 未合并前不会动 main。

zfqxuz added 4 commits October 29, 2026 02:10
P-1: /docs, /redoc, /openapi.json and the GraphiQL page are now gated by
Settings.expose_api_docs (env EXPOSE_API_DOCS, default false). POST /graphql
keeps working either way. Adds tests/unit/test_expose_api_docs.py.
Deletes src/common/verification/test_bypass.py, the two consume()
short-circuits, the Settings fields and the unit tests. Fixed-code test
accounts no longer authenticate; every account must pass real
SMS/email verification.
Adds a deploy_prod workflow_dispatch input and a deploy-prod job that
needs [build-backend, deploy-test], so production always runs the exact
digest the test environment just validated. Dependencies (redis/nacos)
stay in /opt/thvote/prod/docker-compose.deps.yml, out of the compose file
CI overwrites. Post-deploy smoke checks assert /docs is 404 (P-1) and the
old bypass login no longer returns 200 (P-4).
CHANGELOG entry, readiness checklist P-1/P-4 ticked, bypass design doc
archived as removed, captcha-onboarding section invalidated, scraper e2e
instructions updated to require a real verification code.
TRUSTED_PROXY_IPS/ADMIN_ALLOWED_IPS are list[str], so pydantic-settings
JSON-decoded them at the source layer and an empty string (the documented
'leave blank' form) raised SettingsError before any validator ran, crashing
the process at import time. Switch both to NoDecode plus a tolerant parser
accepting '', JSON arrays and comma-separated values.
zfqxuz added 2 commits October 30, 2026 00:25
- src/common/crypto.py: AES-256-GCM + HKDF content/index keys + HMAC blind index
- migration 0022: encrypted columns + (provider, subject_idx) unique index, plaintext nullable
- user/user_identity: encrypted columns + *_plain accessors
- DAO/service/admin: exact lookup by blind index, remove fuzzy identity search
- import_legacy_voters.py: write ciphertext, dedup by subject_idx, --only-test-accounts
- main.py: log PII DEK fingerprint at startup, fail fast if missing
- docker-compose.prod.yml: mount pii_dek secret
- scripts/verify_import.py: read-only import verification
@zfqxuz
zfqxuz merged commit 6d8afc1 into main Oct 29, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant