fix: Fixes migration code incorrectly decoding bcrypt basswords as hex.
All checks were successful
Release code / build (push) Successful in 11m56s

This commit is contained in:
Tera << 8 2024-12-27 09:10:17 -05:00
parent 538c5b6c51
commit c55510eb04
Signed by: imterah
GPG key ID: 8FA7DD57BA6CEA37
3 changed files with 2 additions and 39 deletions

View file

@ -3,7 +3,6 @@ package main
import (
"compress/gzip"
"encoding/base64"
"encoding/hex"
"encoding/json"
"fmt"
"io"
@ -223,18 +222,11 @@ func backupRestoreEntrypoint(cCtx *cli.Context) error {
username = *user.Username
}
bcryptPassword, err := hex.DecodeString(user.Password)
if err != nil {
log.Errorf("Failed to decode hex encoded password: %s", err.Error())
continue
}
userDatabase := &dbcore.User{
Email: user.Email,
Username: username,
Name: user.Name,
Password: base64.StdEncoding.EncodeToString(bcryptPassword),
Password: base64.StdEncoding.EncodeToString([]byte(user.Password)),
IsBot: user.IsBot,
Tokens: tokens,

View file

@ -28,7 +28,7 @@ Below are new environment variables that may need to be set up:
6. Go get the container logs, and make sure no errors get output to the console.
7. Copy the backup as instructed in the log file.
8. DO NOT RESTART THE CONTAINER IF SUCCESSFUL. YOU WILL LOSE ALL YOUR DATA. If the migration fails, follow the steps mentioned in the logs. You do not need to copy the DB backup if it failed to connect or read the database.
9. If successful, remove the environment variable `HERMES_MIGRATE_POSTGRES_DATABASE`.
9. If successful, remove the environment variables `HERMES_MIGRATE_POSTGRES_DATABASE` and `DATABASE_URL`.
10. Switch the API docker image from `ghcr.io/imterah/hermes-backend-migration:latest` to `ghcr.io/imterah/hermes:latest`.
11. Start the backend.
## Failed Migration / Manual Restoration Steps

29
init.sh
View file

@ -1,14 +1,4 @@
#!/usr/bin/env bash
owned_docker=1
# Test if Postgres is up
lsof -i:5432 2> /dev/null > /dev/null
if [ $? -ne 0 ]; then
owned_docker=0
docker compose -f dev-docker-compose.yml up -d
fi
if [ ! -f "backend/.env" ]; then
cp backend/dev.env backend/.env
fi
@ -21,26 +11,7 @@ if [ ! -f "backend-legacy/.env" ]; then
cp backend-legacy/dev.env backend-legacy/.env
fi
if [ ! -d "backend-legacy/node_modules" ]; then
pushd backend-legacy > /dev/null
npm install --save-dev
npx prisma migrate dev
popd > /dev/null
fi
set -a
source backend-legacy/.env
source backend/.env
set +a
on_exit() {
cd $(git rev-parse --show-toplevel)
if [ $owned_docker -ne 0 ]; then
return
fi
docker compose -f dev-docker-compose.yml down
}
trap "on_exit" exit