Skip to content

feat(authn): validate OIDC callers with bounded JWKS staleness (#449) - #458

Merged
jhrozek merged 13 commits into
mainfrom
spike/authn-wiring
Aug 12, 2026
Merged

jhrozek merged 13 commits into
mainfrom
spike/authn-wiring

Conversation

@jhrozek

@jhrozek jhrozek commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Closes #449.

Summary

Wires real OIDC caller-token validation at the gRPC and HTTP server boundaries, with a bounded JWKS staleness policy rather than indefinitely trusting a warm signing-key cache.

  • adds OIDC issuer, JWKS URI, audience, and max-JWKS-staleness operator configuration to mecated and mecak8s;
  • starts a single validator during service construction and fails closed when identity is configured incorrectly or cannot be verified;
  • maps unavailable identity material to HTTP 503 / gRPC Unavailable, separately from rejected credentials;
  • exercises the implementation against an in-cluster Dex issuer in the kind suite;
  • documents the operational IdP/JWKS trade-off, Kubernetes egress requirement, token-bearing TUI path, verified ownership/actor attribution, and an explicit token-free TUI negative check.

Manual verification

On a fresh kind cluster with Dex:

  • acquired an Alice ID token, connected with mecatui, and received a MockLLM reply;
  • verified that a TUI invocation without a token initially appeared to work because MECATL_AUTH_TOKEN is an intentional CLI fallback;
  • removed that variable explicitly with env -u MECATL_AUTH_TOKEN; the first unauthenticated prompt was rejected before a model response;
  • inspected the authenticated session through the API and confirmed its saved verified owner.

Verification

  • git diff --check
  • fresh kind + Dex manual flow above
  • task generate was attempted after the user-doc change, but cannot fetch private github.com/stacklok/[email protected] in this environment. Its partially generated llms.txt was restored; CI should regenerate and validate the docs.

Relation to PR #430

PR #430 is the earlier Track-A attribution implementation for #367. Its own review notes correctly state that production OIDC validation was not yet wired. This PR is the follow-up implementation for #449 and deliberately does not claim to close #367.

@jhrozek
jhrozek requested a review from JAORMX August 11, 2026 20:45
@jhrozek
jhrozek force-pushed the spike/authn-wiring branch 2 times, most recently from 3f099b2 to 15cc736 Compare August 12, 2026 14:50
jhrozek and others added 13 commits August 12, 2026 17:14
Resolves the ship-blockers and hardening gaps from the post-merge review
of spike/authn-wiring:

- Reject --auth-token + --oidc-issuer together at startup instead of
  letting every request 401 (ValidateOIDCAuthToken).
- Preserve the originating caller's principal for the detached
  user-model review Stop hook (context.WithoutCancel instead of
  context.Background).
- Add a peer-keyed rejected-bearer rate limiter so invalid-token
  traffic can no longer bypass metering ahead of full JWT validation;
  context cancellation/deadlines pass through with native gRPC/HTTP
  statuses instead of consuming that budget.
- Reject duplicate gRPC authorization metadata instead of silently
  taking the first value.
- Register the startup model-catalog refresh as a syscaller root
  (RootModelCatalogRefresh).
- Pin that origin_session_id can never arrive over the wire.
- Clone the owner on the MetaLister listing path so a caller can't
  mutate the store's shared Principal through a listed row.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…ing docs

user-docs/ and docs/usage/mecated.md are operator-facing; naming the
delegated OIDC/JWT validator's module path and pinned version there
creates a doc/impl divergence liability with no reader benefit (the
ADRs and PRODUCTION-READINESS.md are the right place for that detail).
Describe the validator by behavior instead.

Also fixes a broken anchor in docs/tui.md — it pointed at a heading
that was never added to mecak8s.md; the caller-identity content
actually lives under mecated.md's Security & transport section.
Regenerated llms.txt (task docs:llms) to match.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…ine/session

Reusable, stdlib-only projection from an already-verified claim set to a
session.Principal, so any engine consumer that verifies its own bearer
tokens can derive attribution without reinventing the grant-type
heuristic. GrantTypeFromClaims moves verbatim from
internal/adapter/server/grant_type.go (deleted in the next commit).

Public API addition to engine/ (ADR 0037 process): engine/api/session.txt
regenerated, engine/CHANGELOG.md classified Added (minor). See ADR 0103.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Package internal/cliconfig/authnvalidator.go's toolhive-core/authn wrapper
as github.com/stacklok/mecatl/authn/oidc, its own Go module (own go.mod,
requires engine + toolhive-core), mirroring the provider/* pattern
(ADR 0093): a real dependency useful to some consumers, kept out of
engine's closure. internal/cliconfig becomes mecated/mecak8s's thin
composition layer over it, unchanged in behavior — same error-sentinel
mapping, same Close() lifecycle.

internal/adapter/server/grant_type.go is deleted (moved to
engine/session in the prior commit). Wires the new module into go.work,
CI (build/test/lint/vet/govulncheck), dependabot, and the Taskfile
lint/test/tidy/coverage tasks. See ADR 0103.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
The standalone GOWORK=off gate (test:authn-standalone) resolves
authn/oidc against the tagged engine release, not the local go.work
replace, so PrincipalFromClaims/GrantTypeFromClaims (this PR) need
engine/v0.10.0 cut and the requirement bumped to compile. Mirrors the
precedent in ea11126 for provider/anthropic.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Co-Authored-By: Claude Sonnet 5 <[email protected]>
@jhrozek
jhrozek force-pushed the spike/authn-wiring branch from 15cc736 to a1a5c23 Compare August 12, 2026 15:17
@jhrozek
jhrozek merged commit 6af357e into main Aug 12, 2026
16 checks passed
@jhrozek
jhrozek deleted the spike/authn-wiring branch August 12, 2026 15:30
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.

Bound JWKS staleness for caller-token validation A caller has an identity, and objects have owners

2 participants