Cycle Plan: 2026-02-16 — Production Hardening
A) Current Findings & Risks
- Admin Auth: Currently relies on
X-Admin-Keyheader. This is a "bootstrap" mechanism and isn't linked to Supabase User identities. - Database Security: RLS is planned but not implemented. All tables are currently accessible if RLS isn't explicitly enabled and configured.
- Ingestion Pipeline:
/upload-curriculumis a standalone "manual" upload. It doesn't link to thereferencesdiscovered by scrapers. - Multilingual RAG: Reranker has basic support, but the initial vector search recall for Arabic questions against French curriculum needs verification/tuning.
B) Proposed Changes (Phased)
Phase 1: Identity-Based Authorization & RLS
- Goal: Shift from "Secret Key" to "JWT Role" for admin actions.
- Action: Update
auth.pyto include aRequireAdmindependency. - Action: Apply RLS Phase 1 to
profiles,wallet,wallet_ledger, andusage_logs.
Phase 2: Reference-Driven Ingestion
- Goal: Move from manual file uploads to "Ingest by Reference".
- Action: Add
POST /vector-embeddingendpoint that accepts areference_id. - Action: This endpoint will fetch the PDF from the reference URL, process it, and update the
referencesstatus in the DB.
Phase 3: Multilingual Retrieval Hardening
- Goal: Ensure Arabic questions find French content.
- Action: Refine
reranker.pyprompt to explicitly handle cross-lingual relevance. - Action: Update
/chatto include auser_idin the LangGraph state for better usage logging.
C) File-by-File Change List
| File Path | Change Description |
|---|---|
app/core/auth.py |
Add get_current_admin dependency using JWT role check. |
app/api/routers/scraping.py |
Replace verify_admin (key-based) with get_current_admin (role-based). |
app/api/routers/upload.py |
Replace verify_admin with get_current_admin. Add /vector-embedding logic. |
app/services/supabase_references.py |
Add get_reference_by_id and update_reference_status helpers. |
db/migrations/20260216000006_rls_phase_1.sql |
New migration for RLS policies. |
db/bootstrap.sql |
Append new migrations to remain the source of truth. |
docs/10_current_state/api_inventory.md |
Update with new /vector-embedding endpoint. |
D) DB Migration List
20260216000006_rls_phase_1.sql:- Enable RLS on
profiles,wallet,wallet_ledger,usage_logs. - Add
SELECTpolicies for owners. - Restrict all write access to
service_role.
E) External Actions Checklist
See docs/20_runbooks/external_actions_checklist.md for detailed SQL and environment steps.
F) Test Plan
- Auth Test: Call
/scraping/sourceswith no auth (Success). - Admin Test: Call
/scraping/koutoubi/syncwith Student JWT (Expect 403). - Admin Test: Call
/scraping/koutoubi/syncwith Admin JWT (Expect 200). - Ingestion Test: Call
/vector-embeddingwith a validreference_id. Verify Pinecone namespace is populated. - RLS Test: Use a Student Supabase Key to try and read another user's
walletrecord (Should return empty/fail).
G) Rollback Strategy
- DB: Run
DROP POLICY ...or revert to previous migration state. - Code: Git revert to
HEAD^. - Infra: Re-enable
ADMIN_API_KEYrequirement if JWT auth fails in production.