RBAC-3: trust platform forwardAuth headers (X-Plat-*) instead of in-app OAuth (plat/mitosis#30) #3
No reviewers
Labels
No labels
agent-work
agent-working
ultracode
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
open-platform/app-template!3
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/rbac-3-forward-auth-headers"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Implements RBAC-3 (roadmap plat/mitosis#30): the app can now TRUST the platform edge's forwardAuth headers instead of running its own better-auth OAuth flow. RBAC-2 (the forwardAuth service + Traefik middleware) is merged to
plat/mcpmain and injectsX-Plat-User/X-Plat-Perm/X-Plat-Manageafter stripping any inboundX-Plat-*, so those headers are authoritative inside the app.Two modes (default OFF — existing apps byte-identical)
PLAT_FORWARD_AUTH/api/auth/*bridge, session-cookie/api/me, Forgejo sign-in button. Verified byte-identical homepage +/api/me.=1X-Plat-*;/api/mereturns{login,perm,manage}; example/api/managegated onX-Plat-Manage=1.better-auth (
src/auth.ts) is now imported lazily, so a header-trust app needs no OAuth/DB-auth env at all.Safety
X-Plat-User→401(never an anonymous allow), so a deploy that bypasses the edge cannot leak. A smuggledX-Plat-Manage=1with no user is denied.X-Plat-*before injecting the verified trio — documented in the README.Files
src/platform-auth.ts— header-trust identity resolver + manage gate (case-insensitive, fail-closed).src/platform-auth.test.ts—node:testunits for the decision (manage only withX-Plat-Manage=1; missingX-Plat-User→ denied).src/server.ts— two-mode wiring, lazy better-auth import, example/api/manage.src/homepage.ts— header-trust auth-box variant (no in-app sign-in); default variant byte-identical.README.md— documents both modes + the edge-is-the-gate / fail-closed contract.Validation
biome ciclean,tsc --noEmitclean,tscbuild clean./api/meno-header→401, with user→200,/api/manageuser-only→403, user+manage→200, manage-without-user→401.auth.ts(same env requirements) — behavior unchanged. CI's default-mode smoke covers the OAuth path.PLAT_FORWARD_AUTH=1); header logic is unit- and boot-validated here.🤖 Generated with Claude Code