Skip to content

feat(inboundauth): verify bearer JWTs against JWKS - #110

Merged
pavelanni merged 4 commits into
mainfrom
feature/inboundauth
Nov 6, 2026
Merged

pavelanni merged 4 commits into
mainfrom
feature/inboundauth

Conversation

@pavelanni

Copy link
Copy Markdown
Collaborator

Summary

Adds pkg/inboundauth, a standalone net/http middleware that authenticates callers itself because OpenShell bearer passthrough also admits token-less requests.

  • Verifies ES256/RS256 only; rejects none and HS* before key selection.
  • JWKS cache with unknown-kid refresh, rate-limited by MinRefreshInterval.
  • Checks signature, exp/nbf/iat with clock skew, iss, aud, scopes (scope or scp), and azp/client_id.
  • Deletes Authorization and stores verified claims in the request context.
  • Stable JSON deny codes per docs/dev/zero-trust/00-index.md; 401s carry WWW-Authenticate.
  • No internal/ imports, so it can be reused by an A2A adapter.

Library choice: github.com/lestrrat-go/jwx/v3 v3.4.0 — one dependency instead of two, 30 added dependency edges vs 40 for jwt/v5 + keyfunc, and explicit control over cache refresh for the rate-limit requirement. Rationale is in pkg/inboundauth/doc.go.

Test plan

  • make fmt lint test
  • go test -race ./pkg/inboundauth/ — 34 middleware rows plus JWKS refresh, rate-limit, unavailable, and error-body tests
  • go list -deps ./pkg/inboundauth | grep docsclaw/internal prints nothing
  • TestNoInternalImports enforces the isolation check in CI

🤖 Generated with Claude Code

Add the middleware configuration and its validation, and document the
library comparison that selects lestrrat-go/jwx/v3.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Pavel Anni <[email protected]>
…odes

Verify ES256/RS256 tokens against a rate-limited JWKS cache, enforce time,
issuer, audience, scope, and caller rules, strip the Authorization header,
and return a stable error code for every deny reason.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Pavel Anni <[email protected]>
Document the package threat model, deny codes, token-stripping guarantee,
and library choice, and add a compiling usage example plus a guard that the
package never imports internal/.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Pavel Anni <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 6, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

Release the key cache mutex before the network call and serialize
refreshes with an in-flight flag, so a slow or blocked JWKS fetch cannot
stall requests whose kid is already cached. Strip Authorization on exempt
paths, compare configured exempt entries verbatim, and document that a
token without kid is rejected even for a single-key JWKS.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Pavel Anni <[email protected]>
@pavelanni
pavelanni marked this pull request as ready for review November 6, 2026 23:38
@pavelanni
pavelanni merged commit cadc7d2 into main Nov 6, 2026
5 checks passed
@pavelanni
pavelanni deleted the feature/inboundauth branch November 6, 2026 23:38
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