Uma segurança maior pode ser alcançada através de medidas simples, habilitadas por padrão, e gratuitas.
Como DBA, eu desabilitava o SELinux (Security-Enhanced Linux) imediatamente após a instalação do Linux. Este requisito é encontrado em muitos tutoriais de instalação do Oracle Database (incluindo os meus), e até mesmo na documentação ele passou a ser suportado apenas “recentemente”:
Starting with Oracle Database 11g Release 2 (11.2), the Security Enhanced Linux (SELinux) feature is supported for Oracle Linux 4, Red Hat Enterprise Linux 4, Oracle Linux 5, and Red Hat Enterprise Linux 5.
Fonte: http://docs.oracle.com/cd/E11882_01/install.112/e47689/inst_task.htm#LADBI1257
Eu passei a gostar do SELinux quando tomei vergonha na cara e aprendi como liberar regras específicas, ao invés de desabilita-lo completamente.
O primeiro passo é encontrar no log de auditoria o que você quer liberar. Eu começo com um tail -f , filtrando apenas pelo o que foi bloqueado (denied).
[root@Baltazar ~]# tail -f /var/log/audit/audit.log | grep denied type=AVC msg=audit(1500382051.594:1232278): avc: denied { read } for pid=1580 comm="mysql" name="my.cnf" dev="sda1" ino=1075313619 scontext=system_u:system_r:zabbix_agent_t:s0 tcontext=system_u:object_r:mysqld_etc_t:s0 tclass=file type=AVC msg=audit(1500382051.594:1232278): avc: denied { open } for pid=1580 comm="mysql" path="/etc/my.cnf" dev="sda1" ino=1075313619 scontext=system_u:system_r:zabbix_agent_t:s0 tcontext=system_u:object_r:mysqld_etc_t:s0 tclass=file type=AVC msg=audit(1500382054.711:1232279): avc: denied { read } for pid=1597 comm="mysql" name=".my.cnf" dev="sda1" ino=1662731 scontext=system_u:system_r:zabbix_agent_t:s0 tcontext=unconfined_u:object_r:mysqld_home_t:s0 tclass=file type=AVC msg=audit(1500382054.713:1232280): avc: denied { connectto } for pid=1597 comm="mysql" path="/var/lib/mysql/mysql.sock" scontext=system_u:system_r:zabbix_agent_t:s0 tcontext=system_u:system_r:mysqld_t:s0 tclass=unix_stream_socket ^C [root@Baltazar ~]#
Em seguida eu filtro mais um pouco, apenas pelo uso do arquivo /var/lib/mysql/mysql.sock, e apenas as últimas 10 ocorrências (pois podem ter muitas).
[root@Baltazar ~]# grep denied /var/log/audit/audit.log | grep /var/lib/mysql/mysql.sock | tail -10 type=AVC msg=audit(1500381682.845:1231190): avc: denied { connectto } for pid=30660 comm="mysqladmin" path="/var/lib/mysql/mysql.sock" scontext=system_u:system_r:zabbix_agent_t:s0 tcontext=system_u:system_r:mysqld_t:s0 tclass=unix_stream_socket type=AVC msg=audit(1500381683.655:1231192): avc: denied { connectto } for pid=30669 comm="mysql" path="/var/lib/mysql/mysql.sock" scontext=system_u:system_r:zabbix_agent_t:s0 tcontext=system_u:system_r:mysqld_t:s0 tclass=unix_stream_socket type=AVC msg=audit(1500381742.252:1231369): avc: denied { connectto } for pid=31071 comm="mysqladmin" path="/var/lib/mysql/mysql.sock" scontext=system_u:system_r:zabbix_agent_t:s0 tcontext=system_u:system_r:mysqld_t:s0 tclass=unix_stream_socket type=AVC msg=audit(1500381747.715:1231372): avc: denied { connectto } for pid=31133 comm="mysql" path="/var/lib/mysql/mysql.sock" scontext=system_u:system_r:zabbix_agent_t:s0 tcontext=system_u:system_r:mysqld_t:s0 tclass=unix_stream_socket type=AVC msg=audit(1500381802.073:1231557): avc: denied { connectto } for pid=31540 comm="mysqladmin" path="/var/lib/mysql/mysql.sock" scontext=system_u:system_r:zabbix_agent_t:s0 tcontext=system_u:system_r:mysqld_t:s0 tclass=unix_stream_socket type=AVC msg=audit(1500381806.706:1231560): avc: denied { connectto } for pid=31593 comm="mysql" path="/var/lib/mysql/mysql.sock" scontext=system_u:system_r:zabbix_agent_t:s0 tcontext=system_u:system_r:mysqld_t:s0 tclass=unix_stream_socket type=AVC msg=audit(1500381862.826:1231741): avc: denied { connectto } for pid=32149 comm="mysqladmin" path="/var/lib/mysql/mysql.sock" scontext=system_u:system_r:zabbix_agent_t:s0 tcontext=system_u:system_r:mysqld_t:s0 tclass=unix_stream_socket type=AVC msg=audit(1500382042.771:1232269): avc: denied { connectto } for pid=1380 comm="mysqladmin" path="/var/lib/mysql/mysql.sock" scontext=system_u:system_r:zabbix_agent_t:s0 tcontext=system_u:system_r:mysqld_t:s0 tclass=unix_stream_socket type=AVC msg=audit(1500382045.395:1232277): avc: denied { connectto } for pid=1506 comm="mysql" path="/var/lib/mysql/mysql.sock" scontext=system_u:system_r:zabbix_agent_t:s0 tcontext=system_u:system_r:mysqld_t:s0 tclass=unix_stream_socket type=AVC msg=audit(1500382054.713:1232280): avc: denied { connectto } for pid=1597 comm="mysql" path="/var/lib/mysql/mysql.sock" scontext=system_u:system_r:zabbix_agent_t:s0 tcontext=system_u:system_r:mysqld_t:s0 tclass=unix_stream_socket [root@Baltazar ~]#
E agora filtro mais um pouco, apenas pelo uso deste arquivo pelo programa mysqladmin, e apenas as últimas 10 ocorrências.
[root@Baltazar ~]# grep denied /var/log/audit/audit.log | grep /var/lib/mysql/mysql.sock | grep mysqladmin | tail -10 type=AVC msg=audit(1500381442.724:1230464): avc: denied { connectto } for pid=28107 comm="mysqladmin" path="/var/lib/mysql/mysql.sock" scontext=system_u:system_r:zabbix_agent_t:s0 tcontext=system_u:system_r:mysqld_t:s0 tclass=unix_stream_socket type=AVC msg=audit(1500381502.325:1230641): avc: denied { connectto } for pid=28804 comm="mysqladmin" path="/var/lib/mysql/mysql.sock" scontext=system_u:system_r:zabbix_agent_t:s0 tcontext=system_u:system_r:mysqld_t:s0 tclass=unix_stream_socket type=AVC msg=audit(1500381562.774:1230815): avc: denied { connectto } for pid=29547 comm="mysqladmin" path="/var/lib/mysql/mysql.sock" scontext=system_u:system_r:zabbix_agent_t:s0 tcontext=system_u:system_r:mysqld_t:s0 tclass=unix_stream_socket type=AVC msg=audit(1500381622.504:1231014): avc: denied { connectto } for pid=30222 comm="mysqladmin" path="/var/lib/mysql/mysql.sock" scontext=system_u:system_r:zabbix_agent_t:s0 tcontext=system_u:system_r:mysqld_t:s0 tclass=unix_stream_socket type=AVC msg=audit(1500381682.845:1231190): avc: denied { connectto } for pid=30660 comm="mysqladmin" path="/var/lib/mysql/mysql.sock" scontext=system_u:system_r:zabbix_agent_t:s0 tcontext=system_u:system_r:mysqld_t:s0 tclass=unix_stream_socket type=AVC msg=audit(1500381742.252:1231369): avc: denied { connectto } for pid=31071 comm="mysqladmin" path="/var/lib/mysql/mysql.sock" scontext=system_u:system_r:zabbix_agent_t:s0 tcontext=system_u:system_r:mysqld_t:s0 tclass=unix_stream_socket type=AVC msg=audit(1500381802.073:1231557): avc: denied { connectto } for pid=31540 comm="mysqladmin" path="/var/lib/mysql/mysql.sock" scontext=system_u:system_r:zabbix_agent_t:s0 tcontext=system_u:system_r:mysqld_t:s0 tclass=unix_stream_socket type=AVC msg=audit(1500381862.826:1231741): avc: denied { connectto } for pid=32149 comm="mysqladmin" path="/var/lib/mysql/mysql.sock" scontext=system_u:system_r:zabbix_agent_t:s0 tcontext=system_u:system_r:mysqld_t:s0 tclass=unix_stream_socket type=AVC msg=audit(1500382042.771:1232269): avc: denied { connectto } for pid=1380 comm="mysqladmin" path="/var/lib/mysql/mysql.sock" scontext=system_u:system_r:zabbix_agent_t:s0 tcontext=system_u:system_r:mysqld_t:s0 tclass=unix_stream_socket type=AVC msg=audit(1500382102.836:1232451): avc: denied { connectto } for pid=2113 comm="mysqladmin" path="/var/lib/mysql/mysql.sock" scontext=system_u:system_r:zabbix_agent_t:s0 tcontext=system_u:system_r:mysqld_t:s0 tclass=unix_stream_socket [root@Baltazar ~]#
Agora eu filtro para pegar a última ocorrência.
[root@Baltazar ~]# grep denied /var/log/audit/audit.log | grep /var/lib/mysql/mysql.sock | grep mysqladmin | tail -1 type=AVC msg=audit(1500382102.836:1232451): avc: denied { connectto } for pid=2113 comm="mysqladmin" path="/var/lib/mysql/mysql.sock" scontext=system_u:system_r:zabbix_agent_t:s0 tcontext=system_u:system_r:mysqld_t:s0 tclass=unix_stream_socket [root@Baltazar ~]#
A parte fácil é criar a regra – basta pegar esta ocorrência que você quer liberar, e direcionar para o programa audit2allow (transforma “auditoria” em “permissão”), que irá criar um arquivo com a regra.
[root@Baltazar ~]# grep denied /var/log/audit/audit.log | grep /var/lib/mysql/mysql.sock | grep mysqladmin | tail -1 | audit2allow -M MyPolicy ******************** IMPORTANT *********************** To make this policy package active, execute: semodule -i MyPolicy.pp [root@Baltazar ~]#
E o último passo é importar a regra com o comando semodule.
[root@Baltazar ~]# semodule -i MyPolicy.pp [root@Baltazar ~]#
Bom dia Portilho!
Muito obrigado por compartilhar e nos ensinar a pensar de forma diferente.
Um fraterno abraço,
Obrigado Wagner!
Grande abraço !
Eu aprendi sobre o SELinux logo no início deste ano quando também resolvi procurar entender como ele funciona. Assisti no YouTube a seguinte palestra: “SELinux for mere mortals”
https://www.youtube.com/watch?v=cNoVgDqqJmM&t=2814s
Opa, vídeo muito bom, obrigado Franky.
Não encontrei o programa gráfico que ele usa no final (system-config-linux) em CentOs 7. Encontrei o selinux-polgengui, instalado pelo pacote policycoreutils-gui.
Sim, eu também achei. O SELinux não é difícil, mas o pessoal acha mais fácil ignorá-lo do que assistir um vídeo de 1 hora, né?
Legal, não sabia desse pacote para Linux 7.
O pessoal tem coisa mais importante pra fazer, estreou temporada nova de várias séries. 😀