diff options
| author | Andrew Dolgov <fox@fakecake.org> | 2026-10-11 08:14:42 +0300 |
|---|---|---|
| committer | Andrew Dolgov <fox@fakecake.org> | 2026-10-11 08:14:42 +0300 |
| commit | e77e334e4e7a4b17aa3f7ca1c5324a8030d162d7 (patch) | |
| tree | a37a6b8f78ba238fc8958faa8f1e350f1936ff54 | |
| parent | 451710e9f052db9167afb8130900d2d5bec6993a (diff) | |
| download | the-epube-e77e334e4e7a4b17aa3f7ca1c5324a8030d162d7.tar.gz the-epube-e77e334e4e7a4b17aa3f7ca1c5324a8030d162d7.tar.xz | |
create admin user with random password on first start instead of relying on a predefined one
| -rw-r--r-- | .docker/app/Dockerfile | 6 | ||||
| -rw-r--r-- | .docker/app/startup.sh | 27 | ||||
| -rw-r--r-- | .env-dist | 8 |
3 files changed, 35 insertions, 6 deletions
diff --git a/.docker/app/Dockerfile b/.docker/app/Dockerfile index 9ec3691..d2e7b5b 100644 --- a/.docker/app/Dockerfile +++ b/.docker/app/Dockerfile @@ -63,8 +63,12 @@ RUN chmod 0755 ${SCRIPT_ROOT}/startup.sh ENV PHP_WORKER_MAX_CHILDREN=5 ENV PHP_WORKER_MEMORY_LIMIT=256M +# Admin bootstrap account. Only the *name* is baked in — never a password. +# If the user does not exist at first boot, startup.sh creates it with a +# randomly generated password, printed once to the container log. +# Override the name with -e EPUBE_ADMIN_USER=..., or supply your own password +# via -e EPUBE_ADMIN_PASS=... if you must. ENV EPUBE_ADMIN_USER="admin" -ENV EPUBE_ADMIN_PASS="password" # EPUBE_XDEBUG_HOST defaults to host IP if unset ENV EPUBE_XDEBUG_ENABLED="" diff --git a/.docker/app/startup.sh b/.docker/app/startup.sh index 64ad86f..d49dd05 100644 --- a/.docker/app/startup.sh +++ b/.docker/app/startup.sh @@ -36,8 +36,31 @@ rm -f /tmp/error.log && mkfifo /tmp/error.log (tail -q -f /tmp/error.log >> /proc/1/fd/2) & -if ! php${PHP_SUFFIX} $DST_DIR/update.php --user-list | grep -q "$EPUBE_ADMIN_USER"; then - php${PHP_SUFFIX} $DST_DIR/update.php --user-add "$EPUBE_ADMIN_USER:$EPUBE_ADMIN_PASS" +# --- Bootstrap admin account ------------------------------------------------- +# If the configured admin user does not exist yet, create it. When no password +# is supplied via EPUBE_ADMIN_PASS, generate a random one and print it to the +# container log exactly once. No static credentials ship in the image. +generate_password() { + local pass="" + while [ ${#pass} -lt 24 ]; do + pass="${pass}$(head -c 128 /dev/urandom | tr -dc 'A-Za-z0-9')" + done + printf '%s' "${pass:0:24}" +} + +php${PHP_SUFFIX} "$DST_DIR/update.php" --user-list > /tmp/epube_users.txt + +if ! grep -q "^.*\. *${EPUBE_ADMIN_USER}\$" /tmp/epube_users.txt; then + if [ -n "$EPUBE_ADMIN_PASS" ]; then + printf 'Creating admin user "%s" with password from environment.\n' "$EPUBE_ADMIN_USER" + else + EPUBE_ADMIN_PASS="$(generate_password)" + printf 'Creating admin user "%s" with generated password: %s\n' "$EPUBE_ADMIN_USER" "$EPUBE_ADMIN_PASS" + printf 'Store it now — it will not be shown again.\n' + fi + php${PHP_SUFFIX} "$DST_DIR/update.php" --user-add="${EPUBE_ADMIN_USER}:${EPUBE_ADMIN_PASS}" fi +rm -f /tmp/epube_users.txt + exec /usr/sbin/php-fpm${PHP_SUFFIX} --nodaemonize --force-stderr -R diff --git a/.env-dist b/.env-dist index c2dcd96..3f4781e 100644 --- a/.env-dist +++ b/.env-dist @@ -66,11 +66,13 @@ BOOKS_DIR=/home/user/calibre/Books # EPUBE_DICT_SERVER=dict # --------------------------------------------------------------------------- -# Authentication — Default Admin Account +# Authentication — Admin Bootstrap Account # --------------------------------------------------------------------------- -# Created on first startup if the user does not already exist. +# The admin user is created on first startup if it does not already exist. +# If EPUBE_ADMIN_PASS is left unset, a random password is generated and +# printed ONCE to the container log (docker logs <app-container>). EPUBE_ADMIN_USER=admin -EPUBE_ADMIN_PASS=password +# EPUBE_ADMIN_PASS= # optional — set explicitly only if you insist on your own # --------------------------------------------------------------------------- # Authentication — OpenID Connect (OIDC) |
