fix(hub): soften license gate to permissive when JWKS unavailable#62
Merged
Conversation
Root cause: GET /api/profile returned 402 in prod because the license gate
ran for every /api/* route, hit a stale cache, called validateLicenseKey
which then called verifyLicenseJwt -> jose's createRemoteJWKSet got a 404
from Keygen's JWKS endpoint, jose threw a non-mapped error, mapJoseError
fell through to TitaniumVerifyError('malformed', 'Unknown verify error: ...'),
and refreshLicense flipped the cached ACTIVE status to INVALID -> 402.
Two surgical fixes:
1. LICENSE_REQUIRED env flag (default true). When false, requireActiveLicense
short-circuits to next() and logs a one-shot warning. Escape hatch for
the JWKS-is-down period without redeploying schema.
2. refreshLicense now treats TitaniumVerifyError of kind 'network'/'malformed'
(or any message containing /jwks/i) as TRANSIENT: preserves cached status,
does NOT persist a flip to INVALID. Matches the existing TitaniumApiError
semantics ("decoupled-for-read: a healthy ACTIVE user must not be locked
out by a transient verify failure").
Tests: 15 existing license-gate cases still pass + 2 new cases covering the
permissive bypass and the JWKS-transient preservation. The 5 failing tests
in insert-run-started-at.test.ts are pre-existing on main (unrelated).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root cause
GET /api/profilereturned 402 in prod because:/api/*route (mounted globally inhub/src/index.ts).refreshLicense→validateLicenseKey→verifyLicenseJwt→ josecreateRemoteJWKSetfetches${KEYGEN_URL}/v1/accounts/{id}/.well-known/jwks.json→ 404.mapJoseErrorfalls through →TitaniumVerifyError('malformed', 'Unknown verify error: ...').refreshLicensecatches it → maps toINVALID→ persists → gate denies with 402.The Keygen JWKS 404 is a separate infra issue. This PR makes the gate resilient to that failure so identity/REST reads aren't gated by Keygen health.
Changes
LICENSE_REQUIREDenv flag (defaulttrue, setfalseto bypass). When false,requireActiveLicenseshort-circuits tonext()and logs a one-shot warning. Escape hatch for the JWKS-down period.Transient verify errors no longer flip cache to INVALID.
refreshLicensenow treatsTitaniumVerifyErrorof kindnetwork/malformed(or message matching/jwks/i) as transient: preserves cached status, does not persist. Matches existingTitaniumApiErrorsemantics — decoupled-for-read: a healthy ACTIVE user must not be locked out by a transient verify failure.Tests
LICENSE_REQUIRED=falsebypass + JWKS-unreachable preserves cached ACTIVE without persisting INVALID.insert-run-started-at.test.tsare pre-existing onmain(unrelated).Deploy plan
Set
LICENSE_REQUIRED=falsein Coolify env forapp.remo-code.comuntil Keygen JWKS path is sorted. Even without the env var, the transient-handling change alone prevents ACTIVE→INVALID flips going forward.🤖 Generated with Claude Code