-
Notifications
You must be signed in to change notification settings - Fork 51
LCORE-287: update documentation for authorized endpoint to align with openshift #505
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -180,7 +180,7 @@ async def query_endpoint_handler( | |
| # log Llama Stack configuration | ||
| logger.info("Llama stack config: %s", configuration.llama_stack_configuration) | ||
|
|
||
| user_id, _, token = auth | ||
| user_id, _, _, token = auth | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainAuthTuple unpack updated to 4-tuple — consider self-documenting placeholders. Using named throwaways improves readability when the tuple grows. - user_id, _, _, token = auth
+ user_id, _username, _skip_userid_check, token = authRun to catch any remaining 3-item unpacking of 🏁 Script executed: #!/bin/bash
# 3-item unpacks of `auth`
rg -nP --type=py '\b([A-Za-z_][A-Za-z0-9_]*\s*,\s*){2}[A-Za-z_][A-Za-z0-9_]*\s*=\s*auth\b' src/
# 4-item unpacks of `auth` (expected)
rg -nP --type=py '\b([A-Za-z_][A-Za-z0-9_]*\s*,\s*){3}[A-Za-z_][A-Za-z0-9_]*\s*=\s*auth\b' src/Length of output: 1261 Unpack user_id, _user_name, _skip_userid_check, token = authApply this change at:
🤖 Prompt for AI Agents |
||
|
|
||
| user_conversation: UserConversation | None = None | ||
| if query_request.conversation_id: | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,7 +11,6 @@ | |||||||||
| from kubernetes.config import ConfigException | ||||||||||
|
|
||||||||||
| from configuration import configuration | ||||||||||
| from auth.utils import extract_user_token | ||||||||||
| from auth.interface import AuthInterface | ||||||||||
| from constants import DEFAULT_VIRTUAL_PATH | ||||||||||
|
|
||||||||||
|
|
@@ -227,18 +226,33 @@ class K8SAuthDependency(AuthInterface): # pylint: disable=too-few-public-method | |||||||||
| def __init__(self, virtual_path: str = DEFAULT_VIRTUAL_PATH) -> None: | ||||||||||
| """Initialize the required allowed paths for authorization checks.""" | ||||||||||
| self.virtual_path = virtual_path | ||||||||||
| self.skip_userid_check = False | ||||||||||
|
|
||||||||||
| async def __call__(self, request: Request) -> tuple[str, str, str]: | ||||||||||
| async def __call__(self, request: Request) -> tuple[str, str, bool, str]: | ||||||||||
| """Validate FastAPI Requests for authentication and authorization. | ||||||||||
|
|
||||||||||
| Args: | ||||||||||
| request: The FastAPI request object. | ||||||||||
|
|
||||||||||
| Returns: | ||||||||||
| The user's UID and username if authentication and authorization succeed | ||||||||||
| user_id check is skipped with noop auth to allow consumers provide user_id | ||||||||||
| user_id check should never be skipped with K8s authentication | ||||||||||
| If user_id check should be skipped - always return False for k8s | ||||||||||
| User's token | ||||||||||
| """ | ||||||||||
| token = extract_user_token(request.headers) | ||||||||||
| authorization_header = request.headers.get("Authorization") | ||||||||||
| if not authorization_header: | ||||||||||
| raise HTTPException( | ||||||||||
| status_code=401, detail="Unauthorized: No auth header found" | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| token = _extract_bearer_token(authorization_header) | ||||||||||
| if not token: | ||||||||||
| raise HTTPException( | ||||||||||
| status_code=401, | ||||||||||
| detail="Unauthorized: Bearer token not found or invalid", | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| user_info = get_user_info(token) | ||||||||||
| if user_info is None: | ||||||||||
| raise HTTPException( | ||||||||||
|
|
@@ -267,4 +281,9 @@ async def __call__(self, request: Request) -> tuple[str, str, str]: | |||||||||
| logger.error("API exception during SubjectAccessReview: %s", e) | ||||||||||
| raise HTTPException(status_code=403, detail="Internal server error") from e | ||||||||||
|
|
||||||||||
|
Comment on lines
281
to
283
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 403 with “Internal server error” message is inconsistent; use 500 On SAR ApiException, respond 500 to reflect server failure. - raise HTTPException(status_code=403, detail="Internal server error") from e
+ raise HTTPException(status_code=500, detail="Internal server error") from e📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
| return user_info.user.uid, user_info.user.username, token | ||||||||||
| return ( | ||||||||||
| user_info.user.uid, | ||||||||||
| user_info.user.username, | ||||||||||
| self.skip_userid_check, | ||||||||||
| token, | ||||||||||
| ) | ||||||||||
|
Comment on lines
+284
to
+289
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reconsider returning the raw K8s token to downstream The 4th tuple element is now the bearer token. Downstream code currently forwards it to MCP servers by default when no Options:
|
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -307,6 +307,7 @@ class AuthorizedResponse(BaseModel): | |
| Attributes: | ||
| user_id: The ID of the logged in user. | ||
| username: The name of the logged in user. | ||
| skip_userid_check: Whether to skip the user ID check. | ||
| """ | ||
|
|
||
| user_id: str = Field( | ||
|
|
@@ -319,6 +320,11 @@ class AuthorizedResponse(BaseModel): | |
| description="User name", | ||
| examples=["John Doe", "Adam Smith"], | ||
| ) | ||
| skip_userid_check: bool = Field( | ||
| ..., | ||
| description="Whether to skip the user ID check", | ||
| examples=[True, False], | ||
| ) | ||
|
Comment on lines
+323
to
+327
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainVerify all producers now set skip_userid_check Guard against partial updates by scanning for missing field in AuthorizedResponse constructors and lingering 3-tuple auth usage. 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "Calls to AuthorizedResponse potentially missing skip_userid_check:"
# List all constructor calls and filter out those that already mention skip_userid_check
rg -n 'AuthorizedResponse\s*\(' | rg -v 'skip_userid_check'
echo
echo "Possible 3-tuple auth destructuring or construction:"
# Common patterns of 3-elem destructure from auth
rg -nP '\b([\w_]+\s*,\s*[\w_]+\s*,\s*[\w_]+)\s*=\s*auth\b' -g '!**/node_modules/**'
# 3-elem tuples passed as auth=(...)
rg -nP r'auth\s*=\s*\([^,()]+,\s*[^,()]+,\s*[^,()]+\)' -g '!**/node_modules/**'Length of output: 1526 Include
🤖 Prompt for AI Agents |
||
|
|
||
| # provides examples for /docs endpoint | ||
| model_config = { | ||
|
|
@@ -327,6 +333,7 @@ class AuthorizedResponse(BaseModel): | |
| { | ||
| "user_id": "123e4567-e89b-12d3-a456-426614174000", | ||
| "username": "user1", | ||
| "skip_userid_check": False, | ||
| } | ||
| ] | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix missing spaces in concatenated doc strings (user-facing text).
Adjacent string literals concatenate without spaces; current text renders “noop andnoop-with-token” and “thek8s”.
📝 Committable suggestion
🤖 Prompt for AI Agents