forked from phoenix/litellm-mirror
fix(proxy_server.py): add 'admin' user to db (#6223)
* fix(proxy_server.py): add 'admin' user to db Fixes noisy error https://github.com/BerriAI/litellm/issues/6206 * fix(proxy_server.py): return correct 'userID' for `/login` endpoint Fixes https://github.com/BerriAI/litellm/issues/6206
This commit is contained in:
parent
c7bf693aff
commit
199896f912
2 changed files with 19 additions and 19 deletions
|
@ -2935,21 +2935,21 @@ async def startup_event(): # noqa: PLR0915
|
||||||
verbose_proxy_logger.info("Skipping writing master key hash to db")
|
verbose_proxy_logger.info("Skipping writing master key hash to db")
|
||||||
else:
|
else:
|
||||||
# add master key to db
|
# add master key to db
|
||||||
asyncio.create_task(
|
# add 'admin' user to db. Fixes https://github.com/BerriAI/litellm/issues/6206
|
||||||
generate_key_helper_fn(
|
task_1 = generate_key_helper_fn(
|
||||||
request_type="user",
|
request_type="user",
|
||||||
duration=None,
|
duration=None,
|
||||||
models=[],
|
models=[],
|
||||||
aliases={},
|
aliases={},
|
||||||
config={},
|
config={},
|
||||||
spend=0,
|
spend=0,
|
||||||
token=master_key,
|
token=master_key,
|
||||||
user_id=litellm_proxy_admin_name,
|
user_id=litellm_proxy_admin_name,
|
||||||
user_role=LitellmUserRoles.PROXY_ADMIN,
|
user_role=LitellmUserRoles.PROXY_ADMIN,
|
||||||
query_type="update_data",
|
query_type="update_data",
|
||||||
update_key_values={"user_role": LitellmUserRoles.PROXY_ADMIN},
|
update_key_values={"user_role": LitellmUserRoles.PROXY_ADMIN},
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
asyncio.create_task(task_1)
|
||||||
|
|
||||||
if prisma_client is not None and litellm.max_budget > 0:
|
if prisma_client is not None and litellm.max_budget > 0:
|
||||||
if litellm.budget_duration is None:
|
if litellm.budget_duration is None:
|
||||||
|
@ -8107,16 +8107,16 @@ async def login(request: Request): # noqa: PLR0915
|
||||||
):
|
):
|
||||||
# Non SSO -> If user is using UI_USERNAME and UI_PASSWORD they are Proxy admin
|
# Non SSO -> If user is using UI_USERNAME and UI_PASSWORD they are Proxy admin
|
||||||
user_role = LitellmUserRoles.PROXY_ADMIN
|
user_role = LitellmUserRoles.PROXY_ADMIN
|
||||||
user_id = username
|
user_id = litellm_proxy_admin_name
|
||||||
|
|
||||||
# we want the key created to have PROXY_ADMIN_PERMISSIONS
|
# we want the key created to have PROXY_ADMIN_PERMISSIONS
|
||||||
key_user_id = litellm_proxy_admin_name
|
key_user_id = litellm_proxy_admin_name
|
||||||
if (
|
if (
|
||||||
os.getenv("PROXY_ADMIN_ID", None) is not None
|
os.getenv("PROXY_ADMIN_ID", None) is not None
|
||||||
and os.environ["PROXY_ADMIN_ID"] == user_id
|
and os.environ["PROXY_ADMIN_ID"] == user_id
|
||||||
) or user_id == "admin":
|
) or user_id == litellm_proxy_admin_name:
|
||||||
# checks if user is admin
|
# checks if user is admin
|
||||||
key_user_id = os.getenv("PROXY_ADMIN_ID", "default_user_id")
|
key_user_id = os.getenv("PROXY_ADMIN_ID", litellm_proxy_admin_name)
|
||||||
|
|
||||||
# Admin is Authe'd in - generate key for the UI to access Proxy
|
# Admin is Authe'd in - generate key for the UI to access Proxy
|
||||||
|
|
||||||
|
@ -8161,7 +8161,7 @@ async def login(request: Request): # noqa: PLR0915
|
||||||
{
|
{
|
||||||
"user_id": user_id,
|
"user_id": user_id,
|
||||||
"key": key,
|
"key": key,
|
||||||
"user_email": user_id,
|
"user_email": None,
|
||||||
"user_role": user_role, # this is the path without sso - we can assume only admins will use this
|
"user_role": user_role, # this is the path without sso - we can assume only admins will use this
|
||||||
"login_method": "username_password",
|
"login_method": "username_password",
|
||||||
"premium_user": premium_user,
|
"premium_user": premium_user,
|
||||||
|
|
|
@ -128,7 +128,7 @@ const Navbar: React.FC<NavbarProps> = ({
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Dropdown menu={{ items }}>
|
<Dropdown menu={{ items }}>
|
||||||
<Space>{userEmail}</Space>
|
<Space>{userEmail ? userEmail : userRole}</Space>
|
||||||
</Dropdown>
|
</Dropdown>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue