diff --git a/src/phoenix/config.py b/src/phoenix/config.py index 90c58aef97..86592ff763 100644 --- a/src/phoenix/config.py +++ b/src/phoenix/config.py @@ -98,6 +98,12 @@ ENV_PHOENIX_ENABLE_AUTH = "PHOENIX_ENABLE_AUTH" ENV_PHOENIX_DISABLE_RATE_LIMIT = "PHOENIX_DISABLE_RATE_LIMIT" ENV_PHOENIX_SECRET = "PHOENIX_SECRET" +ENV_PHOENIX_DEFAULT_ADMIN_INITIAL_EMAIL = "PHOENIX_DEFAULT_ADMIN_INITIAL_EMAIL" +""" +The initial email for the default admin account, which defaults to ‘admin@localhost’ if not +explicitly set. Note that changing this value will have no effect if the default admin +record already exists in the database. +""" ENV_PHOENIX_DEFAULT_ADMIN_INITIAL_PASSWORD = "PHOENIX_DEFAULT_ADMIN_INITIAL_PASSWORD" """ The initial password for the default admin account, which defaults to ‘admin’ if not @@ -282,6 +288,12 @@ def get_env_phoenix_secret() -> Optional[str]: return phoenix_secret +def get_env_default_admin_initial_email() -> str: + from phoenix.auth import DEFAULT_ADMIN_EMAIL + + return os.environ.get(ENV_PHOENIX_DEFAULT_ADMIN_INITIAL_EMAIL) or DEFAULT_ADMIN_EMAIL + + def get_env_default_admin_initial_password() -> str: from phoenix.auth import DEFAULT_ADMIN_PASSWORD diff --git a/src/phoenix/db/facilitator.py b/src/phoenix/db/facilitator.py index 6321141713..a6c39a8158 100644 --- a/src/phoenix/db/facilitator.py +++ b/src/phoenix/db/facilitator.py @@ -12,14 +12,16 @@ from sqlalchemy.ext.asyncio import AsyncSession from phoenix.auth import ( - DEFAULT_ADMIN_EMAIL, DEFAULT_ADMIN_USERNAME, DEFAULT_SECRET_LENGTH, DEFAULT_SYSTEM_EMAIL, DEFAULT_SYSTEM_USERNAME, compute_password_hash, ) -from phoenix.config import get_env_default_admin_initial_password +from phoenix.config import ( + get_env_default_admin_initial_email, + get_env_default_admin_initial_password, +) from phoenix.db import models from phoenix.db.enums import COLUMN_ENUMS, UserRole from phoenix.server.types import DbSessionFactory @@ -97,6 +99,7 @@ async def _ensure_user_roles(session: AsyncSession) -> None: admin_role_id := role_ids.get(admin_role) ) is not None: salt = secrets.token_bytes(DEFAULT_SECRET_LENGTH) + email = get_env_default_admin_initial_email() password = get_env_default_admin_initial_password() compute = partial(compute_password_hash, password=password, salt=salt) loop = asyncio.get_running_loop() @@ -104,7 +107,7 @@ async def _ensure_user_roles(session: AsyncSession) -> None: admin_user = models.User( user_role_id=admin_role_id, username=DEFAULT_ADMIN_USERNAME, - email=DEFAULT_ADMIN_EMAIL, + email=email, password_salt=salt, password_hash=hash_, reset_password=True,