[MDEV-21778] Disable system commands in mysql/mariadb client Created: 2020-02-19 Updated: 2022-12-01 |
|
| Status: | Open |
| Project: | MariaDB Server |
| Component/s: | Scripts & Clients |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major |
| Reporter: | Ian Gilfillan | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 2 |
| Labels: | beginner-friendly | ||
| Description |
|
There may be circumstances where it makes sense to disable the system command in the mysql client. See https://mariadb.com/kb/en/how-to-disable-system-command-on-mariadb-shell, https://stackoverflow.com/questions/40958372/how-to-make-the-system-command-unavailable-in-mysql and https://bugs.mysql.com/bug.php?id=26941 for a MySQL patch that was never implemented. |
| Comments |
| Comment by Aman Alam Bora [ 2020-02-23 ] | ||||||||||||||||||||||||||||
|
Hi I'm trying for GSOC 2020 . I would like to work on this issue to get familiar with the code base. I would require some guidance as I'm new in this org as well as Jira. | ||||||||||||||||||||||||||||
| Comment by Ralf Gebhardt [ 2021-04-08 ] | ||||||||||||||||||||||||||||
|
To make the mariadb command line client "more secure" as requested, we do not only need to disable the system command, we also need to think about disabling for:
Another option would be to add chroot in the client and to be able to define a root directory for the client. | ||||||||||||||||||||||||||||
| Comment by Ralf Gebhardt [ 2022-01-21 ] | ||||||||||||||||||||||||||||
|
serg, to follow up on this. Do we really need the system command in the client, I am not sure if it is used that much. Do you have an opinion on that? chroot would of course also be a good option with the directory to be defined in the config file (and a good default). | ||||||||||||||||||||||||||||
| Comment by Sergei Golubchik [ 2022-01-21 ] | ||||||||||||||||||||||||||||
|
I've used it myself for backups. Like
that was, admittedly, long time ago and doesn't work all too well with InnoDB. Still, I suppose people use it. | ||||||||||||||||||||||||||||
| Comment by Valerii Kravchuk [ 2022-01-24 ] | ||||||||||||||||||||||||||||
|
System command is also useful while importing InnoDB tables, see http://mysqlentomologist.blogspot.com/2016/11/how-to-recover-corrupted-innodb.html for a typical way to use cp etc from inside mysql session. | ||||||||||||||||||||||||||||
| Comment by Ralf Gebhardt [ 2022-01-24 ] | ||||||||||||||||||||||||||||
|
serg, so it looks like using chroot is a good approach here. If you agree, does it need more details before somebody could work on this? | ||||||||||||||||||||||||||||
| Comment by Sergei Golubchik [ 2022-03-25 ] | ||||||||||||||||||||||||||||
|
anyone, it's a trivial patch. But it'll mean that mariadb client will need to be run as root. Is it acceptable? | ||||||||||||||||||||||||||||
| Comment by Laurent Blume [ 2022-03-25 ] | ||||||||||||||||||||||||||||
|
Hello, I'd just would like to know, what does "need to be run as root" mean here? Enabling the setuid bit? My original concern with system stems from this: when using unix_socket to authenticate MariaDB's root (something which is now the default setting in at least Ubuntu), then giving somebody root access to the database also means giving them root access to the system, which is not always desirable. Laurent | ||||||||||||||||||||||||||||
| Comment by Sergei Golubchik [ 2022-03-30 ] | ||||||||||||||||||||||||||||
|
I mean that only system root user can do chroot(). So for mariadb command client to do it, it must either be run by root or be setuid root. But let's get to your original concern. system command can only run commands as the user who started mariadb command line client. If root has started it, then those commands will be run as root. If non-root starts it, they'll be run as that user. When using unix_socket to authenticate MariaDB's root, then only system root will be able to connect as MariaDB root. But you can give anyone access to MariaDB root via a password, without giving system root privileges. Just login as root and issue
and you'll be able to connect with a password if you aren't system root. Connecting as system root will still work without a password (good for scripts and for resetting the password when needed). | ||||||||||||||||||||||||||||
| Comment by Laurent Blume [ 2022-03-30 ] | ||||||||||||||||||||||||||||
|
That's where I'm coming from | ||||||||||||||||||||||||||||
| Comment by Sergei Golubchik [ 2022-03-31 ] | ||||||||||||||||||||||||||||
|
So, you want to have only system root access to mariadb root, and you configure /etc/sudoers so that other users will be able to run mysql client as root, but not any other commands? Yes, in this case chroot approach will work and will do what you need. A more database centric approach would be to create a role, say, "admin" and grant it to those users that you want to be root-like. Say,
After that, say, Tom will be able to login without a password as tom, and then he'll be able to set the admin role to do root stuff:
That is, a user can login without a password as himself — just as you like. And then the user can assume the superuser role if needed, but can also work as non-superuser normally, so it doesn't mean that Tom becomes a superuser. Pretty much like you'd have with sudo and /etc/sudoers approach. But without a dangerous system root access. | ||||||||||||||||||||||||||||
| Comment by Daniel Black [ 2022-03-31 ] | ||||||||||||||||||||||||||||
|
Less invasive than chroot that doesn't require elevated privs, set the process rlimit to 1
Sure some error handling is needed here.
| ||||||||||||||||||||||||||||
| Comment by Daniel Black [ 2022-04-01 ] | ||||||||||||||||||||||||||||
|
Other non-code solutions:
| ||||||||||||||||||||||||||||
| Comment by Sergei Golubchik [ 2022-04-01 ] | ||||||||||||||||||||||||||||
|