Repository navigation
feat(edgeauth): verify guard's identity JWT in Go and TypeScript (COR-1076) - #6
Merged
malpou merged 4 commits intoNov 18, 2026
Conversation
This was referenced Oct 30, 2026
…-1076) edgeauth verifies the x-bastion-identity JWT guard sends upstream (ES256, typ bastion-id+jwt, iss bastion, aud in the app's hosts, exp/iat with 10 s leeway) against guard's JWKS, fetched lazily, cached 5 min and refetched for an unknown kid at most once per 30 s. Middleware puts the identity in the context, answers 401 for an invalid token and 503 when the keys are unreachable; RequireIdentity and RequireRole refuse anonymous and unauthorised callers. edgeauthtest mints identities for app tests. @metsaapp/edgeauth is the TypeScript twin on jose, installable from this repository by tag. Both run the conformance vectors in edgeauth/testdata/vectors.json.
Guard sends x-bastion-identity once. Middleware read the first value with Header.Get, so a second copy that got past the edge went unnoticed. It now answers 401 and logs it, the same as an invalid token. The TypeScript helper already refuses it, because Headers joins the values into one string that does not parse.
…perty test FuzzVerify and FuzzParseJWKS cover the token and JWKS parsers. A verified token must carry the signed part of a valid vector, and a kept JWKS key must be a P-256 point under a kid. TestGuardIssuedToken builds keys, JWKS and claims the way guard's identity code does, including a bearer with a zero auth_time and a token from a key that is published but no longer active. The TypeScript property test refuses 3000 seeded mutations of the vectors.
GitHub Actions CI is off, so the edgeauth-ts job in ci.yml never runs. check.sh now runs the same steps: npm ci, the jose range check, types, a committed dist that matches the source, and vitest under Node and Bun. The disabled job moves to ubuntu-24.04 like the others.
malpou
force-pushed
the
malthe/cor-1076-shared-identity-verifier-platform-kit-edgeauth-and-a-ts
branch
from
November 18, 2026 09:02
338c115 to
4f993d0
Compare
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.
Summary
The shared verifier for guard's identity JWT (contract COR-1073 §2, §3, §10), in Go and TypeScript, with conformance vectors both run.
edgeauth/:Verifierwith ES256 only,typbastion-id+jwt (compared the RFC 7515 / jose way: case-insensitive,application/optional), a knownkid,issbastion,audinConfig.Audiences,exp/iat(andnbfwhen present) with 10 s leeway,subrequired. The JWKS is fetched lazily (never inNew) and cached 5 min. An unknown kid triggers at most one refetch per 30 s, and fetches are single-flight. A failed fetch is remembered for 5 s, and keys that were cached before still verify during an outage. go-jose v4 does the JWS parsing and signature check (it was already in the module graph); the claim rules are written out by hand so they match the TS side exactly.Middleware: no header → anonymous.ErrInvalid→ 401, logged throughWithLogger.ErrUnavailable→ 503. Bodies are plain text and never echo the token.RequireIdentity,RequireRole(any of; 401/403),FromContext/ContextWith,Identity.HasRole/HasAnyRole.edgeauth/edgeauthtest:NewIssuer(t)(in-memory P-256 key, httptest JWKS closed byt.Cleanup),Config,Mint,MintWith(id, aud, func(*Claims))for expired or wrong-aud tokens,Sign(aud =r.Host, lower case, no port).edgeauth/testdata/vectors.json: 32 cases generated bygo generate ./edgeauth(internal/vectorgen). The JWS is assembled by hand with deterministic RFC 6979 signatures, and a test fails when the committed file is stale. Cases: valid session/bearer, empty/absent roles, leeway edges for exp and iat, future iat/nbf, wrong/upper-case aud, aud array, wrong iss, HS256 key-confusion, alg none, wrong/missing typ, unknown/missing kid, foreign-key signature, DER signature, tampered payload, wrong claim types, missing sub/exp/iat, a non-JWS, JWKS unreachable → unavailable.ts/edgeauth/+ rootpackage.json(@metsaapp/edgeauth):createVerifier({jwksUrl?, audiences, now?})→{verify, fromHeaders}, built on jose (createRemoteJWKSetwith cacheMaxAge 5 min, cooldown 30 s, timeout 5 s;jwtVerifywith ES256, typ, issuer, audience, clockTolerance 10, plus the iat-not-ahead check jose skips). Errors areEdgeAuthInvalid/EdgeAuthUnavailable.scripts/check.sh(CI is off) and the disabled CI jobedgeauth-ts: runnpm ci, checks the jose ranges agree, type-checks, checks the committeddistmatches the source, then runs vitest under Node and under Bun.PLATFORM_KIT_EDGEAUTH_*added to the runtime contract's variables.API additions beyond the contract (nothing renamed)
ConfigFromEnv(),ErrConfig,WithLogger, constsIssuer,TokenType,DefaultJWKSURL,Leeway,SourceSession/SourceBearer;edgeauthtest.MintWith,Claims,JWKSURL(),KeyID,Lifetime.NewIssuertakestesting.TB.RequireRole()with no roles behaves likeRequireIdentity. Interpretation: "iat not more than 60 s ahead" is implemented as iat ≤ now + 10 s leeway (guard sets iat = now).Packaging decisions
dist: Bun and pnpm do not run lifecycle scripts of git dependencies, so apreparebuild is unreliable. Bun imports the TS source through thebunexport condition. Node and bundlers getdist/index.js+.d.ts.filesis limited tots/edgeauthsrc/dist. I installed this commit withnpm install @metsaapp/edgeauth@git+file://…#<sha>andbun addand imported it under both runtimes.ts/edgeauth/package.json, lockfile, node_modules) stays underts/. A stubts/go.modkeeps./..., golangci-lint and the Go module zip out of it. The rootpackage.jsonhas no devDependencies.package.jsonversionis inextra-files, so it bumps with each Go release. The release type staysgo.Test evidence
go build ./... && go vet ./... && go test -race ./...: ok (edgeauth, natsclient, runtime)go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.11.3 run: 0 issuesnpm run check && npm run typecheck && npm run build && npm test: 37 passed.bun --bun x vitest run: 37 passed. dist matches the source.Apps pin a pseudo-version of this branch's head until v0.3.0 is out (
go get github.com/MetsaApp/platform-kit@4f993d0f2e50). On merge, release-please opens the v0.3.0 release PR.Rebased 2026-11-18
Replayed the one commit onto main at f7717b9 with no conflicts; the only overlap was ci.yml, where the disabled
edgeauth-tsjob now runs on ubuntu-24.04 like the others. Three commits on top:x-bastion-identityheaders,Middlewareverified the first and ignored the second. It now answers 401. The new case inTestMiddlewarefails on the old code.FuzzVerify(a verified token must carry a valid vector's signed part) andFuzzParseJWKS(every kept key is a P-256 point under a kid), 3 minutes each with no failures: 820,205 and 895,360 executions.TestGuardIssuedTokensigns the way guard'scor-1074-1branch does: PKCS#8 PEM keys, every key published with alg ES256 and use sig, guard's claim struct withauth_timealways present. It covers a bearer with a zeroauth_timeand a token from a published key that is no longer active. A seeded TS property test refuses 3000 mutated tokens.scripts/check.shnow runs the ts/edgeauth steps, so the pre-push hook covers them.Tested:
scripts/check.shpasses (go build, vet, test -race, golangci-lint v2.11.3 with 0 issues, and 39 vitest tests under Node 24 and Bun 1.4).