Skip to content

Conversation

@rndmh3ro
Copy link
Member

According to CIS-recommendations, mysql logfiles and the datadir belong to the user mysql.
We do this exactly like this, however the config-files under /etc/mysql/* are checked that they belong to user root.

I know that having least privileges is a good idea and I'm in favor of this.
However I propose to let the config-files belong to user mysql, too, because:

  • It's easier to reason about if all mysql-files belong to the same user. The permissions should stay restrictive (640), so only the user that runs mysql has access to these files.
  • In operating systems that do not use systemd, mysql is initially started as root but then forks to user mysql. There it makes sense that root is the owner of the config. However in operating systems with systemd, the process is directly started as user mysql. This means that the process cannot read its config-files if they belong to root. (see: https://mariadb.com/kb/en/systemd/)

The mysql-docs state to this topic (https://dev.mysql.com/doc/mysql-secure-deployment-guide/8.0/en/secure-deployment-post-install.html#secure-deployment-startup-options):

shell> cd /etc
shell> touch my.cnf
shell> chown root:root my.cnf  
shell> chmod 644 my.cnf

While the config-file belongs to root here, it is readable by everyone.

Signed-off-by: Sebastian Gumprich [email protected]

Copy link
Member

@micheelengronne micheelengronne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You had me at least privileges 👍

@schurzi
Copy link
Contributor

schurzi commented Aug 21, 2020

I like the ability for mysql server to read the config file as user mysql, so no root privilege is needed to start the server. But I have some problems with changing the user of the file/folder to mysql, since this would enable the running mysql process to potentially overwrite it's own configuration file

So I think the best option would be to set owner to root and group to mysql for all files and directories, that contain configuration.

Signed-off-by: Sebastian Gumprich <[email protected]>
@rndmh3ro
Copy link
Member Author

Good idea @schurzi. This way its more secure and still works for systems with systemd.

Copy link
Member

@micheelengronne micheelengronne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems good to me.

@rndmh3ro rndmh3ro merged commit a2faf0b into master Aug 26, 2020
@rndmh3ro rndmh3ro deleted the use_mysql_user branch October 14, 2020 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants