Skip to content

Commit d42ce38

Browse files
committed
5511: Change API-KEY permission to allow admin users only
1 parent 140605e commit d42ce38

File tree

2 files changed

+4
-19
lines changed

2 files changed

+4
-19
lines changed

backend/open_webui/routers/auths.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,15 +1107,7 @@ async def update_ldap_config(
11071107

11081108
# create api key
11091109
@router.post("/api_key", response_model=ApiKey)
1110-
async def generate_api_key(request: Request, user=Depends(get_current_user)):
1111-
if not request.app.state.config.ENABLE_API_KEYS or not has_permission(
1112-
user.id, "features.api_keys", request.app.state.config.USER_PERMISSIONS
1113-
):
1114-
raise HTTPException(
1115-
status_code=status.HTTP_403_FORBIDDEN,
1116-
detail=ERROR_MESSAGES.API_KEY_CREATION_NOT_ALLOWED,
1117-
)
1118-
1110+
async def generate_api_key(request: Request, user=Depends(get_admin_user)):
11191111
api_key = create_api_key()
11201112
success = Users.update_user_api_key_by_id(user.id, api_key)
11211113

@@ -1129,14 +1121,14 @@ async def generate_api_key(request: Request, user=Depends(get_current_user)):
11291121

11301122
# delete api key
11311123
@router.delete("/api_key", response_model=bool)
1132-
async def delete_api_key(user=Depends(get_current_user)):
1124+
async def delete_api_key(user=Depends(get_admin_user)):
11331125
success = Users.update_user_api_key_by_id(user.id, None)
11341126
return success
11351127

11361128

11371129
# get api key
11381130
@router.get("/api_key", response_model=ApiKey)
1139-
async def get_api_key(user=Depends(get_current_user)):
1131+
async def get_api_key(user=Depends(get_admin_user)):
11401132
api_key = Users.get_user_api_key_by_id(user.id)
11411133
if api_key:
11421134
return {

backend/open_webui/utils/auth.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -377,14 +377,7 @@ def get_current_user_by_api_key(request, api_key: str):
377377
detail=ERROR_MESSAGES.INVALID_TOKEN,
378378
)
379379

380-
if not request.state.enable_api_keys or (
381-
user.role != "admin"
382-
and not has_permission(
383-
user.id,
384-
"features.api_keys",
385-
request.app.state.config.USER_PERMISSIONS,
386-
)
387-
):
380+
if (user.role != "admin"):
388381
raise HTTPException(
389382
status.HTTP_403_FORBIDDEN, detail=ERROR_MESSAGES.API_KEY_NOT_ALLOWED
390383
)

0 commit comments

Comments
 (0)