Five apps (mastodon, owncloud, mattermost, matrix, stoat) took their generated secrets from the compose-side generator tags PASSWORD_TAG_<n>/RANDOM_TAG_<n>/ HEX_TAG_<n>/VAPID_TAG_<n>. Those mint a fresh secret on every templating run, so a reinstall handed the app a new database password while its data volume kept the one initdb was given, and the app came back up unable to open its own database. Move them to <app>.config as RANDOMIZED* placeholders, reaching the compose via the #LIBREPORTAL|<APP>_<KEY>_TAG| mechanism tags_processor_app_config_values already provides. No new handler: the tag name is derived from the config key, so this is a config line plus a tag per secret. Generation is unchanged — still random on first install; the value is now remembered instead of re-rolled. Also fixes two things this exposed: - The RANDOMIZED* replacers matched unanchored. `sort -u` orders slots lexically (1, 10, 11, 2), so slot 1's pattern rewrote the prefix inside slot 10's placeholder and slots 10+ ended up holding slot 1's secret with a digit glued on — derivable, and invisible because the values weren't byte-identical. Anchoring with \b makes match order irrelevant. Verified at 20 slots across all four placeholder types: 64 keys, 64 distinct values, no prefix collisions. - generateRandomPassword drew from base64 without constraining the mix; measured over 2000 draws, 1 in 40 contained no digit at all. Retry until the result has both a digit and a letter, bounded so a pathological length can't spin. owncloud gains a fix in passing: its compose seeded the admin account from PASSWORD_TAG_2 while the WebUI displayed CFG_OWNCLOUD_ADMIN_PASSWORD, which was generated separately and never used. Both now read the same value. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
28 lines
1.1 KiB
Bash
28 lines
1.1 KiB
Bash
#!/bin/bash
|
|
|
|
# Laravel-style APP_KEY placeholders.
|
|
# Bookstack (and other Laravel apps) expect APP_KEY=base64:<32-byte
|
|
# base64> — refuses to boot otherwise. We swap RANDOMIZEDAPPKEY<N>
|
|
# placeholders with a freshly generated value.
|
|
replaceLaravelAppKeys()
|
|
{
|
|
local file="$1"
|
|
|
|
local existing_placeholders=$(runCfgOp grep -oE 'RANDOMIZEDAPPKEY[0-9]*' "$file" 2>/dev/null | sort -u)
|
|
|
|
# \b on the substitution below: `sort -u` orders slots lexically (1, 10, 11,
|
|
# 2), so without it slot 1's pattern matches inside slot 10's placeholder and
|
|
# slots 10+ end up holding slot 1's secret with a digit appended. See
|
|
# password_replace.sh for the full description.
|
|
if [[ -n "$existing_placeholders" ]]; then
|
|
while IFS= read -r placeholder; do
|
|
if [[ -n "$placeholder" ]]; then
|
|
local app_key
|
|
app_key="base64:$(openssl rand -base64 32)"
|
|
runCfgOp sed -i "s#${placeholder}\\b#${app_key}#g" "$file"
|
|
checkSuccess "Updated ${placeholder} in $(basename "$file") with a new Laravel APP_KEY."
|
|
fi
|
|
done <<< "$existing_placeholders"
|
|
fi
|
|
}
|