docs/ops: deployment bootstrap runbook — service order, seed data, grant blessings, and required scopes (for an autonomous bootstrap)

Đang mở
#83 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
43/100
Loại issue
Tài liệu
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
flask, python
Lĩnh vực
devops, documentation

Hướng nghiên cứu

Read campus/docs/prod-rollout.md, campus/docs/required-env-vars.md, and docs/circles-access-control.md for the existing deployment and grant procedures. Validate the bootstrap order and verification checklist against those references, then create the docs runbook described in the follow-up; done means it provides a consistent, actionable sequence for deployment, seed data, blessings, scopes, and verification.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

documentation enhancement

Why now

The 2026-11-19 login outage (every sign-in on both deployments 500ed) was a bootstrap prerequisite nobody had written down in one place: /login requested a scope (users:read, added in 4946d91) that the portal client's allowed_scopes cap didn't cover, and campus.auth validates that request all-or-nothing. The recovery knowledge was scattered across the README, campus/docs/prod-rollout.md, docs/circles-access-control.md, a commit message, and live debugging. This issue collects the full bootstrap sequence — deployment order, seed data, grant blessings, scopes — so an autonomous (or merely sane) bootstrap can succeed. Fixes so far: today's cap repair + PR #82 (baseline-only login + step-up), but the runbook itself is the missing artifact.

1. Deployment order (what must exist first)

Each layer depends on the previous; the campus-side mechanics live in campus/docs/prod-rollout.md (§3 staggered sequence) and campus/docs/required-env-vars.md (boot-enforced in prod, #1108):

  1. Data stores — Postgres (auth/api/audit) + Mongo (auth/api) + object bucket. Credentials in the creation payload — a volume attach before credentials land poisons the datadir (postgres needs databasePasswordReset, mongo full recreation; campus#1105). Verify connectivity via a temporary tcp-proxy before wiring app URIs.
  2. campus.audit — its operator API key (AUDIT_OPERATOR_API_KEY) auto-seeds at audit startup; every other service's AUDIT_API_KEY (traces:write) and the portal's AUDIT_UI_API_KEY (traces:read + apikeys:read + apikeys:write) are minted from that operator key afterwards. So audit before all trace producers.
  3. campus.auth — the identity fabric. Needs AUTH_SUPER_ADMIN (master admin), AUTH_OPERATOR_CLIENT_IDS (operator clients — on prod this is literally the portal client, campus-admin-production / uid-client-6ec13381), WORKSPACE_DOMAIN, and the Google OAuth app + vault label behind /google/authorize.
  4. campus.api — circles, grant store, resources. Its init_storage bootstrap is idempotent and seeds the circles graph (below); prod runs schema + seed via the one-off (ENV=development for the process only) + migration-ledger stamping per TARGET_DB (campus#1103 / #1104).
  5. Gateway (dev campus-development, prod nyjc-campus) fronting the services. Known failure mode: the dev gateway's auth/api/audit upstreams can flap 502 — consumers should set per-service URL overrides (CAMPUS_AUTH_URL / CAMPUS_API_URL / CAMPUS_AUDIT_URL) as the fallback rather than riding BASE_URL (this bit the dev portal on 2026-11-19 too).
  6. Consumer apps — campus-admin portal, classroom, etc.

2. Seed data (what must exist before anything signs in)

Circles graph (CirclesResource.init_storage(), idempotent, per docs/circles-access-control.md §Bootstrap): the @meta record, root circle, the campus-admin sentinel (the portal's default ADMIN_CIRCLE), bootstrap admins' user circles (BOOTSTRAP_ADMIN_USERS: [email protected] + [email protected] — user circles are named after the email and represent the user in role memberships), a resource circle + <resource>.admin role circle per guarded resource, and the bootstrap admins added to every role circle.

campus.auth: the guest client (public; CLI device flow) — its scope allowlist is per-environment: dev includes clients:read/clients:write, prod's does not (a prod device login requesting client-management scopes is rejected outright); the master admin account ([email protected], AUTH_SUPER_ADMIN bypass + campus-admin circle member); operator client wiring.

campus.api (prod): schema init + ledger stamps, the circles graph, vault labels the services read + vault access grants for their clients (bits: 1 = read, 15 = full).

Trap to encode in any automation: client principals cannot edit circle membership (#854 — domain administration must be attributable to a user), so the first admin must come from seed data, never from an API call. The bootstrap paradox is otherwise unresolvable.

3. The portal (campus-admin) bootstrap checklist

  1. Client mint (campus-admin-dev / campus-admin-production): redirect_uris = {PUBLIC_URL}/finalize_login (+ http://localhost:5000/finalize_login in dev). campus#651 enforces fail-closed: a callback not registered here 400s at authorize — every sign-in broken.
  2. allowed_scopes cap — the one that bit us. Must include:
    • campus.profile (OAuth floor) — always.
    • users:read — not a feature scope: flask_campus's context hook re-fetches the signed-in user's record on cache misses through users[id].get(), two-leg gated; without the scope the portal 500s on every request once the context cache expires (4946d91; the #854-family regression campus#956). This is a bootstrapping requirement of any flask_campus consumer, not a campus-admin quirk.
    • Feature vocabularies the deployment uses — today the migrations set (migrations:read/write/admin), acquired per-user via the Migrations view's step-up re-auth (PR #82). A cap gap there no longer breaks sign-in: the step-up catches it and shows the reason; the nav renders disabled-with-reason.
    • Failure mode if the cap lags the login request: campus.auth rejects sessions.new → every sign-in 500s (the outage). Since PR #82, /login requests only the structural baseline LOGIN_SCOPES_BASE = ["campus.profile", "users:read"], so cap drift on feature vocabularies degrades to visible UI states instead.
  3. Service env: SECRET_KEY, CLIENT_ID/CLIENT_SECRET, PUBLIC_URL, BASE_URL or per-service URL overrides (the gateway-flapping fallback above), AUDIT_API_KEY (producer), AUDIT_UI_API_KEY (UI key), AUDIT_TRACING_ENABLED, AUDIT_ADMINS (comma list — independent gate), ADMIN_CIRCLE (default campus-admin sentinel — independent gate).
  4. Audit keys: mint the UI key (traces:read + apikeys:read + apikeys:write) from the audit operator key; the /audit section authenticates by API key, not bearer.

4. Grant blessings — the sequence

Authority for blessings is itself bootstrapped, so order matters:

  1. Seed the first admins (circles membership + role circles) via BOOTSTRAP_ADMIN_USERS / the master admin — APIs can't do it (#854 above).
  2. A seeded admin logs in via campus-cli device flow and blesses others:
    • Circle membership: the user's user circle must exist before members/add accepts an email-shaped member; the grantor needs circles.admin (e.g. campus-test-admin grants via its own device login — credentials deliberately unshared). Live recipe: docs/circles-access-control.md §Classroom live-testing grants.
    • Grant rows (#883 two-leg designation leg): campus grant grant --grantee-type user --grantee-id <email> --resource <vocabulary> --level <read|write|admin> — requires the operator or a same-vocabulary admin; levels are hierarchical (admin ⊇ write ⊇ read).
    • Migrations grants are seeded ahead of a migration window by explicit decision — they are not standing blessings.
    • users:read/write grants for portal admins (a users:write row covers read).
  3. Env-specific CLI constraint: on prod, the guest client cannot even request clients:* login scopes, and grant-store reads/writes reject plain user tokens (#854 family) — so prod client/grant administration needs the operator context or a pre-seeded grants admin. Automations must not assume the dev CLI path works on prod.
  4. Vault blessings for service clients ride the Clients page / campus client access (bits 1/15), not the grant store.

5. Scopes reference (who needs what, and why)

Scope Required by Why
campus.profile every login OAuth floor
users:read portal /login baseline context-hook user-record fallback; missing ⇒ portal-wide 500s after cache expiry
migrations:read/write/admin Migrations view step-up capability leg; the grant row is the designation leg; services enforce both per call
read, write CLI default device-flow default set
clients:read/write campus-cli client administration dev guest allowlist yes, prod no — a grant row is also required (#883)
traces:write / traces:read + apikeys:* audit producers / audit UI API-key auth (minted from the operator key), not bearer scopes

6. Autonomous-bootstrap verification checklist

  • Every service /health 200 (incl. gateway).
  • /auth/v1/oauth/device_authorize issues codes; /auth/v1/google/authorize redirects with the right client.
  • Portal: /login 302 → authorize → finalize → dashboard 200 (a 500 here = cap / redirect_uri / secret drift — check in that order).
  • Anonymous /resources/circles 302s to sign-in; wrong-redirect_uri clients get the campus#651 browser error page.
  • Context-cache expiry does NOT 500 the next request (the users:read trap).
  • Migrations view renders the correct two-leg panel state; grant store reachable.
  • Circle/grant probes answer for the seeded admins; a non-member's section pill renders disabled with the reason (PR #82).

Follow-ups this issue tracks

  • Turn this into a script/runbook file (docs/) once validated — an autonomous bootstrap wants executable checks, not prose.
  • Upstream (campus): narrow token issuance by designation so tokens reflect grants — single-source capability detection instead of the scope+grant double probes (PR #82).
  • Upstream (campus): consider making users:read implicit for self-reads (the #879 embedded-user path already avoids the fallback on current builds; the fallback remains a bootstrap trap on older builds).
  • BOOTSTRAP_ADMIN_USERS lifecycle (removal flow) — flagged in circles-access-control.md as a deliberate follow-up.
Ngôn ngữ chính
Python
Star
0
Fork
0
Merge trung bình
13 phút
Pull request đã merge (30 ngày)
62

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

  • Không có Dockerfile hay tệp Docker Compose
  • Không có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của nyjc-computing/campus-admin

Tất cả issue của nyjc-computing/campus-admin

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.