Generates `tasks/new/2026-0824.01.jul.feat.auth-api.traefik-ingress-control-2105.md` outlining the architecture and implementation steps for: - Traefik global default-deny ForwardAuth setup - Valkey-cached dynamic database bypass matrix (`is_public`, `bypass_paths`) - Hybrid universal path and CIDR exemptions - Dual-response error handling (302 vs 403) for unregistered apps - Ephemeral guest sandbox flow with passkey promotion Co-authored-by: mrteye <1945243+mrteye@users.noreply.github.com>
4.8 KiB
4.8 KiB
TASK METADATA
- Target Files:
COMPOSE_CONVENTIONS.md,server/main.ts,server/auth-session.ts,server/db.ts - Core Objective: Architect and formalize the Tier 1 Universal Global Edge Ingress Protection protocol for Traefik to enforce default-deny while supporting a dynamic, multi-tier bypass and guest sandbox matrix.
- Dependencies: Database schema update for
appstable (is_public,bypass_paths). - Additional Important Notes: Must align closely with
docs/FORWARDAUTH_REDIRECT_SPEC.mdfor dual-response handling and rely entirely on Valkey L1/L2 caching to maintain sub-millisecond edge latency for dynamic routing decisions.
1. TASK METADATA
(Defined in the header block above)
2. Architectural Considerations & Risks
- Risks:
- Recursive Deadlocks (Self-Exemption): Applying ForwardAuth globally introduces the risk of
auth-apiprotecting itself, leading to an infinite authentication loop where users cannot reach the login page to authenticate.auth-apimust be explicitly exempted. - Health Probe Failures: Traefik and orchestrator liveness/readiness probes (e.g.,
/healthz) might be blocked if they fall under the global ForwardAuth middleware, causing rolling restart failures. - Latency Regressions: If
auth-apiqueries PostgreSQL on every request to evaluate dynamic bypass paths (is_public,bypass_paths, or CIDRs), performance will tank. We must guarantee this data is piggybacked onto the existing Valkey app caching flow.
- Recursive Deadlocks (Self-Exemption): Applying ForwardAuth globally introduces the risk of
- Alternatives & Architectural Decisions:
- Dynamic Bypass Matrix: Evaluated inside
auth-apiwith Valkey L1/L2 caching instead of dynamic Traefik HTTP providers to avoid sync overhead and polling complexity. - Universal Bypasses (Hybrid Approach):
- Critical infrastructural paths (
/.well-known/acme-challenge/*,/healthz) bypass ForwardAuth directly at the Traefik router level to prevent lockout during restarts. - Semantic app paths (
/api/public/*,/webhooks/*) and CIDR allowlists are evaluated withinauth-apifor centralized auditing and hot-reloading.
- Critical infrastructural paths (
- Unregistered App Handling: Adheres to the Dual-Response protocol. Web browsers receive a
302 Redirectto a polished Hono SSR error page (/errors/unregistered), while API/cURL clients receive a fast403 Forbiddenresponse. - Guest Sandboxes: Handled natively via a Valkey ephemeral session with an
account_status: "guest"andX-Forwarded-Scopes: guest,trial. Seamless in-flight passkey promotion transitions them to full users.
- Dynamic Bypass Matrix: Evaluated inside
3. Proposed Implementation
-
Global Default-Deny Configuration:
- Document how Traefik's
entryPoints.websecure.http.middlewaresshould be updated to universally apply theauth-forward@dockermiddleware. - Define the explicit router priority and empty middleware override required for
auth-apiand ACME challenge routers to guarantee self-exemption. - Define the mechanism for explicit host-level application bypass where fully public applications (e.g. landing pages, sandboxes) can use specific Docker labels (like
traefik.http.routers.app.middlewares=) to bypass ForwardAuth entirely at the edge without traversing toauth-api.
- Document how Traefik's
-
Schema & Database Updates:
- Add database migrations for the
appstable:is_public(boolean, defaultfalse)bypass_paths(text array, default[])allowed_cidrs(text array, default[])
- Add database migrations for the
-
Valkey Caching Upgrades (
server/auth-session.ts):- Update
getAppByHostto SELECT and cache the newis_public,bypass_paths, andallowed_cidrsfields within theauth:app_by_host:<host>Valkey payload.
- Update
-
Dynamic Bypass & Dual-Response Execution (
server/main.ts):- In
GET /api/forward-auth:- Unregistered App Handling: If
getAppByHostreturns null, evaluate theAcceptheader. Issue a302 Redirecttohttps://auth.atyg.org/errors/unregistered?host=...if it containstext/html, otherwise return403 Forbidden. - Path & CIDR Exemption Check: Before checking for a valid session, evaluate the requested URI (
X-Forwarded-Uri) and Client IP against the cachedbypass_paths,allowed_cidrs, andis_publicflags. - Immediate Allowance: If the request matches a bypass rule or is public, immediately return
200 OKwithout queryinggetAuthenticatedUser().
- Unregistered App Handling: If
- In
-
Ephemeral Guest Session Generation:
- Expose a new endpoint (e.g.,
/api/guests/sandbox) that provisions a Valkey session ID without requiring PostgreSQL insertion. - Attach
account_status: "guest"to the Valkey payload and map the correspondingX-Forwarded-Scopes. - Update the
/api/passkeys/register/verifyflow to detectupgrade_sessionand persist the guest's UUID and session context to theuserstable upon successful passkey verification.
- Expose a new endpoint (e.g.,