Skip to content

Commit

Permalink
Fix the db user for mariadb in ubuntu 24.04
Browse files Browse the repository at this point in the history
It was fixed in past for ubuntu 22.04 with [1],
removing the check for jammy so it applies to
all ubuntu versions since jammy.
The checks now only refer debian distros so those
can be adjusted with new debian releases.

[1] https://review.opendev.org/c/openstack/devstack/+/866944

Related-Bug: #1999090
Closes-Bug: #2090835
Change-Id: Iff843c5c3f9c081aa1cec6c399a6ed8c05e06abe
  • Loading branch information
karelyatin committed Dec 3, 2024
1 parent a7fe836 commit 97ea68e
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions lib/databases/mysql
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ function configure_database_mysql {
# Set the root password - only works the first time. For Ubuntu, we already
# did that with debconf before installing the package, but we still try,
# because the package might have been installed already. We don't do this
# for Ubuntu 22.04 (jammy) because the authorization model change in
# for Ubuntu 22.04+ because the authorization model change in
# version 10.4 of mariadb. See
# https://mariadb.org/authentication-in-mariadb-10-4/
if ! (is_ubuntu && [[ "$DISTRO" == "jammy" ]] && [ "$MYSQL_SERVICE_NAME" == "mariadb" ]); then
if ! (is_ubuntu && [[ ! "$DISTRO" =~ bookworm|bullseye ]] && [ "$MYSQL_SERVICE_NAME" == "mariadb" ]); then
sudo mysqladmin -u root password $DATABASE_PASSWORD || true
fi

Expand All @@ -124,16 +124,11 @@ function configure_database_mysql {
# we need to change auth plugin for root user
# TODO(frickler): simplify this logic
if is_ubuntu && [[ ! "$DISTRO" =~ bookworm|bullseye ]] && [ "$MYSQL_SERVICE_NAME" == "mariadb" ]; then
if [[ "$DISTRO" == "jammy" ]]; then
# For Ubuntu 22.04 (jammy) we follow the model outlined in
# https://mariadb.org/authentication-in-mariadb-10-4/
sudo mysql -e "ALTER USER $DATABASE_USER@localhost IDENTIFIED VIA mysql_native_password USING PASSWORD('$DATABASE_PASSWORD');"
else
sudo mysql $cmd_args -e "UPDATE mysql.user SET plugin='' WHERE user='$DATABASE_USER' AND host='localhost';"
sudo mysql $cmd_args -e "FLUSH PRIVILEGES;"
fi
# For Ubuntu 22.04+ we follow the model outlined in
# https://mariadb.org/authentication-in-mariadb-10-4/
sudo mysql -e "ALTER USER $DATABASE_USER@localhost IDENTIFIED VIA mysql_native_password USING PASSWORD('$DATABASE_PASSWORD');"
fi
if ! (is_ubuntu && [[ "$DISTRO" == "jammy" ]] && [ "$MYSQL_SERVICE_NAME" == "mariadb" ]); then
if ! (is_ubuntu && [[ ! "$DISTRO" =~ bookworm|bullseye ]] && [ "$MYSQL_SERVICE_NAME" == "mariadb" ]); then
# Create DB user if it does not already exist
sudo mysql $cmd_args -e "CREATE USER IF NOT EXISTS '$DATABASE_USER'@'%' identified by '$DATABASE_PASSWORD';"
# Update the DB to give user '$DATABASE_USER'@'%' full control of the all databases:
Expand Down

0 comments on commit 97ea68e

Please sign in to comment.