mysql policy
I have a few questions about the mysql policy:
For me, starting it up via "run_init /etc/init.d/mysql start" doesn't work. There's a lot of messages like these:
Oct 28 12:47:23 nsa2 kernel: avc: denied { write } for pid=1376 exe=/usr/bin/tee path=/lib/mysql dev=03:04 ino=3014657 scontext=system_u:system_r:initrc_t tcontext=system_u:object_r:mysqld_db_t tclass=dir
Oct 28 12:47:24 nsa2 kernel: avc: denied { read } for pid=1377 exe=/usr/bin/mysqladmin path=/etc/mysql/my.cnf dev=03:01 ino=32610 scontext=system_u:system_r:initrc_t tcontext=system_u:object_r:etc_mysqld_t tclass=filePiped into newrules, it all boils down to:
allow initrc_t etc_mysqld_t:file { read };
allow initrc_t mysqld_db_t:dir { write };
Which tells me that run_init doesn't change context when it calls mysqladmin, which is part of the "safe_mysql" script.
Is this on purpose or a mistake? If it's on purpose, what is the workaround I'm missing to get mysql to start?
Signature · 8 lines
PGP/GPG key: http://web.lemuria.org/pubkey.html pub 1024D/2D7A04F5 2002-05-16 Tom Vogt <[email protected]> Key fingerprint = C731 64D1 4BCF 4C20 48A4 29B2 BF01 9FA1 2D7A 04F5 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 1 line · Tom
I have a few questions about the mysql policy:
Firstly when discussing my policy files please CC me (otherwise I am not guaranteed to receive the message).
Quoted 11 lines
For me, starting it up via "
run_init/etc/init.d/mysqlstart" doesn't work. There's a lot of messages like these:Oct 28 12:47:23 nsa2 kernel: avc: denied { write } for pid=1376exe=/usr/bin/tee path=/lib/mysql dev=03:04 ino=3014657 scontext=system_u:system_r:initrc_t tcontext=system_u:object_r:mysqld_db_t tclass=dir Oct 28 12:47:24 nsa2 kernel: avc: denied { read } for pid=1377 exe=/usr/bin/mysqladmin path=/etc/mysql/my.cnf dev=03:01 ino=32610 scontext=system_u:system_r:initrc_t tcontext=system_u:object_r:etc_mysqld_t tclass=file
Quoted 4 lines
Piped into newrules, it all boils down to:
allow
initrc_tetc_mysqld_t:file { read };
allowinitrc_tmysqld_db_t:dir { write };
It's not that uncommon for an init script to read the config file before starting a daemon. I'll change my policy in that regard.
For the tee thing, I think that the startup scripts you use are using tee to redirect stdout of the daemon to a file on disk as well. What version of the daemon are you using?
Signature · 10 lines
http://www.coker.com.au/selinux/ My NSA Security Enhanced Linux packages http://www.coker.com.au/bonnie++/ Bonnie++ hard drive benchmark http://www.coker.com.au/postal/ Postal SMTP/POP benchmark http://www.coker.com.au/~russell/ My home page -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 2 lines · Russell Coker
It's not that uncommon for an init script to read the config file before starting a daemon. I'll change my policy in that regard.
Right. The thing is, this is the mysqladmin program, not mysqld - mysqladmin is a commandline tool to administrate the database. Not sure if they should run in the same domain. Right now, mysqladmin is just a regular tool, i.e. bin_t.
Quoted 3 lines
For the tee thing, I think that the startup scripts you use are using tee to redirect stdout of the daemon to a file on disk as well. What version of the daemon are you using?
Current sid (updated today). I'm running the normal /etc/init.d/mysql script, nothing else. The /usr/bin/safe_mysqld script started from there does indeed contain a few tee commands.
Funny thing is, it worked flawlessly on friday. I made an update earlier today, so maybe a recent change broke it?
Signature · 8 lines
PGP/GPG key: http://web.lemuria.org/pubkey.html pub 1024D/2D7A04F5 2002-05-16 Tom Vogt <[email protected]> Key fingerprint = C731 64D1 4BCF 4C20 48A4 29B2 BF01 9FA1 2D7A 04F5 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 8 lines · Tom
Quoted 2 lines · Russell Coker
It's not that uncommon for an init script to read the config file before starting a daemon. I'll change my policy in that regard.
Right. The thing is, this is the mysqladmin program, not mysqld - mysqladmin is a commandline tool to administrate the database. Not sure if they should run in the same domain. Right now, mysqladmin is just a regular tool, i.e.
bin_t.
Being in bin_t means of course that there's no domain transition.
Maybe the right thing to do would be to have a separate domain for mysql admin, so initrc_t transitions to mysqld_admin_t which then transitions to mysqld_t when it runs the database server.
I haven't got into these things in any detail, you're probably the best person to work on this.
Quoted 2 lines
Funny thing is, it worked flawlessly on friday. I made an update earlier today, so maybe a recent change broke it?
That's not uncommon. Debian/unstable changes fast.
Signature · 10 lines
http://www.coker.com.au/selinux/ My NSA Security Enhanced Linux packages http://www.coker.com.au/bonnie++/ Bonnie++ hard drive benchmark http://www.coker.com.au/postal/ Postal SMTP/POP benchmark http://www.coker.com.au/~russell/ My home page -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 3 lines · Russell Coker
Maybe the right thing to do would be to have a separate domain for mysql admin, so
initrc_ttransitions tomysqld_admin_twhich then transitions tomysqld_twhen it runs the database server.
Funny thing is: It doesn't I don't understand why it's running mysaqladmin at all. Oh, well, I'll just find out.
Quoted 2 lines
I haven't got into these things in any detail, you're probably the best person to work on this.
So I'm now with apache and mysql. :)
That's fine with me as I'm working on that anyways. I'm currently fighting with apache2 and SSL. I'll get to apache1+SSL later.
Signature · 8 lines
PGP/GPG key: http://web.lemuria.org/pubkey.html pub 1024D/2D7A04F5 2002-05-16 Tom Vogt <[email protected]> Key fingerprint = C731 64D1 4BCF 4C20 48A4 29B2 BF01 9FA1 2D7A 04F5 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Here's a small patch to mysqld.te which solves the startup problem for me and lets mysqld run without any error.
I believe these changes do not open any security problems as they don't give init access to the databases. One could do away with the requirement to write into the /var/lib/mysql directory with a few changes to the safe_mysqld startup script, but I don't think it would make much of a difference, security-wise.
Signature · 3 lines
PGP/GPG key: http://web.lemuria.org/pubkey.html pub 1024D/2D7A04F5 2002-05-16 Tom Vogt <[email protected]> Key fingerprint = C731 64D1 4BCF 4C20 48A4 29B2 BF01 9FA1 2D7A 04F5
domains/program/mysqld.te 2002-10-28 17:32:28.000000000 +0100 renamed from domains/program/mysqld.te 2002-10-27 02:29:00.000000000 +0200 +4 -1
@@ -26,6 +26,8 @@ allow initrc_t var_run_mysqld_t:sock_file write; allow initrc_t mysqld_log_t:file { write append setattr ioctl }; +allow initrc_t etc_mysqld_t:file { read }; +allow initrc_t mysqld_db_t:dir { write }; allow mysqld_t self:capability { setgid setuid }; allow mysqld_t self:process getsched;
@@ -34,7 +36,8 @@ # Allow access to the mysqld databases create_dir_file(mysqld_t, mysqld_db_t) -allow mysqld_t var_lib_t:dir search; +allow mysqld_t var_lib_t:dir { getattr search }; + # read config files r_dir_file(mysqld_t, etc_mysqld_t)
Quoted 1 line · Tom
+allow
initrc_tmysqld_db_t:dir { write };
I'm not clear as to the purpose of this rule in isolation. Without other directory permissions (e.g. add_name, remove_name), directory write permission is useless. What exactly is the rc script doing to this directory?
--
Stephen D. Smalley, NAI Labs
[email protected]
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 6 lines · Stephen Smalley
Quoted 1 line
+allow
initrc_tmysqld_db_t:dir { write };I'm not clear as to the purpose of this rule in isolation. Without other directory permissions (e.g.
add_name,remove_name), directory write permission is useless. What exactly is the rc script doing to this directory?
If I remember correctly, it's tee'ing any errors during startup to an error log file that is located there. I'm working on this anyway, so if you don't feel happy with it, just wait until I have a more refined policy to offer. For some reason, though, adding this rule makes it work on my system.
Signature · 8 lines
http://web.lemuria.org/pubkey.html pub 1024D/2D7A04F5 2002-05-16 Tom Vogt <[email protected]> Key fingerprint = C731 64D1 4BCF 4C20 48A4 29B2 BF01 9FA1 2D7A 04F5 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 5 lines · Tom
If I remember correctly, it's tee'ing any errors during startup to an error log file that is located there. I'm working on this anyway, so if you don't feel happy with it, just wait until I have a more refined policy to offer. For some reason, though, adding this rule makes it work on my system.
mysqld_db_t is assigned to /var/lib/mysql. mysqld_log_t is assigned to/var/log/mysql.*. So I'm not clear as to why a log file would be
created in /var/lib/mysql. If it is (re)creating a file in /var/lib/mysql, then it should require search, write, and add_name permission to mysqld_db_t:dir as well as create permission to mysqld_db_t:file. If it is merely appending to an existing file, it should only need search permission to the directory and append permission to the file.
--
Stephen D. Smalley, NAI Labs
[email protected]
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 3 lines · Stephen Smalley
mysqld_db_tis assigned to/var/lib/mysql.mysqld_log_tis assigned to/var/log/mysql.*. So I'm not clear as to why a log file would be
created in/var/lib/mysql.
Neither am I. As I said: For some reason it works for me with this line, and it doesn't without. I will be checking this in more detail over the next days and submit a better patch.
Signature · 8 lines
http://web.lemuria.org/pubkey.html pub 1024D/2D7A04F5 2002-05-16 Tom Vogt <[email protected]> Key fingerprint = C731 64D1 4BCF 4C20 48A4 29B2 BF01 9FA1 2D7A 04F5 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 3 lines · Stephen Smalley
Quoted 1 line
+allow
initrc_tmysqld_db_t:dir { write };I'm not clear as to the purpose of this rule in isolation.
I understand it now, and I've attached a new mysql policy. There are some other weirdnesses in it, due to the specific way that mysqld works, especially all the wrapper scripts or the fact that mysqld (running in mysqld_t) is shut down by a call to mysqladmin (bin_t).
I've put more comments into this policy to make it more transparent why some rules are there.
This is not a patch since I've changed almost everything. I've decided to post full files instead for the discussion. I will test this policy for a few days before submitting it, then in patch form.
mysqld is a weird beast, especially with the wrapper script, and some tools that can't quite decide whether they want to be part of the server or not.
I've gone back and forth between defining new domains for the safe_mysqld wrapper or not (deciding on not for now), and I'm not yet sure whether it may be a good idea to put make the mysqladmin a mysqld_exec_t, too.
That's why I post this now - to get some feedback. This policy works for me, but I'm sure it can be improved.
Signature · 3 lines
PGP/GPG key: http://web.lemuria.org/pubkey.html pub 1024D/2D7A04F5 2002-05-16 Tom Vogt <[email protected]> Key fingerprint = C731 64D1 4BCF 4C20 48A4 29B2 BF01 9FA1 2D7A 04F5
#DESC mysql database server
#
# Authors: Russell Coker <[email protected]>
# Tom Vogt <[email protected]>
#
#################################
#
# Rules for the mysqld_t domain.
#
# mysqld_t is the type of the mysql daemon # daemon_domain(mysqld) domain_auto_trans(initrc_t, mysqld_exec_t, mysqld_t)
type etc_mysqld_t, file_type, sysadmfile; type mysqld_db_dir_t, file_type, sysadmfile; type mysqld_db_t, file_type, sysadmfile; type mysqld_log_t, file_type, sysadmfile, logfile;
#
# Permissions required by the initrc script and safe_mysqld wrapper # (both running in initrc_t)
#
allow initrc_t etc_mysqld_t:file { read };
# create error startup log in /var/lib/mysql
allow initrc_t mysqld_db_dir_t:dir { write };
file_type_auto_trans(initrc_t, mysqld_db_dir_t, mysqld_db_t)# touch /var/log/mysql and chown it to the mysql user allow initrc_t mysqld_log_t:dir rw_dir_perms; allow initrc_t mysqld_log_t:file create_file_perms;
# mysqladmin wants to talk to mysqld
allow initrc_t var_run_mysqld_t:sock_file { write };
allow initrc_t mysqld_t:unix_stream_socket { connectto };#
# Permissions for the daemon itself (mysqld)
#general_proc_read_access(mysqld_t) general_file_read_access(mysqld_t)
allow mysqld_t self:unix_stream_socket create_stream_socket_perms; allow mysqld_t self:fifo_file rw_file_perms;
allow mysqld_t self:process { getsched };
# read config files allow mysqld_t etc_mysqld_t:dir r_dir_perms; allow mysqld_t etc_t:lnk_file r_file_perms; allow mysqld_t etc_t:file r_file_perms; allow mysqld_t etc_mysqld_t:file r_file_perms;
# temp and log files
allow mysqld_t var_log_t:dir { search };
allow mysqld_t var_log_t:file { append };
allow mysqld_t mysqld_log_t:file { create append };
file_type_auto_trans(mysqld_t, var_log_t, mysqld_log_t)
allow mysqld_t tmp_t:dir r_dir_perms;# drop uid/gid
allow mysqld_t self:capability { setgid setuid };# read /etc/mtab allow mysqld_t etc_runtime_t:file r_file_perms;
# access the console
allow mysqld_t admin_tty_type:chr_file { read write };#
# The databases
#file_type_auto_trans(mysqld_t, mysqld_db_dir_t, mysqld_db_t) allow mysqld_t mysqld_db_dir_t:dir create_dir_perms; allow mysqld_t mysqld_db_t:dir create_dir_perms; allow mysqld_t mysqld_db_t:file create_file_perms;
# Let dpkg install the default DB correctly and start/stop the server ifdef(dpkg.te',
allow dpkg_t mysqld_exec_t:file { execute }; domain_auto_trans(dpkg_t, mysqld_exec_t, mysqld_t) file_type_auto_trans(dpkg_t, mysqld_db_dir_t, mysqld_db_t) ')
#
# Client tools, for the sysadm role, this is easy:
#
allow sysadm_t mysqld_t:unix_stream_socket { connectto };
# for normal users, we need to give them some other
# access rights, too:
allow user_t mysqld_t:unix_stream_socket { connectto };
allow user_t var_run_mysqld_t:sock_file { write };
allow user_t etc_mysqld_t:dir { search };
allow user_t etc_mysqld_t:file { read };
allow user_t mysqld_db_dir_t:dir { search };
allow user_t var_run_mysqld_t:dir { search };ifdef(logrotate.te', r_dir_file(logrotate_t, etc_mysqld_t)
allow logrotate_t mysqld_db_dir_t:dir search; allow logrotate_t var_run_mysqld_t:dir search; allow logrotate_t var_run_mysqld_t:sock_file write; can_unix_connect(logrotate_t, mysqld_t)
')
# mysql database server /usr/sbin/mysqld system_u:object_r:mysqld_exec_t /var/run/mysqld(/.*)? system_u:object_r:var_run_mysqld_t /var/log/mysql.* system_u:object_r:mysqld_log_t /var/lib/mysql system_u:object_r:mysqld_db_dir_t /var/lib/mysql/.* system_u:object_r:mysqld_db_t /etc/my.cnf system_u:object_r:etc_mysqld_t /etc/mysql(/.*)? system_u:object_r:etc_mysqld_t