project-pegaprox icon indicating copy to clipboard operation
project-pegaprox copied to clipboard

[Bug] - Accounts deleted after container restart, pegaprox password reverts to 'admin'

Open yairmiz opened this issue 8 months ago • 1 comments

Describe the bug

_migrate_from_legacy() in db.py wipes all users and resets the pegaprox account to the default admin password on every container restart when any OIDC/Entra ID/LDAP user exists in the database.

The root cause is a startup check that looks for any user with an empty password_salt. External auth users (OIDC, Entra ID, LDAP) legitimately have no password_salt — their authentication is handled externally. When such a user is the first row returned, the check incorrectly sets needs_user_remigration = True, which then:

  1. Runs DELETE FROM users — wipes the entire users table
  2. Attempts to re-migrate from users.enc (legacy encrypted file) — which doesn't exist on SQLite-based installs
  3. Falls through to create_default_users() — recreates pegaprox with password=admin and force_password_change=True

Relevant code in pegaprox/core/db.py inside _migrate_from_legacy():

cursor.execute("SELECT username, password_salt FROM users LIMIT 1")
row = cursor.fetchone()
if row:
    salt = row[1] if len(row) > 1 else None
    if not salt or salt == '':  # <-- fires on every OIDC/Entra user
        needs_user_remigration = True

Steps to Reproduce

  1. Configure Entra ID / OIDC / LDAP authentication in PegaProx settings
  2. Log in with an external auth user — the account is saved to the SQLite DB with an empty password_salt
  3. Restart the container (docker compose restart)
  4. All users are gone; the pegaprox account is back with password=admin and force_password_change=1

Expected behavior

Container restarts should not affect user accounts. External auth users have no password_salt by design and should never trigger legacy migration. All existing users should persist across restarts.

Suggested fix — scope the check to local auth users only:

# Before:
cursor.execute("SELECT username, password_salt FROM users LIMIT 1")

# After:
cursor.execute("SELECT username, password_salt FROM users WHERE auth_source = 'local' LIMIT 1")

Environment

  • PegaProx Version: 0.9.3 Beta
  • Installation Method: Docker
  • OS: Debian 12
  • Browser: N/A (API-level reproduction)
  • Behind Reverse Proxy? No
  • UI? Modern Layout

Logs

# On startup (docker logs pegaprox):
Initializing user system...
Loaded 2 users        # <-- users loaded correctly from DB

# But after restart, users are gone and this appears:
DEFAULT LOGIN CREDENTIALS:
  Username: pegaprox
  Password: admin
  Please change the password after first login!
# DB state before restart — confirms empty salt for Entra ID user:
# SELECT username, password_salt FROM users;
# yair.mizrahi | ''         <-- Entra ID user, empty salt
# pegaprox     | 'argon2'   <-- local user, has salt

yairmiz avatar Mar 25 '26 14:03 yairmiz

Just did shoot trough the fix :)

Thanks for reporting!

Best Regards, Nico

MrMasterbay avatar Mar 25 '26 19:03 MrMasterbay