feat(BA-2825): Implement JWT authentication module for GraphQL Federation#6410
Merged
Conversation
…tion This commit implements a JWT-based authentication system to support GraphQL Federation with Hive Router. The traditional HMAC signature verification fails when Hive Router splits queries into subgraph requests with different request bodies. Key components: - JWTConfig: Pydantic-based configuration with validation - JWTSigner: Token generation from authenticated user context - JWTValidator: Token validation and claims extraction - JWTClaims/JWTUserContext: Structured dataclasses for type safety - Custom exceptions inheriting from BackendAIError Design decisions: - Algorithm: HS256 (symmetric) for simplicity - Token TTL: 15 minutes (configurable) - Custom header: X-BackendAI-Token (avoids conflict with appproxy) - No replay attack prevention (internal network, short TTL) - Stateless validation in manager (no Redis dependency) The module is placed in ai.backend.common for sharing between webserver (token generation) and manager (token validation). Related: BA-2824 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR implements a JWT-based authentication module to support GraphQL Federation with Hive Router, replacing traditional HMAC signature verification which fails when Hive Router splits queries into subgraph requests.
Key Changes:
- Introduces
JWTConfig,JWTSigner,JWTValidatorclasses for token generation and validation - Adds
JWTClaimsandJWTUserContextdataclasses for type-safe data handling - Implements custom JWT exceptions inheriting from
BackendAIError
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/ai/backend/common/jwt/__init__.py |
Module entry point with exports and usage documentation |
src/ai/backend/common/jwt/config.py |
Pydantic-based JWT configuration with validation |
src/ai/backend/common/jwt/exceptions.py |
Custom JWT exception hierarchy |
src/ai/backend/common/jwt/signer.py |
Token generation from authenticated user context |
src/ai/backend/common/jwt/validator.py |
Token validation and claims extraction |
src/ai/backend/common/jwt/types.py |
Dataclasses for JWT claims and user context |
tests/common/jwt/BUILD |
Build configuration for test suite |
tests/common/jwt/test_signer.py |
Comprehensive tests for JWT signer |
tests/common/jwt/test_types.py |
Tests for JWT types and dataclasses |
tests/common/jwt/test_validator.py |
Tests for JWT validator |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
jopemachine
pushed a commit
that referenced
this pull request
Oct 30, 2025
…tion (#6410) Co-authored-by: Claude <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.
This commit implements a JWT-based authentication system to support GraphQL Federation with Hive Router. The traditional HMAC signature verification fails when Hive Router splits queries into subgraph requests with different request bodies.
Key components:
Design decisions:
The module is placed in ai.backend.common for sharing between webserver (token generation) and manager (token validation).
resolves #6405 (BA-2825)
Checklist: (if applicable)
ai.backend.testdocsdirectory