SlideShare una empresa de Scribd logo
1 de 7
Descargar para leer sin conexión
777
Customizing SELinux Policy
46.1. Introduction
In earlier releases of Red Hat Enterprise Linux it was necessary to install the selinux-policy-
targeted-sources packages and then to create a local.te file in the /etc/selinux/
targeted/src/policy/domains/misc directory. You could use the audit2allow utility to
translate the AVC messages into allow rules, and then rebuild and reload the policy.
The problem with this was that every time a new policy package was released it would have to
execute the Makefile in order to try to keep the local policy.
In Red Hat Enterprise Linux 5, this process has been completely revised. The "sources" rpm packages
have been completely removed, and policy packages are treated more like the kernel. To look
at the sources used to build the policy, you need to install the source rpm, selinux-policy-
XYZ.src.rpm. A further package, selinux-policy-devel, has also been added, which provides
further customization functionality.
46.1.1. Modular Policy
Red Hat Enterprise Linux introduces the concept of modular policy. This allows vendors to ship
SELinux policy separately from the operating system policy. It also allows administrators to make local
changes to policy without worrying about the next policy install. The most important command that was
added was semodule.
semodule is the tool used to manage SELinux policy modules, including installing, upgrading, listing
and removing modules. You can also use semodule to force a rebuild of policy from the module
store and/or to force a reload of policy without performing any other transaction. semodule acts
on module packages created by semodule_package. Conventionally, these files have a .pp suffix
(policy package), although this is not mandated in any way.
46.1.1.1. Listing Policy Modules
To list the policy modules on a system, use the semodule -l command:
[root@host2a ~]# semodule -l
amavis 1.1.0
ccs 1.0.0
clamav 1.1.0
dcc 1.1.0
evolution 1.1.0
iscsid 1.0.0
mozilla 1.1.0
mplayer 1.1.0
nagios 1.1.0
oddjob 1.0.1
pcscd 1.0.0
pyzor 1.1.0
razor 1.1.0
ricci 1.0.0
smart mon 1.1.0
778
Capítulo 46. Customizing SELinux Policy
Note
This command does not list the base policy module, which is also installed.
The /usr/share/selinux/targeted/ directory contains a number of policy
package (*.pp) files. These files are included in the selinux-policy rpm and are
used to build the policy file.
46.2. Building a Local Policy Module
The following section uses an actual example to demonstrate building a local policy module to address
an issue with the current policy. This issue involves the ypbind init script, which executes the
setsebool command, which in turn tries to use the terminal. This is generating the following denial:
type=AVC msg=audit(1164222416.269:22): avc: denied { use } for pid=1940 comm="setsebool"
name="0" dev=devpts ino=2 
scontext=system_u:system_r:semanage_t:s0 tc onte xt=syste m_u:syste m_r:init_t:s0 tc lass=fd
Even though everything still works correctly (that is, it is not preventing any applications form running
as intended), it does interrupt the normal work flow of the user. Creating a local policy module
addresses this issue.
46.2.1. Using audit2allow to Build a Local Policy Module
The audit2allow utility now has the ability to build policy modules. Use the following command to
build a policy module based on specific contents of the audit.log file:
ausearch -m AVC --comm setsebool | audit2allow -M mysemanage
The audit2allow utility has built a type enforcement file (mysemanage.te). It then executed
the check module command to compile a module file (mysemanage.mod). Lastly, it uses
the semodule_package command to create a policy package (mysemanage.pp). The
semodule_package command combines different policy files (usually just the module and potentially
a file context file) into a policy package.
46.2.2. Analyzing the Type Enforcement (TE) File
Use the cat command to inspect the contents of the TE file:
[root@host2a ~]# cat mysemanag.te
module mysemanage 1.0;
require {
cla ss fd use ;
type init_t;
type semanage_t;
role syste m_r;
};
allow semanage_t init_t:fd use;
779
Loading the Policy Package
The TE file is comprised of three sections. The first section is the module command, which identifies
the module name and version. The module name must be unique. If you create an semanage module
using the name of a pre-existing module, the system would try to replace the existing module package
with the newly-created version. The last part of the module line is the version. semodule can update
module packages and checks the update version against the currently installed version.
The next block of the TE file is the require block. This informs the policy loader which types, classes
and roles are required in the system policy before this module can be installed. If any of these fields
are undefined, the semodule command will fail.
Lastly are the allow rules. In this example, you could modify this line to dontaudit, because
semodule does not need to access the file descriptor.
46.2.3. Loading the Policy Package
The last step in the process of creating a local policy module is to load the policy package into the
kernel.
Use the semodule command to load the policy package:
[root@host2a ~]# semodule -i mysemana ge.pp
This command recompiles the policy file and regenerates the file context file. The changes are
permanent and will survive a reboot. You can also copy the policy package file (mysemanage.pp) to
other machines and install it using semodule.
The audit2allow command outputs the commands it executed to create the policy package so that
you can edit the TE file. This means you can add new rules as required or change the allow rule to
dontaudit. You could then recompile and repackage the policy package to be installed again.
There is no limit to the number of policy packages, so you could create one for each local modification
you want to make. Alternatively, you could continue to edit a single package, but you need to ensure
that the "require" statements match all of the allow rules.
780
781
Referencias
Las siguientes referencias apuntan a información adicional que es relevante a SELinux y Red Hat
Enterprise Linux pero que va más allá del propósito de este manual. Tenga en cuenta que debido
al rápido desarrollo de SELinux, este material podría ser aplicable únicamente a un lanzamiento
específico de Red Hat Enterprise Linux.
Libros
SELinux by Example
Mayer, MacMillan, and Caplan
Prentice Hall, 2007
Tutoriales y ayuda
Understanding and Customizing the Apache HTTP SELinux Policy
http://docs.fedoraproject.org/selinux-apache-fc3/
Tutorials and talks from Russell Coker
http://www.coker.com.au/selinux/talks/ibmtu-2004/
Generic Writing SELinux policy HOWTO
https://sourceforge.net/docman/display_doc.php?docid=21959[amp ]group_id=21266
1
Red Hat Knowledgebase
http://kbase.redhat.com/
Información general
Sitio web principal de NSA SELinux
http://www.nsa.gov/research/selinux/index.shtml
NSA SELinux, Preguntas frecuentes
http://www.nsa.gov/research/selinux/faqs.shtml
Fedora SELinux, Preguntas frecuentes
http://docs.fedoraproject.org/selinux-faq/
SELinux NSA's Open Source Security Enhanced Linux
http://www.oreilly.com/catalog/selinux/
Tecnologías
An Overview of Object Classes and Permissions
http://www.tresys.com/selinux/obj_perms_help.html
Integrating Flexible Support for Security Policies into the Linux Operating System (una historia de la
implementación de Flask en Linux, artículo en inglés)
http://www.nsa.gov/research/_files/selinux/papers/freenix01/freenix01.shtml
1
https://sourceforge.net/docman/display_doc.php?docid=21959[amp ]group_id=21266
Capítulo 47. Referencias
782
Implementing SELinux as a Linux Security Module
http://www.nsa.gov/research/selinux/index.shtmlpapers/module-abs.cfm
A Security Policy Configuration for the Security-Enhanced Linux
http://www.nsa.gov/research/_files/selinux/papers/policy/policy.shtml
Comunidad
Página de la comunidad SELinux
http://selinux.sourceforge.net
IRC
irc.freenode.net, #rhel-selinux
Capítulo 47. Referencias
783
Historia
Quick history of Flask
http://www.cs.utah.edu/flux/fluke/html/flask.html
Full background on Fluke
http://www.cs.utah.edu/flux/fluke/html/index.html

Más contenido relacionado

Similar a 46 customizing se linux policy

Unix Automation using centralized configuration management tool
Unix Automation using centralized configuration management toolUnix Automation using centralized configuration management tool
Unix Automation using centralized configuration management tool
Torrid Networks Private Limited
 
Unix Automation using centralized configuration management tool
Unix Automation using centralized configuration management toolUnix Automation using centralized configuration management tool
Unix Automation using centralized configuration management tool
Torrid Networks Private Limited
 
CMSIS_RTOS_Tutorial.pdf
CMSIS_RTOS_Tutorial.pdfCMSIS_RTOS_Tutorial.pdf
CMSIS_RTOS_Tutorial.pdf
chau44
 
Cgroup resource mgmt_v1
Cgroup resource mgmt_v1Cgroup resource mgmt_v1
Cgroup resource mgmt_v1
sprdd
 
Cgroup resource mgmt_v1
Cgroup resource mgmt_v1Cgroup resource mgmt_v1
Cgroup resource mgmt_v1
sprdd
 
Exploit Frameworks
Exploit FrameworksExploit Frameworks
Exploit Frameworks
phanleson
 
SELinux concept in rhel_Linux_today.pptx
SELinux concept in rhel_Linux_today.pptxSELinux concept in rhel_Linux_today.pptx
SELinux concept in rhel_Linux_today.pptx
AbhradipChatterjee2
 
MKT 100Week 6 Assignment{Enter Student Name Here}{Enter Bu.docx
MKT 100Week 6 Assignment{Enter Student Name Here}{Enter Bu.docxMKT 100Week 6 Assignment{Enter Student Name Here}{Enter Bu.docx
MKT 100Week 6 Assignment{Enter Student Name Here}{Enter Bu.docx
kendalfarrier
 

Similar a 46 customizing se linux policy (20)

Deploy Application Files with Git
Deploy Application Files with GitDeploy Application Files with Git
Deploy Application Files with Git
 
Readme
ReadmeReadme
Readme
 
Managing Perl Installations: A SysAdmin's View
Managing Perl Installations: A SysAdmin's ViewManaging Perl Installations: A SysAdmin's View
Managing Perl Installations: A SysAdmin's View
 
SELinux Basic Usage
SELinux Basic UsageSELinux Basic Usage
SELinux Basic Usage
 
The Domino 10 RHEL 7 Primer
The Domino 10 RHEL 7 PrimerThe Domino 10 RHEL 7 Primer
The Domino 10 RHEL 7 Primer
 
Unix Automation using centralized configuration management tool
Unix Automation using centralized configuration management toolUnix Automation using centralized configuration management tool
Unix Automation using centralized configuration management tool
 
Unix Automation using centralized configuration management tool
Unix Automation using centralized configuration management toolUnix Automation using centralized configuration management tool
Unix Automation using centralized configuration management tool
 
Drupal Modules
Drupal ModulesDrupal Modules
Drupal Modules
 
Upgrading to MySQL 8.0 webinar slides November 27th, 2019
Upgrading to MySQL 8.0 webinar slides November 27th, 2019Upgrading to MySQL 8.0 webinar slides November 27th, 2019
Upgrading to MySQL 8.0 webinar slides November 27th, 2019
 
CMSIS_RTOS_Tutorial.pdf
CMSIS_RTOS_Tutorial.pdfCMSIS_RTOS_Tutorial.pdf
CMSIS_RTOS_Tutorial.pdf
 
2008-07-30 IBM Teach the Teacher (IBM T3), Red Hat Update for System z
2008-07-30 IBM Teach the Teacher (IBM T3), Red Hat Update for System z2008-07-30 IBM Teach the Teacher (IBM T3), Red Hat Update for System z
2008-07-30 IBM Teach the Teacher (IBM T3), Red Hat Update for System z
 
First steps on CentOs7
First steps on CentOs7First steps on CentOs7
First steps on CentOs7
 
Odoo (Build module, Security, ORM)
Odoo (Build module, Security, ORM)Odoo (Build module, Security, ORM)
Odoo (Build module, Security, ORM)
 
Puppet quick start guide
Puppet quick start guidePuppet quick start guide
Puppet quick start guide
 
AtoZ about TYPO3 v8 CMS
AtoZ about TYPO3 v8 CMSAtoZ about TYPO3 v8 CMS
AtoZ about TYPO3 v8 CMS
 
Cgroup resource mgmt_v1
Cgroup resource mgmt_v1Cgroup resource mgmt_v1
Cgroup resource mgmt_v1
 
Cgroup resource mgmt_v1
Cgroup resource mgmt_v1Cgroup resource mgmt_v1
Cgroup resource mgmt_v1
 
Exploit Frameworks
Exploit FrameworksExploit Frameworks
Exploit Frameworks
 
SELinux concept in rhel_Linux_today.pptx
SELinux concept in rhel_Linux_today.pptxSELinux concept in rhel_Linux_today.pptx
SELinux concept in rhel_Linux_today.pptx
 
MKT 100Week 6 Assignment{Enter Student Name Here}{Enter Bu.docx
MKT 100Week 6 Assignment{Enter Student Name Here}{Enter Bu.docxMKT 100Week 6 Assignment{Enter Student Name Here}{Enter Bu.docx
MKT 100Week 6 Assignment{Enter Student Name Here}{Enter Bu.docx
 

Más de Aprende Viendo

44 seguridad y se linux
44  seguridad y se linux44  seguridad y se linux
44 seguridad y se linux
Aprende Viendo
 
43 aseguramiento de su red
43  aseguramiento de su red43  aseguramiento de su red
43 aseguramiento de su red
Aprende Viendo
 
42 seguridad y autenticación
42  seguridad y autenticación42  seguridad y autenticación
42 seguridad y autenticación
Aprende Viendo
 
41 parámetros y módulos generales
41  parámetros y módulos generales41  parámetros y módulos generales
41 parámetros y módulos generales
Aprende Viendo
 
40 configuración del kernel y dispositivos
40  configuración del kernel y dispositivos40  configuración del kernel y dispositivos
40 configuración del kernel y dispositivos
Aprende Viendo
 
38 reunir información del sistema
38  reunir información del sistema38  reunir información del sistema
38 reunir información del sistema
Aprende Viendo
 
37 supervisión del sistema
37  supervisión del sistema37  supervisión del sistema
37 supervisión del sistema
Aprende Viendo
 
36 archivos de registro
36  archivos de registro36  archivos de registro
36 archivos de registro
Aprende Viendo
 
34 configuración de la impresora
34  configuración de la impresora34  configuración de la impresora
34 configuración de la impresora
Aprende Viendo
 
32 configuración del sistema x window
32  configuración del sistema x window32  configuración del sistema x window
32 configuración del sistema x window
Aprende Viendo
 
31 el sistema x window
31  el sistema x window31  el sistema x window
31 el sistema x window
Aprende Viendo
 
29 configuración de la fecha y hora
29  configuración de la fecha y hora29  configuración de la fecha y hora
29 configuración de la fecha y hora
Aprende Viendo
 
27 configuración del sistema
27  configuración del sistema27  configuración del sistema
27 configuración del sistema
Aprende Viendo
 
28 el directorio sysconfig
28  el directorio sysconfig28  el directorio sysconfig
28 el directorio sysconfig
Aprende Viendo
 
25 protocolo ligero de acceso a directorios ldap
25  protocolo ligero de acceso a directorios ldap25  protocolo ligero de acceso a directorios ldap
25 protocolo ligero de acceso a directorios ldap
Aprende Viendo
 
24 correo electrónico
24  correo electrónico24  correo electrónico
24 correo electrónico
Aprende Viendo
 

Más de Aprende Viendo (20)

44 seguridad y se linux
44  seguridad y se linux44  seguridad y se linux
44 seguridad y se linux
 
43 aseguramiento de su red
43  aseguramiento de su red43  aseguramiento de su red
43 aseguramiento de su red
 
42 seguridad y autenticación
42  seguridad y autenticación42  seguridad y autenticación
42 seguridad y autenticación
 
41 parámetros y módulos generales
41  parámetros y módulos generales41  parámetros y módulos generales
41 parámetros y módulos generales
 
40 configuración del kernel y dispositivos
40  configuración del kernel y dispositivos40  configuración del kernel y dispositivos
40 configuración del kernel y dispositivos
 
39 o profile
39  o profile39  o profile
39 o profile
 
38 reunir información del sistema
38  reunir información del sistema38  reunir información del sistema
38 reunir información del sistema
 
37 supervisión del sistema
37  supervisión del sistema37  supervisión del sistema
37 supervisión del sistema
 
36 archivos de registro
36  archivos de registro36  archivos de registro
36 archivos de registro
 
35 automated tasks
35  automated tasks35  automated tasks
35 automated tasks
 
34 configuración de la impresora
34  configuración de la impresora34  configuración de la impresora
34 configuración de la impresora
 
33 usuarios y grupos
33  usuarios y grupos33  usuarios y grupos
33 usuarios y grupos
 
32 configuración del sistema x window
32  configuración del sistema x window32  configuración del sistema x window
32 configuración del sistema x window
 
31 el sistema x window
31  el sistema x window31  el sistema x window
31 el sistema x window
 
29 configuración de la fecha y hora
29  configuración de la fecha y hora29  configuración de la fecha y hora
29 configuración de la fecha y hora
 
27 configuración del sistema
27  configuración del sistema27  configuración del sistema
27 configuración del sistema
 
28 el directorio sysconfig
28  el directorio sysconfig28  el directorio sysconfig
28 el directorio sysconfig
 
25 protocolo ligero de acceso a directorios ldap
25  protocolo ligero de acceso a directorios ldap25  protocolo ligero de acceso a directorios ldap
25 protocolo ligero de acceso a directorios ldap
 
24 correo electrónico
24  correo electrónico24  correo electrónico
24 correo electrónico
 
22 apache http server
22  apache http server22  apache http server
22 apache http server
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Último (20)

DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 

46 customizing se linux policy

  • 1. 777 Customizing SELinux Policy 46.1. Introduction In earlier releases of Red Hat Enterprise Linux it was necessary to install the selinux-policy- targeted-sources packages and then to create a local.te file in the /etc/selinux/ targeted/src/policy/domains/misc directory. You could use the audit2allow utility to translate the AVC messages into allow rules, and then rebuild and reload the policy. The problem with this was that every time a new policy package was released it would have to execute the Makefile in order to try to keep the local policy. In Red Hat Enterprise Linux 5, this process has been completely revised. The "sources" rpm packages have been completely removed, and policy packages are treated more like the kernel. To look at the sources used to build the policy, you need to install the source rpm, selinux-policy- XYZ.src.rpm. A further package, selinux-policy-devel, has also been added, which provides further customization functionality. 46.1.1. Modular Policy Red Hat Enterprise Linux introduces the concept of modular policy. This allows vendors to ship SELinux policy separately from the operating system policy. It also allows administrators to make local changes to policy without worrying about the next policy install. The most important command that was added was semodule. semodule is the tool used to manage SELinux policy modules, including installing, upgrading, listing and removing modules. You can also use semodule to force a rebuild of policy from the module store and/or to force a reload of policy without performing any other transaction. semodule acts on module packages created by semodule_package. Conventionally, these files have a .pp suffix (policy package), although this is not mandated in any way. 46.1.1.1. Listing Policy Modules To list the policy modules on a system, use the semodule -l command: [root@host2a ~]# semodule -l amavis 1.1.0 ccs 1.0.0 clamav 1.1.0 dcc 1.1.0 evolution 1.1.0 iscsid 1.0.0 mozilla 1.1.0 mplayer 1.1.0 nagios 1.1.0 oddjob 1.0.1 pcscd 1.0.0 pyzor 1.1.0 razor 1.1.0 ricci 1.0.0 smart mon 1.1.0
  • 2. 778 Capítulo 46. Customizing SELinux Policy Note This command does not list the base policy module, which is also installed. The /usr/share/selinux/targeted/ directory contains a number of policy package (*.pp) files. These files are included in the selinux-policy rpm and are used to build the policy file. 46.2. Building a Local Policy Module The following section uses an actual example to demonstrate building a local policy module to address an issue with the current policy. This issue involves the ypbind init script, which executes the setsebool command, which in turn tries to use the terminal. This is generating the following denial: type=AVC msg=audit(1164222416.269:22): avc: denied { use } for pid=1940 comm="setsebool" name="0" dev=devpts ino=2 scontext=system_u:system_r:semanage_t:s0 tc onte xt=syste m_u:syste m_r:init_t:s0 tc lass=fd Even though everything still works correctly (that is, it is not preventing any applications form running as intended), it does interrupt the normal work flow of the user. Creating a local policy module addresses this issue. 46.2.1. Using audit2allow to Build a Local Policy Module The audit2allow utility now has the ability to build policy modules. Use the following command to build a policy module based on specific contents of the audit.log file: ausearch -m AVC --comm setsebool | audit2allow -M mysemanage The audit2allow utility has built a type enforcement file (mysemanage.te). It then executed the check module command to compile a module file (mysemanage.mod). Lastly, it uses the semodule_package command to create a policy package (mysemanage.pp). The semodule_package command combines different policy files (usually just the module and potentially a file context file) into a policy package. 46.2.2. Analyzing the Type Enforcement (TE) File Use the cat command to inspect the contents of the TE file: [root@host2a ~]# cat mysemanag.te module mysemanage 1.0; require { cla ss fd use ; type init_t; type semanage_t; role syste m_r; }; allow semanage_t init_t:fd use;
  • 3. 779 Loading the Policy Package The TE file is comprised of three sections. The first section is the module command, which identifies the module name and version. The module name must be unique. If you create an semanage module using the name of a pre-existing module, the system would try to replace the existing module package with the newly-created version. The last part of the module line is the version. semodule can update module packages and checks the update version against the currently installed version. The next block of the TE file is the require block. This informs the policy loader which types, classes and roles are required in the system policy before this module can be installed. If any of these fields are undefined, the semodule command will fail. Lastly are the allow rules. In this example, you could modify this line to dontaudit, because semodule does not need to access the file descriptor. 46.2.3. Loading the Policy Package The last step in the process of creating a local policy module is to load the policy package into the kernel. Use the semodule command to load the policy package: [root@host2a ~]# semodule -i mysemana ge.pp This command recompiles the policy file and regenerates the file context file. The changes are permanent and will survive a reboot. You can also copy the policy package file (mysemanage.pp) to other machines and install it using semodule. The audit2allow command outputs the commands it executed to create the policy package so that you can edit the TE file. This means you can add new rules as required or change the allow rule to dontaudit. You could then recompile and repackage the policy package to be installed again. There is no limit to the number of policy packages, so you could create one for each local modification you want to make. Alternatively, you could continue to edit a single package, but you need to ensure that the "require" statements match all of the allow rules.
  • 4. 780
  • 5. 781 Referencias Las siguientes referencias apuntan a información adicional que es relevante a SELinux y Red Hat Enterprise Linux pero que va más allá del propósito de este manual. Tenga en cuenta que debido al rápido desarrollo de SELinux, este material podría ser aplicable únicamente a un lanzamiento específico de Red Hat Enterprise Linux. Libros SELinux by Example Mayer, MacMillan, and Caplan Prentice Hall, 2007 Tutoriales y ayuda Understanding and Customizing the Apache HTTP SELinux Policy http://docs.fedoraproject.org/selinux-apache-fc3/ Tutorials and talks from Russell Coker http://www.coker.com.au/selinux/talks/ibmtu-2004/ Generic Writing SELinux policy HOWTO https://sourceforge.net/docman/display_doc.php?docid=21959[amp ]group_id=21266 1 Red Hat Knowledgebase http://kbase.redhat.com/ Información general Sitio web principal de NSA SELinux http://www.nsa.gov/research/selinux/index.shtml NSA SELinux, Preguntas frecuentes http://www.nsa.gov/research/selinux/faqs.shtml Fedora SELinux, Preguntas frecuentes http://docs.fedoraproject.org/selinux-faq/ SELinux NSA's Open Source Security Enhanced Linux http://www.oreilly.com/catalog/selinux/ Tecnologías An Overview of Object Classes and Permissions http://www.tresys.com/selinux/obj_perms_help.html Integrating Flexible Support for Security Policies into the Linux Operating System (una historia de la implementación de Flask en Linux, artículo en inglés) http://www.nsa.gov/research/_files/selinux/papers/freenix01/freenix01.shtml 1 https://sourceforge.net/docman/display_doc.php?docid=21959[amp ]group_id=21266
  • 6. Capítulo 47. Referencias 782 Implementing SELinux as a Linux Security Module http://www.nsa.gov/research/selinux/index.shtmlpapers/module-abs.cfm A Security Policy Configuration for the Security-Enhanced Linux http://www.nsa.gov/research/_files/selinux/papers/policy/policy.shtml Comunidad Página de la comunidad SELinux http://selinux.sourceforge.net IRC irc.freenode.net, #rhel-selinux
  • 7. Capítulo 47. Referencias 783 Historia Quick history of Flask http://www.cs.utah.edu/flux/fluke/html/flask.html Full background on Fluke http://www.cs.utah.edu/flux/fluke/html/index.html