You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The existing mariadb operator in fact already "supports" in-place
change of secret, since if you change Spec.Secret to a new secret
name, that would imply a new job hash, and the account.sh script running
using only GRANT statements would update the password per mariadb.
This already works for flipping the TLS flag on and off too.
So in this patch, we clean this up and add a test to include:
* a new field Status.CurrentSecret, which is used to indicate the
previous secret from which the finalizer should be removed. This will
also be used when we migrate the root password to use MariaDBAccount
by providing the "current" root password when changing to a new root
password
* improved messaging in log messages, name of job. This changes the
job hash for mariadbaccount which will incur a run on existing environments,
however the
job hashes are already changing on existing environments due to the
change in how the mysql root password is sent, i.e. via volume mounted
script rather than env var secret
* update account.sh to use modern idiomatic patterns for user create
/alter, while mariadb is fine with the legacy style of using only
GRANT statements, MySQL 8 no longer allows this statement to proceed
without a CREATE USER, so formalize the commands used here to use
distinct CREATE USER, ALTER USER, GRANT statements and clarify the
script is good for all create/update user operations.
mysql -h {{.DatabaseHostname}} -u {{.DatabaseAdminUsername}} -P 3306 -e "GRANT ALL PRIVILEGES ON {{.DatabaseName}}.* TO '{{.UserName}}'@'localhost' IDENTIFIED BY '$DatabasePassword'{{.RequireTLS}};GRANT ALL PRIVILEGES ON {{.DatabaseName}}.* TO '{{.UserName}}'@'%' IDENTIFIED BY '$DatabasePassword'{{.RequireTLS}};"
10
+
GRANT_DATABASE="{{.DatabaseName}}"
9
11
else
10
-
mysql -h {{.DatabaseHostname}} -u {{.DatabaseAdminUsername}} -P 3306 -e "GRANT ALL PRIVILEGES ON *.* TO '{{.UserName}}'@'localhost' IDENTIFIED BY '$DatabasePassword'{{.RequireTLS}};GRANT ALL PRIVILEGES ON *.* TO '{{.UserName}}'@'%' IDENTIFIED BY '$DatabasePassword'{{.RequireTLS}};"
12
+
GRANT_DATABASE="*"
11
13
fi
12
14
15
+
# going for maximum compatibility here:
16
+
# 1. MySQL 8 no longer allows implicit create user when GRANT is used
17
+
# 2. MariaDB has "CREATE OR REPLACE", but MySQL does not
18
+
# 3. create user with CREATE but then do all password and TLS with ALTER to
19
+
# support updates
20
+
21
+
$MYSQL_CMD<<EOF
22
+
CREATE USER IF NOT EXISTS '{{.UserName}}'@'localhost';
23
+
CREATE USER IF NOT EXISTS '{{.UserName}}'@'%';
24
+
25
+
ALTER USER '{{.UserName}}'@'localhost' IDENTIFIED BY '$DatabasePassword'{{.RequireTLS}};
26
+
ALTER USER '{{.UserName}}'@'%' IDENTIFIED BY '$DatabasePassword'{{.RequireTLS}};
27
+
28
+
GRANT ALL PRIVILEGES ON ${GRANT_DATABASE}.* TO '{{.UserName}}'@'localhost';
29
+
GRANT ALL PRIVILEGES ON ${GRANT_DATABASE}.* TO '{{.UserName}}'@'%';
30
+
EOF
31
+
32
+
13
33
# search for the account. not using SHOW CREATE USER to avoid displaying
14
34
# password hash
15
-
username=$(mysql -h {{.DatabaseHostname}} -u {{.DatabaseAdminUsername}} -P 3306 -NB -e "select user from mysql.user where user='{{.UserName}}' and host='localhost';")
35
+
username=$($MYSQL_CMD -NB -e "select user from mysql.user where user='{{.UserName}}' and host='localhost';")
0 commit comments