-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve gateway auth issues troubleshooting (#1569)
If `dstack-gateway` experiences issues when checking authorization: - Log a more understandable error message - Send 5xx error code to the user
- Loading branch information
Showing
3 changed files
with
36 additions
and
33 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,20 +1,13 @@ | ||
from fastapi import APIRouter, Depends, HTTPException, Security | ||
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer | ||
from fastapi import APIRouter, Depends | ||
|
||
from dstack.gateway.core.auth import AuthProvider, get_auth | ||
from dstack.gateway.core.auth import access_to_project_required | ||
|
||
router = APIRouter() | ||
|
||
|
||
# TODO(egor-s): support Authorization header alternative for web browsers | ||
|
||
|
||
@router.get("/{project}") | ||
async def get_auth( | ||
project: str, | ||
token: HTTPAuthorizationCredentials = Security(HTTPBearer()), | ||
auth: AuthProvider = Depends(get_auth), | ||
): | ||
if await auth.has_access(project, token.credentials): | ||
return {"status": "ok"} | ||
raise HTTPException(status_code=403) | ||
@router.get("/{project}", dependencies=[Depends(access_to_project_required)]) | ||
async def get_auth(): | ||
return {"status": "ok"} |
This file contains 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
This file contains 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