-
Notifications
You must be signed in to change notification settings - Fork 752
feat(auth): configure WebSocket identity credentials #2196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rapids-bot
merged 2 commits into
NVIDIA:develop
from
ericevans-nv:feat/websocket-identity-credentials
Aug 31, 2026
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
2 changes: 2 additions & 0 deletions
2
packages/nvidia_nat_core/src/nat/authentication/jwt/__init__.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 |
44 changes: 44 additions & 0 deletions
44
packages/nvidia_nat_core/src/nat/authentication/jwt/jwt_auth_provider.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| """Named JWT identity verification provider.""" | ||
|
|
||
| from nat.authentication.credential_validator.bearer_token_validator import BearerTokenValidator | ||
| from nat.authentication.interfaces import AuthProviderBase | ||
| from nat.authentication.jwt.jwt_auth_provider_config import JwtAuthProviderConfig | ||
| from nat.data_models.authentication import AuthResult | ||
| from nat.data_models.authentication import TokenValidationResult | ||
|
|
||
|
|
||
| class JwtAuthProvider(AuthProviderBase[JwtAuthProviderConfig]): | ||
| """Validate inbound JWTs using a named issuer policy.""" | ||
|
|
||
| def __init__(self, config: JwtAuthProviderConfig) -> None: | ||
| super().__init__(config) | ||
| self._validator = BearerTokenValidator( | ||
| issuer=config.issuer_url, | ||
| audience=config.audience, | ||
| jwks_uri=config.jwks_uri, | ||
| scopes=config.scopes, | ||
| timeout=config.timeout, | ||
| leeway=config.leeway, | ||
| ) | ||
|
|
||
| async def verify(self, token: str) -> TokenValidationResult: | ||
| """Verify a JWT against this provider's configured trust policy.""" | ||
| return await self._validator.verify(token) | ||
|
|
||
| @property | ||
| def validator(self) -> BearerTokenValidator: | ||
| """Return the cached validator used by this named provider.""" | ||
| return self._validator | ||
|
|
||
| async def authenticate(self, user_id: str | None = None, **kwargs) -> AuthResult: | ||
| """Validate the supplied ``token`` through the authentication-provider interface.""" | ||
| token = kwargs.get("token") | ||
| if not isinstance(token, str) or not token: | ||
| raise ValueError("JWT authentication requires a token") | ||
|
|
||
| result = await self.verify(token) | ||
| if not result.active: | ||
| raise ValueError("JWT verification failed") | ||
| return AuthResult(raw=result.model_dump()) |
30 changes: 30 additions & 0 deletions
30
packages/nvidia_nat_core/src/nat/authentication/jwt/jwt_auth_provider_config.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| """Configuration for validating inbound JWT identity credentials.""" | ||
|
|
||
| from urllib.parse import urlparse | ||
|
|
||
| from pydantic import Field | ||
| from pydantic import field_validator | ||
|
|
||
| from nat.data_models.authentication import AuthProviderBaseConfig | ||
|
|
||
|
|
||
| class JwtAuthProviderConfig(AuthProviderBaseConfig, name="jwt"): | ||
| """Named JWT verification policy for inbound identity credentials.""" | ||
|
|
||
| issuer_url: str = Field(description="Expected JWT issuer claim.") | ||
| jwks_uri: str = Field(description="Endpoint containing trusted public keys for signature verification.") | ||
| audience: str = Field(description="Expected JWT audience claim.") | ||
| scopes: list[str] = Field(default_factory=list, description="Scopes required in a verified JWT.") | ||
| timeout: float = Field(default=10.0, gt=0, description="HTTP timeout for JWKS requests.") | ||
| leeway: int = Field(default=60, ge=0, description="Clock-skew allowance for JWT time claims, in seconds.") | ||
|
|
||
| @field_validator("issuer_url", "jwks_uri") | ||
| @classmethod | ||
| def require_secure_url(cls, value: str, info) -> str: | ||
|
ericevans-nv marked this conversation as resolved.
|
||
| parsed = urlparse(value) | ||
| is_local_http = parsed.scheme == "http" and parsed.hostname in {"localhost", "127.0.0.1", "::1"} | ||
| if not parsed.netloc or (parsed.scheme != "https" and not is_local_http): | ||
| raise ValueError(f"{info.field_name} must use HTTPS (HTTP is allowed only for localhost)") | ||
| return value | ||
13 changes: 13 additions & 0 deletions
13
packages/nvidia_nat_core/src/nat/authentication/jwt/register.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| from nat.authentication.jwt.jwt_auth_provider_config import JwtAuthProviderConfig | ||
| from nat.builder.builder import Builder | ||
| from nat.cli.register_workflow import register_auth_provider | ||
|
|
||
|
|
||
| @register_auth_provider(config_type=JwtAuthProviderConfig) | ||
| async def jwt_auth_provider(config: JwtAuthProviderConfig, builder: Builder): | ||
| from nat.authentication.jwt.jwt_auth_provider import JwtAuthProvider | ||
|
|
||
| yield JwtAuthProvider(config) |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.