-
Notifications
You must be signed in to change notification settings - Fork 435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add do
command to update the authentication plugin of MySQL users
#1097
base: nightly
Are you sure you want to change the base?
Changes from 3 commits
820cebe
4d0042c
19802ea
a9e987e
d266f4b
24e8872
d56029f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- [Improvement] Add a do command to update the authentication plugin of existing MySQL users from mysql_native_password to caching_sha2_password for compatibility with MySQL v8.4.0 and above. (by @Danyal-Faheem) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,8 +12,9 @@ | |
from typing_extensions import ParamSpec | ||
|
||
from tutor import config as tutor_config | ||
from tutor import env, fmt, hooks | ||
from tutor import env, fmt, hooks, plugins | ||
from tutor.hooks import priorities | ||
from tutor.utils import get_mysql_change_authentication_plugin_query | ||
|
||
|
||
class DoGroup(click.Group): | ||
|
@@ -315,6 +316,43 @@ def sqlshell(args: list[str]) -> t.Iterable[tuple[str, str]]: | |
yield ("lms", command) | ||
|
||
|
||
@click.command(context_settings={"ignore_unknown_options": True}) | ||
@click.option( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should not be an option, but an argument, because it's mandatory. The command signature should not be:
but:
Moreover, we should be able to update all users with users=all:
|
||
"--users", | ||
is_flag=False, | ||
nargs=1, | ||
help="Specific users to upgrade the authentication plugin of. Requires comma-seperated values with no space in-between.", | ||
) | ||
def update_mysql_authentication_plugin(users: str) -> t.Iterable[tuple[str, str]]: | ||
""" | ||
Update the authentication plugin of MySQL users from mysql_native_password to caching_sha2_password | ||
Handy command used when upgrading to v8.4 of MySQL which deprecates mysql_native_password | ||
""" | ||
|
||
context = click.get_current_context().obj | ||
config = tutor_config.load(context.root) | ||
|
||
if not config["RUN_MYSQL"]: | ||
fmt.echo_info( | ||
f"You are not running MySQL (RUN_MYSQL=False). It is your " | ||
f"responsibility to update the authentication plugin of mysql users." | ||
) | ||
return | ||
|
||
users_to_update = users.split(",") if users else list(plugins.iter_loaded()) | ||
|
||
query = get_mysql_change_authentication_plugin_query( | ||
config, users_to_update, not users | ||
) | ||
|
||
mysql_command = ( | ||
"mysql --user={{ MYSQL_ROOT_USERNAME }} --password={{ MYSQL_ROOT_PASSWORD }} --host={{ MYSQL_HOST }} --port={{ MYSQL_PORT }} --database={{ OPENEDX_MYSQL_DATABASE }} " | ||
+ shlex.join(["-e", query]) | ||
) | ||
|
||
yield ("lms", mysql_command) | ||
|
||
|
||
def add_job_commands(do_command_group: click.Group) -> None: | ||
""" | ||
This is meant to be called with the `local/dev/k8s do` group commands, to add the | ||
|
@@ -397,5 +435,6 @@ def do_callback(service_commands: t.Iterable[tuple[str, str]]) -> None: | |
print_edx_platform_setting, | ||
settheme, | ||
sqlshell, | ||
update_mysql_authentication_plugin, | ||
] | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,11 @@ services: | |
--character-set-server=utf8mb4 | ||
--collation-server=utf8mb4_unicode_ci | ||
--binlog-expire-logs-seconds=259200 | ||
# We only require this option for MySQL 8.4 and above | ||
# Breaks MySQL for previous versions as this option does not exist on versions earlier than 8.4 | ||
{% if DOCKER_IMAGE_MYSQL.split(':')[-1] == "latest" or (DOCKER_IMAGE_MYSQL.split(':')[-1].split('.') | map('int') | list >= '8.4.0'.split('.') | map('int') | list) -%} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: we can set DOCKER_IMAGE_MYSQL.split(':')[-1] to a variable and use that in comparison. It will make the code readable. |
||
--mysql-native-password=ON | ||
{%- endif %} | ||
restart: unless-stopped | ||
user: "999:999" | ||
volumes: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this paragraph can be reworded to focus that for any particular user, the command expects the configuration settings in a certain format. Then, the myuser examples can be added afterwards/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated this paragraph.