From SELinux Wiki
Revision as of 15:56, 22 October 2009 by JoshuaBrindle (Talk | contribs)

Jump to: navigation, search


This is the project page for the integration of SELinux policy into RPM 4. Specifically the project is focused on adding infrastructure to RPM to install and manage SELinux policies and reduce the error-prone scriptlets that have been used up to now to install policy from RPM's.

Getting the Code

First clone the upstream RPM git repo. Instructions are available on the RPM get source page.


Apply the patches to the RPM repo.

Building and installing the code

  1. ./autogen.sh --noconfigure
  2. ./configure CPPFLAGS="-I/usr/include/nspr4 -I/usr/include/nss3 -I/usr/include/db4" --with-external-db --prefix=/u sr --sysconfdir=/etc --localstatedir=/var --sharedstatedir=/var/lib --with-lua --with-selinux
  3. make
  4. make install

Adding a policy to an RPM

You'll want a source module with the te, if and fc files. You can get one from the Reference Policy or use the one in the repo at rpm/tests/data/SOURCES/poltest-policy-1.0.tar.bz2

Add a Source line to your RPM:

Source1: poltest-policy-%{version}.tar.bz2

Build the policy during %build:

make -f /usr/share/selinux/devel/Makefile -C poltest-policy-%{version}

and specify the policy options using a %policy block:

%module poltest-policy-%{version}/foo.pp
        Name: foo

The name field is required and must match the name declared in the module.

Installing an RPM with a policy

Installing an RPM will also install its policy.

# rpm -i <rpm>

Verifying the policy is installed

# semodule -l | grep foo
foo    1.0.0

Specifying policy type

If your policy only works with a specific policy type (eg., targeted, mls, etc) you can specify that with Types:

%module poltest-policy-%{version}/foo.pp
        Name: foo
        Type: mls

This will only install the module if the current active policy type is "mls" (you can check by looking at the SELINUXTYPE variable in /etc/selinux/config.

If Type is omitted the policy will install on whatever the current policy type is.

Obsoleting a policy module

To obsolete a module you specify which modules are obsoleted with Obsoletes:

%module poltest-policy-%{version}/foo.pp
        Name: foo
        Obsoletes: baz

This will remove the baz module at the same time as installing the foo module.

Multiple modules

You can specify as many modules as necessary in the %policy block

%module poltest-policy-%{version}/foo.pp
        Name: foo
        Types: default
%module poltest-policy-%{version}/bar.pp
        Name: bar
        Types: mls targeted


You can specify a dependency that is used only when policy is being installed with %PolicyRequires

%PolicyRequires policycoreutils 

nopolicy and root

If you specify the --nopolicy flag when running RPM the policy will not get installed. Additionally if you are installing RPM's into a chroot with --root the policies will be installed in the chroot but the policy _will not_ be reloaded.