Skip to content

Increase security by adding possibility to have 'root'@'localhost' and not only 'root'@'%' #231

Closed
@MorganLindqvist

Description

@MorganLindqvist

Hi,

I would like to increase the security in my mySQL docker installation by not allowing root to login from any computer that can access the port on the host.

I am used to that root only is allowed to login from localhost. Since we are talking about a docker container here I guess there can be arguments that one does not in all installations have access to the container itself and need to act as root from another computer.

I would however prefer if there was an option not to have root@% as the default and not the only option when installing.

If you have access to the computer hosting the docker container one can use the command "docker exec -it mysql mysql -u root -p" to run a mySQL client and access the server from localhost.

I was looking into adding files to the /docker-entrypoint-initdb.d/ folder but these files are executed before the commands related to the option MYSQL_ONETIME_PASSWORD is executed. Since the later rely on 'root'@'%' it is not possible to change from @'%' to @'localhost' in a script in this folder.

I see a number of ways to fix this.

  1. Add an option MYSQL_ROOT_HOST that have a default value of '%' (for backwards compatibility) but gives the user of the container the option to set it to 'localhost' or possibly another name that is used by the computer connecting to the docker container.

  2. Move the handling of the MYSQL_ONETIME_PASSWORD above the handling of docker-entrypoint-initdb.d. A user can then add .sql commands to it that changes the '%' for root to 'localhost' or whatever he/she prefers.

I am sure there are more options.

My proposal would be #1 above since I think this will highlight the possible security risk with having 'root'@'%' and give the user of the container the option to increase the security.

If we agree on a way forward I can create a pull-request.

/Morgan

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions