O contexto do RHEL SELinux difere entre matchpathcon e restorecon

2

Estou usando o RHEL 6.3 e experimento um comportamento estranho com os comandos matchpathcon e restorecon SELinux. Para um arquivo específico, eu defini um contexto com semanage fcontext . Então, matchpathcon me diz que o arquivo deve ter o contexto que eu defini, mas restorecon faz o arquivo ter outro contexto. Não consigo entender o comportamento e acho que há algo errado.

Aqui está um exemplo para reproduzir esse comportamento (eu sou um usuário root):

$ cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 6.3 (Santiago)

$ sestatus 
SELinux status:                 enabled
SELinuxfs mount:                /selinux
Current mode:                   enforcing
Mode from config file:          enforcing
Policy version:                 24
Policy from config file:        targeted

Eu criaria um script init.d específico para iniciar um daemon HTTPD.

$ touch /etc/init.d/my-httpd
$ ls -Z /etc/init.d/my-httpd 
-rw-------. root root unconfined_u:object_r:etc_t:s0   /etc/init.d/my-httpd

Então, eu crio o contexto para esse arquivo e verifico que ele foi salvo.

$ semanage fcontext -a -t httpd_initrc_exec_t /etc/init.d/my-httpd
$ semanage fcontext -C -l
contexte fichier SELinux                           type               Contexte

/etc/init.d/my-httpd                               all files          system_u:object_r:httpd_initrc_exec_t:s0

matchpathcon -V /etc/init.d/my-httpd 
/etc/init.d/my-httpd has context unconfined_u:object_r:etc_t:s0, should be system_u:object_r:httpd_initrc_exec_t:s0

Então, tento restaurar o contexto para o que matchpathcon me disse.

restorecon -v /etc/init.d/my-httpd 
restorecon reset /etc/rc.d/init.d/my-httpd context unconfined_u:object_r:etc_t:s0->unconfined_u:object_r:initrc_exec_t:s0

$ ls -Z /etc/init.d/my-httpd 
-rw-------. root root unconfined_u:object_r:initrc_exec_t:s0 /etc/init.d/my-httpd

Neste momento, entendo que o contexto não foi definido como eu faria. Eu tento verificar novamente com matchpathcon , talvez httpd_initrc_exec_t seja um alias de initrc_exec_t.

matchpathcon -V /etc/init.d/my-httpd 
/etc/init.d/my-httpd has context unconfined_u:object_r:initrc_exec_t:s0, should be system_u:object_r:httpd_initrc_exec_t:s0

$ restorecon -v -F /etc/init.d/my-httpd 
restorecon reset /etc/rc.d/init.d/my-httpd context unconfined_u:object_r:initrc_exec_t:s0->system_u:object_r:initrc_exec_t:s0

$ matchpathcon -V /etc/init.d/my-httpd 
/etc/init.d/my-httpd has context system_u:object_r:initrc_exec_t:s0, should be system_u:object_r:httpd_initrc_exec_t:s0

Depois, tento corrigir manualmente o contexto com chcon , mas não é assim que quero fazer isso. É só para verificar a teoria do alias anterior.

$ chcon -t httpd_initrc_exec_t /etc/init.d/my-httpd 
$ ls -Z /etc/init.d/my-httpd 
-rw-------. root root system_u:object_r:httpd_initrc_exec_t:s0 /etc/init.d/my-httpd
$ matchpathcon -V /etc/init.d/my-httpd 
/etc/init.d/my-httpd verified.

$ restorecon -v /etc/init.d/my-httpd 
restorecon reset /etc/rc.d/init.d/my-httpd context system_u:object_r:httpd_initrc_exec_t:s0->system_u:object_r:initrc_exec_t:s0

Esses contextos não parecem ser aliases, mas ainda há um comportamento estranho com o comando restorecon , e planejei usar sua funcionalidade.

Existe outra maneira de definir este contexto do SELinux ou talvez eu tenha feito algo errado?

    
por Julien Vaslet 09.01.2014 / 10:27

1 resposta

1

O suporte da Red Hat me disse o caminho certo para operar. O contexto deve ser definido para /etc/rc.d/init.d/my-httpd e não para /etc/init.d/my-httpd .

$ semanage fcontext -d -t httpd_initrc_exec_t /etc/init.d/my-httpd
$ semanage fcontext -C -l
$ semanage fcontext -a -t httpd_initrc_exec_t /etc/rc.d/init.d/my-httpd
$ semanage fcontext -C -l
SELinux fcontext                                   type               Context

/etc/rc.d/init.d/my-httpd                          all files          system_u:object_r:httpd_initrc_exec_t:s0

Uma vez que o conjunto de regras de contexto correto, restorecon funciona no arquivo /etc/init.d/my-httpd .

ls -Z /etc/rc.d/init.d/my-httpd /etc/init.d/my-httpd
-rw-------. root root system_u:object_r:initrc_exec_t:s0 /etc/init.d/my-httpd
-rw-------. root root system_u:object_r:initrc_exec_t:s0 /etc/rc.d/init.d/my-httpd
$ restorecon /etc/init.d/my-httpd
$ ls -Z /etc/rc.d/init.d/my-httpd /etc/init.d/my-httpd
-rw-------. root root system_u:object_r:httpd_initrc_exec_t:s0 /etc/init.d/my-httpd
-rw-------. root root system_u:object_r:httpd_initrc_exec_t:s0 /etc/rc.d/init.d/my-httpd
    
por 14.01.2014 / 10:16

Tags