authd icon indicating copy to clipboard operation
authd copied to clipboard

Fix migration to lowercase user and group names

Open adombeck opened this issue 11 months ago • 0 comments

  • Fix bbolt to SQLite migration with users with uppercase letters

    The migration failed with

      failed to migrate data: no result matching [email protected] in UserByName
    

    if the user name contains uppercase letters ([email protected] in this case).

    That's because we're calling the Database.BrokerForUser method from package bbolt for each user before migrating it, which calls Database.UserByName. If that returns a lowercase username, it won't find the broker for the user in the UserToBroker which has not been migrated to lowercase yet.

    With this commit, we're not using lowercase names at all in the bbolt package, but only in the SQLite package, which is fine because we're always migrating to SQLite first before we migrate to lowercase names.

  • Test migrating user with uppercase letters

    Regression test for the previous commit.

  • Test migrating group names with uppercase letters.

  • Apply schema migrations after migration to SQLite

    While working on the lowercase usernames PR (#723), a first implementation did the migration to lowercase usernames as part of the bbolt to SQLite migration. Later, we added it as a separate migration, to also support migrating authd installations that were installed from the edge PPA, which already had automated releases which use SQLite.

    Those separate migrations also did some more things than just use lowercase usernames, e.g. it also used lowercase group names and it also renamed the users in the /etc/group file.

    While those migrations have extensive tests in internal/users/db/db_test.go, it turns out that they were never executed when migrating from the last stable authd release, because the migration from bbolt to SQLite creates a SQLite database with schema version 1, which means that the schema migration is not executed.

    To fix that, this commit doesn't do any lowercase username migration as part of the bbolt to SQLite migration, but resets the schema version to 0 afterwards and then applies the schema migrations.

  • Test schema migrations applied after SQLite migration

  • Enable debug logs in daemon tests

UDENG-7094

adombeck avatar May 26 '25 13:05 adombeck