docs: replace api-gateway specs with authenticator + gateway PRD/DESIGN (nginx+auth step 01) - #1662
Conversation
…FF step 01) Remove the docs/components/backend/api-gateway/ tree (umbrella PRD/DESIGN, bff/, router/) per the nginx + authorization decision: the custom Rust Router is replaced by an OpenResty gateway, and the BFF survives as a standalone authenticator service. New artifacts: - docs/components/backend/authenticator/PRD.md + DESIGN.md - OIDC login, stable-session-id / rotating-credential split, login-minted linked gateway JWT (sub=person_id, tenants[], roles, sid), /internal/authz exchange contract with Cache-Control semantics, background IdP token refresh (fail-open transport / fail-closed invalid_grant), RFC 7523 service tokens with a gitops registry, two-listener reachability, first-admin bootstrap, gear anatomy. DD-ROUTER-05 and the "no IdP refresh in v1" carve-out recorded as superseded; DD-ROUTER-03/09/10 and DD-BFF-01/02/03/09 carried over. EdDSA vs ES256 recorded as open (resolved in step 04). - docs/components/backend/gateway/DESIGN.md - nginx edge: ingress- orthogonal topology, route configurator (salvaged routes.yaml schema, minus websocket_max_lifetime_seconds), generated location hygiene block, subrequest contract, Lua exchange cache / correlation ids / RFC 9457 error shaping, failure table, reload procedure. Parent backend specs (PRD/DESIGN) updated: authentication rewritten to the token-handler model, architecture diagram and routing rules now go through the gateway, authenticator + gateway components added, first- login and analytics-query sequences updated. cypilot artifacts registry updated accordingly. Note: cfs validate --local-only currently reports "No artifacts found in registry" for this repo (pre-existing cypilot issue, reproducible on untouched artifacts from main); cfs toc and cfs check-language pass on all touched artifacts, and a manual where-used sweep found no dangling cpt-insightspec-* references. Part of EPIC constructorfabric#1583. Closes constructorfabric#1584. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: Anton Zelenov <antonz@constructor.tech>
📝 WalkthroughWalkthroughThis PR replaces API Gateway documentation with Authenticator Service and nginx Gateway documents, updates backend specs to the new session-to-JWT auth flow, and repoints the artifact registry to the new document locations. ChangesBackend auth architecture documentation overhaul
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related issues
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/components/backend/authenticator/PRD.md`:
- Around line 621-623: The Login section heading in the PRD markdown is skipping
a level and should be aligned with the surrounding section structure. Update the
`Login` heading in the relevant markdown block from `####` to `###` so it
matches the `##` parent section and keeps the TOC/anchors consistent.
In `@docs/components/backend/gateway/DESIGN.md`:
- Around line 81-85: The gateway readiness is currently coupled to the
authenticator dependency, which can cause transient auth outages to mark the
gateway unready. Update the readiness behavior described in the gateway design
so the gateway probe stays local and independent, and move the authenticator
check into a separate health check or dependency probe; use the existing gateway
deployment/readiness description and the authenticator `/ready` reference to
locate the affected text.
- Around line 268-271: The gateway cache behavior needs to account for token
rotation because the cache key is the raw session-token cookie value, which can
keep authorizing a retired cookie until the TTL expires. Update the DESIGN.md
guidance around the cache TTL/cache key and revocation staleness to add a
refresh/rotation invalidation strategy or a versioned cache key tied to the
authenticator’s token rotation, and tighten the TTL coupling so stale cookies
cannot remain valid for the full cache window.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 64691ff6-71e5-4ed7-99b0-9dfbffeee1a0
📒 Files selected for processing (12)
.cf-studio/config/artifacts.tomldocs/components/backend/api-gateway/DESIGN.mddocs/components/backend/api-gateway/PRD.mddocs/components/backend/api-gateway/bff/DESIGN.mddocs/components/backend/api-gateway/bff/PRD.mddocs/components/backend/api-gateway/router/DESIGN.mddocs/components/backend/api-gateway/router/PRD.mddocs/components/backend/authenticator/DESIGN.mddocs/components/backend/authenticator/PRD.mddocs/components/backend/gateway/DESIGN.mddocs/components/backend/specs/DESIGN.mddocs/components/backend/specs/PRD.md
💤 Files with no reviewable changes (6)
- docs/components/backend/api-gateway/bff/PRD.md
- docs/components/backend/api-gateway/bff/DESIGN.md
- docs/components/backend/api-gateway/DESIGN.md
- docs/components/backend/api-gateway/router/PRD.md
- docs/components/backend/api-gateway/PRD.md
- docs/components/backend/api-gateway/router/DESIGN.md
…ate constraints Studio validation (now working after the Cypilot -> Constructor Studio migration) surfaced three deterministic issues: - authenticator/PRD.md: tenant-admin and oidc-provider actors were duplicate definitions of IDs owned by the parent backend PRD; now referenced instead of redefined - gateway/DESIGN.md: restructured to the required DESIGN template headings (Functional Drivers, NFR Allocation, Architecture Layers, Domain Model, API Contracts, Internal/External Dependencies, Database schemas & tables) and moved the topology ID under Technical Architecture (new Deployment Topology section) cfs validate --artifact now passes on all five touched artifacts; the repo-wide run reports only pre-existing errors in untouched files. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: Anton Zelenov <antonz@constructor.tech>
- authenticator/PRD.md (MD001 heading-increment): group section 8 use cases under '### 8.1 Browser Session Lifecycle' and '### 8.2 Service- to-Service Authentication' so headings increment ## -> ### -> #### (use-case names stay #### as the Studio PRD template mandates and cfs requires; the parent backend PRD uses the same grouping pattern). - gateway/DESIGN.md (readiness anti-pattern): decouple gateway readiness from the authenticator. Readiness is now local (nginx workers + valid config); an authenticator blip no longer drains the fleet or the exchange cache. Authenticator reachability moves to a separate /healthz/authenticator dependency probe for alerting only. Updated the NFR-allocation row, internal-deps row, failure table, deployment- topology probes, and API-contracts endpoint list. - gateway/DESIGN.md (cache vs token rotation): document that the token-keyed exchange cache extends a retired cookie's effective life from the 250 ms rotation grace to at most authz_cache_max_age (30 s) at that pod. Explained the bounds (session-linked JWT so revocation is unaffected; only benefits a stolen old cookie; consistent with the probabilistic theft-detection model) and the authz_cache_max_age=0 lever; documented why a purge-on-rotation hook is deliberately not added in v1. cfs validate/toc/check-language green on both artifacts. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: Anton Zelenov <antonz@constructor.tech>
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
docs/components/backend/gateway/DESIGN.md (1)
391-402: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winClarify the cache key wording.
Lines 392 and 398-400 describe two different cache keys: the raw session-token cookie value vs. a stable
session_id. That makes the rotation/staleness contract ambiguous for implementers. Please align the wording so the document states one model consistently.♻️ Suggested wording fix
- The cached artifact is the session-linked JWT (keyed by the stable session_id, not the token); + The cached artifact is the session-linked JWT, but the cache key remains the raw session-token cookie value;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@docs/components/backend/gateway/DESIGN.md` around lines 391 - 402, The cache key description is inconsistent: one place says the key is the raw session-token cookie value, while the rotation section says the cached JWT is keyed by stable session_id, which makes the contract ambiguous. Update the wording in DESIGN.md so the cache key model is stated consistently across the cache TTL/key table and the “Cookie rotation and the cache” section, using the same symbol/term throughout (for example, the authenticator’s session-token cookie value or the stable session_id, but not both).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@docs/components/backend/gateway/DESIGN.md`:
- Around line 391-402: The cache key description is inconsistent: one place says
the key is the raw session-token cookie value, while the rotation section says
the cached JWT is keyed by stable session_id, which makes the contract
ambiguous. Update the wording in DESIGN.md so the cache key model is stated
consistently across the cache TTL/key table and the “Cookie rotation and the
cache” section, using the same symbol/term throughout (for example, the
authenticator’s session-token cookie value or the stable session_id, but not
both).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 75a7fee5-ea92-4ab4-a62f-e40e637106fb
📒 Files selected for processing (2)
docs/components/backend/authenticator/PRD.mddocs/components/backend/gateway/DESIGN.md
✅ Files skipped from review due to trivial changes (1)
- docs/components/backend/authenticator/PRD.md
Part of EPIC #1583 (nginx + authorization), step 01 of 11. Docs only -- no code changes.
Closes #1584.
What
docs/components/backend/api-gateway/spec tree (umbrella PRD/DESIGN,bff/,router/), per the decision document: the custom Rust Router is commodity work nginx does better; the BFF half survives as a standalone authenticator service.docs/components/backend/authenticator/PRD.md+DESIGN.md-- the authenticator gear:__Host-sidcookie as a rotating credential; stablesession_id(UUIDv7) as the session identity; gateway JWT minted at login, linked 1:1 to the session, reissued ahead of expiry (guaranteed 60 s travel margin)sub= person_id,tenants[](only tenant authority),roles(default["user"]),sid,iss/aud/iat/exp/jti-- supersedes DD-ROUTER-05/internal/authzexchange contract incl.Cache-Control: max-age = min(authz_cache_max_age, jwt_exp - now - 60 s), non-200 =no-storeasm:prefix (authenticator session management): token mapping with grace-TTL rotation (noswapkeys, no RENAME), linked JWT, indexes,idp_refresh_duescheduleinvalid_grant(all linked sessions die);offline_accessrequirement +no_refresh_token_policyPOST /internal/token, RFC 7523 assertions, gitops-reviewable registry,sub = service:<name>#[toolkit::gear], OperationBuilder, CanonicalError/RFC 9457,authenticator-sdk, SecurityContext claim alignmentdocs/components/backend/gateway/DESIGN.md-- the nginx (OpenResty) edge: ingress-orthogonal topology, route configurator (salvagedroutes.yamlschema minuswebsocket_max_lifetime_seconds), generated location hygiene block, subrequest contract, Lua exchange cache / UUIDv7 correlation ids / RFC 9457 error shaping, failure table, reload procedure.backend/specs/PRD.md+DESIGN.md): token-handler authentication model, architecture diagram + routing through the gateway, authenticator + gateway components, first-login and analytics-query sequences.cypilot/config/artifacts.toml: removed the four deleted artifacts, registered the three new ones.Salvage (per step instructions)
routes.yamlschema (router DESIGN 3.8), OIDC code+PKCE + session-fixation guard, logout incl. back-channel +jtireplay guard, CSRF, cookie attributes; DD-ROUTER-03/09/10 and DD-BFF-01/02/03/09 carried over; DD-ROUTER-05 and the "no IdP refresh in v1" carve-out recorded as superseded.Validation
cfs toc-- all touched artifacts up to date ("unchanged")cfs check-language-- no violationscfs validate --local-onlyreports "No artifacts found in registry" for this repo -- pre-existing cypilot issue, reproducible on untouched artifacts from main (e.g.analytics/DESIGN.md); the registry TOML parses fine (150 artifacts)where-usedsweep: no danglingcpt-insightspec-*references to removed IDs anywhere indocs/🤖 Generated with Claude Code
Summary by CodeRabbit