Use same script for both SSL and non-SSL users

This commit is contained in:
Markus Mäkelä 2020-11-16 16:54:37 +02:00
parent 43c53e2f79
commit 558bd9279b
No known key found for this signature in database
GPG Key ID: 5CE746D557ACC499
2 changed files with 13 additions and 12 deletions

View File

@ -1,10 +1,15 @@
#!/bin/bash
# The following environment variables are used:
# node_user - A custom user to create
# node_password - The password for the user
# require_ssl - Require SSL for all users except the replication user
mysql --force $1 <<EOF >& /dev/null
DROP USER IF EXISTS '$node_user'@'%';
CREATE USER '$node_user'@'%' IDENTIFIED BY '$node_password';
GRANT ALL PRIVILEGES ON *.* TO '$node_user'@'%' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO '$node_user'@'%' $require_ssl WITH GRANT OPTION;
DROP USER IF EXISTS 'repl'@'%';
CREATE USER 'repl'@'%' IDENTIFIED BY 'repl';
@ -16,7 +21,7 @@ GRANT ALL ON *.* TO 'repl'@'localhost' WITH GRANT OPTION;
DROP USER IF EXISTS 'skysql'@'%';
CREATE USER 'skysql'@'%' IDENTIFIED BY 'skysql';
GRANT ALL ON *.* TO 'skysql'@'%' WITH GRANT OPTION;
GRANT ALL ON *.* TO 'skysql'@'%' $require_ssl WITH GRANT OPTION;
DROP USER IF EXISTS 'skysql'@'localhost';
CREATE USER 'skysql'@'localhost' IDENTIFIED BY 'skysql';
@ -24,19 +29,19 @@ GRANT ALL ON *.* TO 'skysql'@'localhost' WITH GRANT OPTION;
DROP USER IF EXISTS 'maxskysql'@'%';
CREATE USER 'maxskysql'@'%' IDENTIFIED BY 'skysql';
GRANT ALL ON *.* TO 'maxskysql'@'%' WITH GRANT OPTION;
GRANT ALL ON *.* TO 'maxskysql'@'%' $require_ssl WITH GRANT OPTION;
DROP USER IF EXISTS 'maxskysql'@'localhost';
CREATE USER 'maxskysql'@'localhost' IDENTIFIED BY 'skysql';
GRANT ALL ON *.* TO 'maxskysql'@'localhost' WITH GRANT OPTION;
GRANT ALL ON *.* TO 'maxskysql'@'localhost' $require_ssl WITH GRANT OPTION;
DROP USER IF EXISTS 'maxuser'@'%';
CREATE USER 'maxuser'@'%' IDENTIFIED BY 'maxpwd';
GRANT ALL ON *.* TO 'maxuser'@'%' WITH GRANT OPTION;
GRANT ALL ON *.* TO 'maxuser'@'%' $require_ssl WITH GRANT OPTION;
DROP USER IF EXISTS 'maxuser'@'localhost';
CREATE USER 'maxuser'@'localhost' IDENTIFIED BY 'maxpwd';
GRANT ALL ON *.* TO 'maxuser'@'localhost' WITH GRANT OPTION;
GRANT ALL ON *.* TO 'maxuser'@'localhost' $require_ssl WITH GRANT OPTION;
RESET MASTER;
EOF

View File

@ -1,8 +1,4 @@
#!/bin/bash
echo "DROP USER '$node_user'@'%'" | sudo mysql $1
echo "grant all privileges on *.* to '$node_user'@'%' identified by '$node_password' require ssl WITH GRANT OPTION"
echo "grant all privileges on *.* to '$node_user'@'%' identified by '$node_password' require ssl WITH GRANT OPTION" | sudo mysql $1
echo "grant all privileges on *.* to 'maxskysql'@'%' identified by 'skysql' require ssl WITH GRANT OPTION" | sudo mysql $1
echo "grant all privileges on *.* to 'maxuser'@'%' identified by 'maxpwd' require ssl WITH GRANT OPTION" | sudo mysql $1
export require_ssl="REQUIRE SSL"
./create_user.sh $1