Harden Docker defaults for admin bootstrap and secrets#93
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2763e6b28a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| SECRET_KEY = os.getenv("SECRET_KEY", secrets.token_urlsafe(32)) | ||
| SECURITY_PASSWORD_SALT = os.getenv("SECURITY_PASSWORD_SALT", secrets.token_urlsafe(32)) |
There was a problem hiding this comment.
Generate stable secret defaults across workers
SECRET_KEY and SECURITY_PASSWORD_SALT are now generated with secrets.token_urlsafe(32) at import time, so each Gunicorn worker gets different values when env vars are unset. In this repo the entrypoint launches gunicorn --workers 2, so session cookies/CSRF tokens issued by one worker are invalid on requests handled by the other, causing intermittent logouts and form failures in the default Docker deployment. The fallback needs to be process-stable (shared env/file/derived once before workers) rather than per-worker random generation.
Useful? React with 👍 / 👎.
|
0.18 PR request fixes this |
Motivation
admin/passwordaccount and exposed static Flask signing secrets, which allowed remote takeover when the container was run with defaults.SECRET_KEYvalues.Description
entrypoint.shsoflask create_adminruns only whenMOSP_ADMIN_PASSWORDis explicitly provided, with optionalMOSP_ADMIN_LOGINandMOSP_ADMIN_EMAILoverrides, instead of always creatingadmin/password.instance/docker.pyto importsecretsand setSECRET_KEYandSECURITY_PASSWORD_SALTfrom environment variables with secure random fallbacks viasecrets.token_urlsafe(32).SECRET_KEY,SECURITY_PASSWORD_SALT, orMOSP_ADMIN_*environment variables while removing unsafe defaults.Testing
bash -n entrypoint.shwhich returned no syntax errors and succeeded.python -m py_compile instance/docker.pywhich completed successfully with no compilation errors.Codex Task