Skip to content

Commit 0314342

Browse files
committed
[deploy] Fixed password authentication failure #562
Prevents credential mismatch when reinstalling without clearing volumes. The script now detects existing postgres_data volumes and aborts with a clear warning instead of silently generating new credentials that break database connectivity. Fixes #562
1 parent 8f378f3 commit 0314342

1 file changed

Lines changed: 59 additions & 3 deletions

File tree

deploy/auto-install.sh

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,44 @@ setup_docker_openwisp() {
103103
echo -ne ${GRN}"Do you have .env file? Enter filepath (leave blank for ad-hoc configuration): "${NON}
104104
read env_path
105105
if [[ ! -f "$env_path" ]]; then
106+
# Validate backup has required credentials
107+
backup_has_credentials=false
108+
if [[ -f "$ENV_BACKUP" ]]; then
109+
backup_has_credentials=true
110+
for config in DB_USER DB_PASS DJANGO_SECRET_KEY; do
111+
if [[ -z "$(get_env "$config" "$ENV_BACKUP")" ]]; then
112+
backup_has_credentials=false
113+
break
114+
fi
115+
done
116+
fi
117+
118+
if [[ ! -f "$INSTALL_PATH/.env" ]] && [[ "$backup_has_credentials" != true ]] && docker volume inspect "docker-openwisp_postgres_data" &>/dev/null; then
119+
{
120+
echo -e "${RED}CRITICAL: Existing database volume detected!${NON}"
121+
echo ""
122+
echo "The Docker volume \"docker-openwisp_postgres_data\" already exists on this system."
123+
echo "This likely means there is database data from a previous OpenWISP installation."
124+
echo ""
125+
echo "The auto-install script generates new database credentials during fresh installations."
126+
echo "If it proceeds while this volume exists, the newly generated credentials will not"
127+
echo "match the credentials stored in the existing database, making the database"
128+
echo "inaccessible to OpenWISP."
129+
echo ""
130+
echo -e "${RED}⚠️ WARNING: The commands below will permanently delete the database volume and all"
131+
echo -e "stored data. Run them only if you intentionally want to wipe the previous installation"
132+
echo -e "or have a verified backup. Proceed at your own discretion.${NON}"
133+
echo ""
134+
echo "Cleanup commands:"
135+
echo -e " ${YLW}cd /opt/openwisp/docker-openwisp && docker compose down --volumes${NON}"
136+
echo "or"
137+
echo -e " ${YLW}docker volume rm docker-openwisp_postgres_data${NON}"
138+
echo ""
139+
echo "Aborting installation to prevent credential mismatch."
140+
echo -e "${RED}Check logs at $LOG_FILE${NON}"
141+
} | tee -a "$LOG_FILE"
142+
exit 1
143+
fi
106144
# Dashboard Domain
107145
echo -ne ${GRN}"(1/5) Enter dashboard domain: "${NON}
108146
read dashboard_domain
@@ -157,9 +195,27 @@ setup_docker_openwisp() {
157195
fi
158196
# Site manager email
159197
set_env "EMAIL_DJANGO_DEFAULT" "$django_default_email"
160-
# Set random secret values
161-
python3 $INSTALL_PATH/build.py change-secret-key >/dev/null
162-
python3 $INSTALL_PATH/build.py change-database-credentials >/dev/null
198+
# Re-validate backup credentials after download
199+
restore_from_backup=false
200+
if [[ -f "$ENV_BACKUP" ]]; then
201+
restore_from_backup=true
202+
for config in DB_USER DB_PASS DJANGO_SECRET_KEY; do
203+
if [[ -z "$(get_env "$config" "$ENV_BACKUP")" ]]; then
204+
restore_from_backup=false
205+
break
206+
fi
207+
done
208+
fi
209+
# Set random secret values only if no previous credentials exist
210+
if [[ "$restore_from_backup" == true ]]; then
211+
for config in DB_USER DB_PASS DJANGO_SECRET_KEY; do
212+
value=$(get_env "$config" "$ENV_BACKUP")
213+
set_env "$config" "$value"
214+
done
215+
else
216+
python3 $INSTALL_PATH/build.py change-secret-key >/dev/null
217+
python3 $INSTALL_PATH/build.py change-database-credentials >/dev/null
218+
fi
163219
# SSL Configuration
164220
use_letsencrypt_lower=$(echo "$use_letsencrypt" | tr '[:upper:]' '[:lower:]')
165221
if [[ "$use_letsencrypt_lower" == "y" || "$use_letsencrypt_lower" == "yes" ]]; then

0 commit comments

Comments
 (0)