LuxelEspañol

Luxel v0.2 · Guide · part 1 of 3

Luxel behind a gateway

Sprint 13.5 (ADR-065; preview, stage S1-A of 0.2.0-alpha.1). Use this when a gateway in front of your app signs people in: Envoy Gateway with OIDC, oauth2-proxy, Cloudflare Access or a similar proxy. The gateway runs the sign-in with your identity provider and forwards a JWT the provider issued. luxel-host verifies that JWT and turns it into a Luxel session. Your app has no sign-in screen of its own.

What is trusted is the provider's signature, never the gateway's headers. luxel-host checks each token against the provider's published keys (JWKS). X-User-*, X-Actor and similar headers are never read.

Supported combinations (stage S1-A, 0.2.0-alpha.1). Gateway identity works with complete (non-streamed) responses and the bundled session stores: createMemorySessionStore() and createPgSessionStore({ pool }). A host that asks for streamed pages does not start (LUXEL-M001, stage S1-B), nor does one with a delegated or third-party session store (LUXEL-M002, stage S1-C). See the support matrix.

How it works

browser ──► gateway (OIDC with the provider) ──► luxel-host ──► your handlers forwards the access token verifies it on every request, (Authorization: Bearer …) binds the session to its subject

On every request that uses a session (pages, state, events, sign-out), luxel-host:

  1. first applies the checks that cost nothing: the request must go to a route that uses a session (a page of the route table, a view's state by GET, an event, the sign-out route, a surface's manifest at a well-formed address), an event must pass every check the host makes from its headers alone (the page's origin, its CSRF and view token headers, Content-Type: application/json, a size within the limit), and the client's address must be within its rate limit. A request that fails them is answered without a session, and its token is not verified;
  2. reads the token from the configured header (sent once: two fields are refused);
  3. verifies it: the signature against the JWKS, the algorithm, iss, aud and/or azp, exp, nbf, iat, the required claims;
  4. resolves the session in the __Host- cookie, and then:
What arrivesWhat luxel-host does
A valid token, a session bound to the same subjectUses that session. A renewed token (the gateway refreshes tokens) keeps it
A valid token, no sessionOn a page or a view's state: calls your identityPrincipal(claims), asks the session store to open a session for that principal, sets the cookie. An event or the sign-out route never opens one
A valid token of another subject with a session's cookieEnds that session, answers 401
No tokenEnds a signed-in session; the request goes on as a visitor's (public views still work)
An invalid, expired or not-yet-valid tokenEnds the session, answers 401
The JWKS cannot be fetchedAnswers 503 to every request that passes the identity gate, from the failed fetch (or a set past its age that cannot be refreshed) until a fetch works (fails closed): pages, states, events, sign-out and surface manifests, with or without a token, visitors included. No session is opened, used or ended. Public files, /healthz, the favicon and static public views do not pass the gate and are served as usual

An event's session is checked once more after its body is read, before dispatch: if the session ended meanwhile (another request closed it) or the token expired, the event is refused and does not run. The adapters of @luxel-framework/server check it a last time inside the event's transaction, right before your handler (ViewEvent.sessionLive): a session closed by then rolls the transaction back and the event answers UNAUTHENTICATED. If you write your own adapter, declare checksSessionInTransaction: true on it and call event.sessionLive() inside the transaction that commits the event, as its last step before the commit, refusing with UNAUTHENTICATED (nothing committed) when it answers false. Under identity.mode: "gateway-jwt" luxel-host refuses to start with a hand-written adapter that does not declare it, and answers 500 to an accepted event of a declaring adapter whose ask never answered true (that 500 cannot undo what your adapter committed: the check inside your transaction is your adapter's job). With the PostgreSQL session store on the same database as your event store, export sessionsInEventTransaction = true from the bindings: the framework adapters then check the session inside the event's transaction with its row locked (FOR SHARE), so a close or a revocation cannot commit between that check and the event's commit. An event store you write yourself must declare callsBeforeCommit: true and call write's options.beforeCommit(tx) as its last statement before COMMIT (ADR-067): the framework makes its last session check there. Under gateway-jwt luxel-host refuses to start with an event store that does not declare it. A read event's check reads the session without a lock (its transaction may be READ ONLY).

One rule for every response: no byte that carries a session's data or a session cookie is written unless the full check (the token valid by the clock and against the key set, no outage, the session — signed in or visitor, new or existing — still live in the store) completed after the last await before that write. luxel-host enforces it in one place, the response gate (ADR-065 §24): every response of a request that passed the identity gate is checked at its head, whichever code wrote it; a refused one is replaced by the generic 401 or 503, which keeps the security headers of the response it replaces and nothing else of it.

A session the gate opens for a request (or a visitor session) is opened provisional: the store receives a deadline with the open (the host's clock plus 30 s; LUXEL_OPEN_DELIVERY_MS) and ends the session by itself at that deadline. Until it is confirmed, no request but the one that opened it can use it. The response that delivers it (a status below 400) is held whole while two things happen, in this order: the store's confirm removes the deadline (awaited for at most 5 s; LUXEL_OPEN_CONFIRM_MS), and the request is checked once more (its token, the key set, the session in the store). That check is the last one: only then are the head, with the cookie, and the body written, and nothing is asked of the store after that head. A revocation that lands after the last check applies to the next request.

If the confirmation fails, does not answer in time or answers anything but true or false, or if the last check refuses, the answer is the refusal itself (401 or 503), whole, with no cookie and no data, written after the session was closed again at the store (its abandon). The same holds for any other refusal, error or 429 of a request that had opened a session. A close the store does not acknowledge is retried, and the answer waits until the store acknowledges it or the deadline plus a clock margin (5 s; LUXEL_OPEN_CLOCK_MARGIN_MS) has passed, whichever comes first: never longer. By then a session that was never confirmed has ended by itself. One that the store had confirmed may still be there: it is logged as an orphan (luxel.identity.session.orphan or luxel.session.orphan, error), its id was sent to nobody, and no request ever uses it. The bundled stores (memory, PostgreSQL) mark every session opened this way until it is read after its confirmation, and their expiry sweep removes one still marked 30 minutes after its delivery deadline (the store option unusedMs). Every session that is delivered is read that way first (the check after the confirmation, before the head that carries its cookie), so the sweep never ends a delivered session, however long its cookie takes to come back. An orphan whose request was refused before that read lives at most the delivery lifetime plus unusedMs plus the time to the next sweep (about 31.5 minutes by default with the memory store, which sweeps every minute; with PostgreSQL, until the first purgeExpired() of your schedule after that), or less when it expires or its user is revoked first. One refused after that read (an outage or an expiry seen right after the store's answer, a client that left between that read and the head), and a PostgreSQL row written before the upgrade that added the mark, still end at their ordinary expiry (8 hours for a signed-in session) or when their user is revoked (GAPS.md). The costs: the first response of a session waits for the confirmation and one more read of the store before its first byte (not measured); while a store keeps failing abandon, a refusal is late by up to 35 s; and the hosts and a delegated backend must keep their clocks within the margin (GAPS.md; a host checks its clock against the session store's at start and is not ready until the skew is proven within the margin: Production).

A HEAD request never opens a session. A HEAD of a private page with a valid token and no session is answered like a request without a session; a HEAD of a public page gets the page's headers, without a cookie; a HEAD with a session's cookie is served with that session. A health check or a link checker that uses HEAD therefore leaves nothing in the session store.

No page is streamed under gateway identity: a host that asks for it does not start (LUXEL-M001), so every page is buffered, checked, then sent whole, and no store call follows its head. Streaming comes with stage S1-B (support matrix). A sign-out's answer is checked too: if the token stopped holding after the session ended, the answer is a refusal that carries only the clearing cookie. A client that leaves while its session is being opened gets that open undone, and nothing is admitted. A request that carries the gateway's token is checked before every write even when it has no Luxel session (a public form, a redirect). A response that would hold the request's token is refused with a 500 before any session cookie is added. Only a token the gate verified counts as the request's credential: the body and the headers app code supplies are checked for it before they leave, while the framework's own security headers (CSP, Trusted Types…) are never examined.

Static public views (static: true) and public files are the same for everyone, so luxel-host does not read the token for them.

Your handlers see ctx.session.userId, roles and displayName as usual. A server function never reads a request header: the principal comes from your mapping of the verified claims.

On a request that carried a valid token, ctx.session.identity also gives the token of that request: subject (sub), email (when the token has a string email claim), token (the raw access token, to call your own backends with it) and claims (every verified claim, frozen: locale, groups… are given to you; Luxel enforces none of them). It is read from each request, so after a refresh it is the new token; it is never kept in the session store, never logged, and a serialized session leaves it out. Never put the token in a state value, a page, a URL or a log.

A session opened for a request is only delivered if every check made after the store call still holds (the token unexpired, the key set usable, the session not revoked meanwhile). Otherwise that session is closed again before the answer, which is the refusal; a store error after the open closes it too (the answer is then 500). See ADR-065, "Decision (owner, 2026-12-04)".

Setup

1. luxel.config.ts

export default defineConfig({ // … identity: { mode: 'gateway-jwt', issuer: 'https://sso.example.com/realms/acme', authorizedParty: 'luxel-pilot', // the client id: the token's azp audience: 'account', // optional; Keycloak access tokens often carry aud "account" jwksUrl: 'https://sso.example.com/realms/acme/protocol/openid-connect/certs', tokenHeader: 'authorization', // the default }, });

luxel build writes identity into luxel.config.json as it is, after checking it field by field with the rules luxel-host applies when it starts: a value the host would refuse (an algorithm, a token header or a mode that is not one of those listed below, a claim name with a space, a number out of its range) fails the build with LUXEL-E024, and nothing is written. So a field with a fixed list of values never carries anything else into the build. The free-text fields (issuer, audience, authorizedParty, jwksUrl, the names in requiredClaims) are written as you give them: they are public names, so never put a secret in one. The build refuses a URL with credentials, a query or a fragment there, and it refuses process.env in luxel.config.ts (LUXEL-E054), but it cannot tell a secret from a name. luxel-host checks the block again when it starts (it knows whether it runs in production) and refuses to start on any problem. Both messages name the field and the rule, never a value.

FieldMeaningDefault and rules
mode'gateway-jwt'the only mode for now
issuerthe token's iss, compared exactlyrequired
audiencethe token's aud must hold one of these (a string or a list)optional
authorizedPartythe token's azp must be one of these (the client id)optional; give at least one of audience and authorizedParty. With both, both must match
jwksUrlthe provider's key set; set apart from issuer, so it can be an address inside your networkrequired; https in production (LUXEL_ENV=production) unless jwksHttpInCluster; no credentials, query or fragment (luxel build refuses them, so they never reach the build)
algorithmsallowed signature algorithmsDEFAULT_JWT_ALGORITHMS: RS256 and ES256. Any of JWT_ALGORITHMS (RS, PS and ES with 256, 384 or 512). Never none, never HS\*
clockSkewSecondstolerance on exp, nbf, iat30; 0–300
requiredClaimsclaim names every token must carrynone
tokenHeaderwhere the gateway puts the token (IDENTITY_TOKEN_HEADERS)'authorization' (Bearer), 'x-forwarded-access-token', 'cf-access-jwt-assertion'
jwksCacheSecondshow long a fetched key set is used600; 60–86 400
jwksMinRefreshSecondsleast time between two fetches for an unknown kid30; 1–3 600
Edit this page on GitHub

This page: 7.9 KB of JavaScript (Luxel's shared runtime), 0 KB from your app.

Measured when the site is built: the runtime files this page loads, compressed as they are sent.

Made by IntiOps. The Luxel 0.1.0 betas are on npm (0.1.0-beta.1, 0.1.0-beta.2), with an alpha of 0.2 (0.2.0-alpha.1): no external security review yet.