Skip to content

Feature: Adds env var SECRET_KEY_DIR support #7868

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/backend/base/langflow/services/settings/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
class AuthSettings(BaseSettings):
# Login settings
CONFIG_DIR: str
# This must come before `SECRET_KEY` as Pydantic field validation is performed in the order fields are defined.
SECRET_KEY_DIR: str = Field(
default="",
description="Directory for local secret key file. If not provided, CONFIG_DIR will be used.",
frozen=False,
)
SECRET_KEY: SecretStr = Field(
default=SecretStr(""),
description="Secret key for JWT. If not provided, a random one will be generated.",
Expand Down Expand Up @@ -81,12 +87,16 @@ def validate_superuser(cls, value, info):
@classmethod
def get_secret_key(cls, value, info):
config_dir = info.data.get("CONFIG_DIR")
secret_key_dir = info.data.get("SECRET_KEY_DIR")

if not config_dir:
logger.debug("No CONFIG_DIR provided, not saving secret key")
if not config_dir and not secret_key_dir:
logger.debug("No CONFIG_DIR or SECRET_KEY_DIR provided, not saving secret key")
return value or secrets.token_urlsafe(32)

secret_key_path = Path(config_dir) / "secret_key"
if secret_key_dir:
secret_key_path = Path(secret_key_dir).expanduser() / "secret_key"
else:
secret_key_path = Path(config_dir) / "secret_key"

if value:
logger.debug("Secret key provided")
Expand Down
Loading