Litellm encrypt admin UI values (#12675)

* build: move build_and_test to use prisma migrate

* feat(proxy_setting_endpoints.py): encrypt env var before storing in db

Ensures env var can be read when loaded in from DB

Fixes issue when trying to add SSO from admin UI

* test: update tests
This commit is contained in:
Krish Dholakia 2025-07-17 22:24:58 -07:00 committed by GitHub
parent 4d97cd66fb
commit b515d051ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 4 deletions

View File

@ -471,6 +471,7 @@ async def update_sso_settings(sso_config: SSOConfig):
# Update environment variables in config and in memory
sso_data = sso_config.model_dump(exclude_none=True)
mapped_env_vars = {}
for field_name, value in sso_data.items():
if field_name == "user_email" and value is not None:
@ -483,11 +484,17 @@ async def update_sso_settings(sso_config: SSOConfig):
env_var_name = env_var_mapping[field_name]
# Update in config
config["environment_variables"][env_var_name] = value
mapped_env_vars[env_var_name] = value
# Update in runtime environment
os.environ[env_var_name] = value
stored_config = config
if len(mapped_env_vars) > 0:
stored_config["environment_variables"] = proxy_config._encrypt_env_variables(
environment_variables=mapped_env_vars
)
# Save the updated config
await proxy_config.save_config(new_config=config)
await proxy_config.save_config(new_config=stored_config)
return {
"message": "SSO settings updated successfully",

View File

@ -267,7 +267,8 @@ class TestProxySettingEndpoints:
assert "google_client_id" in data["field_schema"]["properties"]
assert "description" in data["field_schema"]["properties"]["google_client_id"]
def test_update_sso_settings(self, mock_proxy_config, mock_auth):
def test_update_sso_settings(self, mock_proxy_config, mock_auth, monkeypatch):
monkeypatch.setenv("LITELLM_SALT_KEY", "test_salt_key")
"""Test updating the SSO settings"""
# New SSO settings to update
new_sso_settings = {
@ -308,11 +309,11 @@ class TestProxySettingEndpoints:
updated_config = mock_proxy_config["config"]
assert (
updated_config["environment_variables"]["GOOGLE_CLIENT_ID"]
== new_sso_settings["google_client_id"]
!= new_sso_settings["google_client_id"]
)
assert (
updated_config["environment_variables"]["GOOGLE_CLIENT_SECRET"]
== new_sso_settings["google_client_secret"]
!= new_sso_settings["google_client_secret"]
)
assert (
updated_config["general_settings"]["proxy_admin_email"]