-
-
Notifications
You must be signed in to change notification settings - Fork 115
[chores] Added loud failure message if existing database is detected #562 #568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -103,6 +103,44 @@ setup_docker_openwisp() { | |||||
| echo -ne ${GRN}"Do you have .env file? Enter filepath (leave blank for ad-hoc configuration): "${NON} | ||||||
| read env_path | ||||||
| if [[ ! -f "$env_path" ]]; then | ||||||
| # Validate backup has required credentials | ||||||
| backup_has_credentials=false | ||||||
| if [[ -f "$ENV_BACKUP" ]]; then | ||||||
| backup_has_credentials=true | ||||||
| for config in DB_USER DB_PASS DJANGO_SECRET_KEY; do | ||||||
| if [[ -z "$(get_env "$config" "$ENV_BACKUP")" ]]; then | ||||||
| backup_has_credentials=false | ||||||
| break | ||||||
| fi | ||||||
| done | ||||||
| fi | ||||||
|
|
||||||
| if [[ ! -f "$INSTALL_PATH/.env" ]] && [[ "$backup_has_credentials" != true ]] && docker volume inspect "docker-openwisp_postgres_data" &>/dev/null; then | ||||||
| { | ||||||
| echo -e "${RED}CRITICAL: Existing database volume detected!${NON}" | ||||||
| echo "" | ||||||
| echo "The Docker volume \"docker-openwisp_postgres_data\" already exists on this system." | ||||||
| echo "This likely means there is database data from a previous OpenWISP installation." | ||||||
| echo "" | ||||||
| echo "The auto-install script generates new database credentials during fresh installations." | ||||||
| echo "If it proceeds while this volume exists, the newly generated credentials will not" | ||||||
| echo "match the credentials stored in the existing database, making the database" | ||||||
| echo "inaccessible to OpenWISP." | ||||||
| echo "" | ||||||
| echo -e "${RED}⚠️ WARNING: The commands below will permanently delete the database volume and all" | ||||||
| echo -e "stored data. Run them only if you intentionally want to wipe the previous installation" | ||||||
| echo -e "or have a verified backup. Proceed at your own discretion.${NON}" | ||||||
| echo "" | ||||||
| echo "Cleanup commands:" | ||||||
| echo -e " ${YLW}cd /opt/openwisp/docker-openwisp && docker compose down --volumes${NON}" | ||||||
| echo "or" | ||||||
| echo -e " ${YLW}docker volume rm docker-openwisp_postgres_data${NON}" | ||||||
| echo "" | ||||||
| echo "Aborting installation to prevent credential mismatch." | ||||||
| echo -e "${RED}Check logs at $LOG_FILE${NON}" | ||||||
| } | tee -a "$LOG_FILE" | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WARNING: ANSI escape codes will be written to the log file The Strip the color codes before writing to the log:
Suggested change
Alternatively, use |
||||||
| exit 1 | ||||||
| fi | ||||||
| # Dashboard Domain | ||||||
| echo -ne ${GRN}"(1/5) Enter dashboard domain: "${NON} | ||||||
| read dashboard_domain | ||||||
|
|
@@ -157,9 +195,27 @@ setup_docker_openwisp() { | |||||
| fi | ||||||
| # Site manager email | ||||||
| set_env "EMAIL_DJANGO_DEFAULT" "$django_default_email" | ||||||
| # Set random secret values | ||||||
| python3 $INSTALL_PATH/build.py change-secret-key >/dev/null | ||||||
| python3 $INSTALL_PATH/build.py change-database-credentials >/dev/null | ||||||
| # Re-validate backup credentials after download | ||||||
| restore_from_backup=false | ||||||
| if [[ -f "$ENV_BACKUP" ]]; then | ||||||
| restore_from_backup=true | ||||||
| for config in DB_USER DB_PASS DJANGO_SECRET_KEY; do | ||||||
| if [[ -z "$(get_env "$config" "$ENV_BACKUP")" ]]; then | ||||||
| restore_from_backup=false | ||||||
| break | ||||||
| fi | ||||||
| done | ||||||
| fi | ||||||
| # Set random secret values only if no previous credentials exist | ||||||
| if [[ "$restore_from_backup" == true ]]; then | ||||||
| for config in DB_USER DB_PASS DJANGO_SECRET_KEY; do | ||||||
| value=$(get_env "$config" "$ENV_BACKUP") | ||||||
| set_env "$config" "$value" | ||||||
| done | ||||||
|
Comment on lines
+210
to
+214
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: find . -name "auto-install.sh" -type fRepository: openwisp/docker-openwisp Length of output: 92 🏁 Script executed: find . -name "build.py" -type fRepository: openwisp/docker-openwisp Length of output: 78 🏁 Script executed: # Let's also check the structure
git ls-files | head -20Repository: openwisp/docker-openwisp Length of output: 552 🏁 Script executed: wc -l deploy/auto-install.sh build.pyRepository: openwisp/docker-openwisp Length of output: 123 🏁 Script executed: # Read auto-install.sh to find set_env() function and the backup restore logic
cat -n deploy/auto-install.shRepository: openwisp/docker-openwisp Length of output: 14757 🏁 Script executed: cat -n build.pyRepository: openwisp/docker-openwisp Length of output: 1907 Fix unsafe secret restoration through The The same vulnerability exists in the upgrade path (lines 254-257). Replace 🤖 Prompt for AI Agents |
||||||
| else | ||||||
| python3 $INSTALL_PATH/build.py change-secret-key >/dev/null | ||||||
| python3 $INSTALL_PATH/build.py change-database-credentials >/dev/null | ||||||
| fi | ||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| # SSL Configuration | ||||||
| use_letsencrypt_lower=$(echo "$use_letsencrypt" | tr '[:upper:]' '[:lower:]') | ||||||
| if [[ "$use_letsencrypt_lower" == "y" || "$use_letsencrypt_lower" == "yes" ]]; then | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't let an incomplete live
.envbypass the volume-safety abort.Line 118 only checks whether
$INSTALL_PATH/.envexists, not whether it still containsDB_USER,DB_PASS, andDJANGO_SECRET_KEY. If that file is partial or corrupted,download_docker_openwisp()will move it to$ENV_BACKUP,restore_from_backupwill stay false, and Lines 216-217 will regenerate fresh credentials against the existingdocker-openwisp_postgres_datavolume. That recreates the auth mismatch this PR is trying to prevent. Reuse the same required-key validation for the live.env, or abort again immediately before the regeneration fallback.Based on learnings, the
.envfile contains critical configurations that must be present for safe operation, and silent failures with empty values would be more dangerous than failing explicitly when the file is missing.🤖 Prompt for AI Agents