Fix ROMM_AUTH_SECRET_KEY auto-generation under nounset

The init script runs with `set -o nounset`, so testing `${ROMM_AUTH_SECRET_KEY}`
aborted with "unbound variable" before reaching the generation branch, leaving
the container in a restart loop. This only triggered when the variable was
omitted entirely; shipping it with an empty value took the working path.

Use `${ROMM_AUTH_SECRET_KEY-}` so the unset case is testable, and warn instead
of info since a generated key changes on every restart.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Georges-Antoine Assi
2026-07-27 08:07:50 -04:00
parent ce49cd0c55
commit 98651ecbf8
5 changed files with 16 additions and 16 deletions

View File

@@ -332,9 +332,9 @@ if ! printenv | grep -q '^OTEL_'; then
fi
# Set ROMM_AUTH_SECRET_KEY if not already set
if [[ -z ${ROMM_AUTH_SECRET_KEY} ]]; then
if [[ -z ${ROMM_AUTH_SECRET_KEY-} ]]; then
ROMM_AUTH_SECRET_KEY=$(python3 -c "import secrets; print(secrets.token_hex(32))")
info_log "ROMM_AUTH_SECRET_KEY not set, generating random secret key"
warn_log "ROMM_AUTH_SECRET_KEY not set, generating a random secret key. It changes on every restart, invalidating API bearer tokens and pending invite/password-reset links. Set it explicitly to keep those valid, and always set it when running more than one replica."
export ROMM_AUTH_SECRET_KEY
fi

View File

@@ -1541,17 +1541,17 @@ Falls back to `FakeRedis` in test mode.
#### Authentication
| Variable | Default | Description |
| ------------------------------------ | --------- | ------------------------------------- |
| `ROMM_AUTH_SECRET_KEY` | | **Required.** JWT/session signing key |
| `OAUTH_ACCESS_TOKEN_EXPIRE_SECONDS` | `1800` | 30 minutes |
| `OAUTH_REFRESH_TOKEN_EXPIRE_SECONDS` | `604800` | 7 days |
| `SESSION_MAX_AGE_SECONDS` | `1209600` | 14 days |
| `DISABLE_CSRF_PROTECTION` | `false` | Disable CSRF |
| `DISABLE_DOWNLOAD_ENDPOINT_AUTH` | `false` | Allow unauthenticated downloads |
| `DISABLE_USERPASS_LOGIN` | `false` | Disable password login |
| `DISABLE_LOGS_VIEWER` | `false` | Disable backend log viewer + endpoint |
| `KIOSK_MODE` | `false` | Read-only anonymous access |
| Variable | Default | Description |
| ------------------------------------ | --------- | ----------------------------------------- |
| `ROMM_AUTH_SECRET_KEY` | | JWT/session signing key (random if unset) |
| `OAUTH_ACCESS_TOKEN_EXPIRE_SECONDS` | `1800` | 30 minutes |
| `OAUTH_REFRESH_TOKEN_EXPIRE_SECONDS` | `604800` | 7 days |
| `SESSION_MAX_AGE_SECONDS` | `1209600` | 14 days |
| `DISABLE_CSRF_PROTECTION` | `false` | Disable CSRF |
| `DISABLE_DOWNLOAD_ENDPOINT_AUTH` | `false` | Allow unauthenticated downloads |
| `DISABLE_USERPASS_LOGIN` | `false` | Disable password login |
| `DISABLE_LOGS_VIEWER` | `false` | Disable backend log viewer + endpoint |
| `KIOSK_MODE` | `false` | Read-only anonymous access |
#### OIDC

View File

@@ -31,7 +31,7 @@ function handle_termination() {
trap handle_termination SIGTERM SIGINT
# Set ROMM_AUTH_SECRET_KEY if not already set
if [[ -z ${ROMM_AUTH_SECRET_KEY} ]]; then
if [[ -z ${ROMM_AUTH_SECRET_KEY-} ]]; then
ROMM_AUTH_SECRET_KEY=$(python3 -c "import secrets; print(secrets.token_hex(32))")
export ROMM_AUTH_SECRET_KEY
fi

View File

@@ -24,7 +24,7 @@ REDIS_DB=0 # Database number for the Redis/Valkey instance
REDIS_SSL=false # Enable SSL (rediss://) for the Redis/Valkey connection
# Authentication
ROMM_AUTH_SECRET_KEY= # App secret, generate with `openssl rand -hex 32` [REQUIRED]
ROMM_AUTH_SECRET_KEY= # App secret, generate with `openssl rand -hex 32`. Randomly generated at startup if left blank, which invalidates API tokens and invite/reset links on every restart
OAUTH_ACCESS_TOKEN_EXPIRE_SECONDS=1800 # Access token lifetime in seconds
OAUTH_REFRESH_TOKEN_EXPIRE_SECONDS=604800 # Refresh token lifetime in seconds
SESSION_MAX_AGE_SECONDS=1209600 # Maximum age of a session in seconds

View File

@@ -13,7 +13,7 @@ services:
- DB_NAME=romm # Should match MARIADB_DATABASE in mariadb
- DB_USER=romm-user # Should match MARIADB_USER in mariadb
- DB_PASSWD= # Should match MARIADB_PASSWORD in mariadb
- ROMM_AUTH_SECRET_KEY= # Generate a key with `openssl rand -hex 32`
- ROMM_AUTH_SECRET_KEY= # Generate a key with `openssl rand -hex 32`, otherwise a random one is generated on each restart (invalidating API tokens)
- SCREENSCRAPER_USER= # These are the recommended metadata providers
- SCREENSCRAPER_PASSWORD= # https://docs.romm.app/latest/Getting-Started/Metadata-Providers/#screenscraper
- RETROACHIEVEMENTS_API_KEY= # https://docs.romm.app/latest/Getting-Started/Metadata-Providers/#retroachievements