RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1848683 - [RFE] Ability to install custom SELinux module via Ansible
Summary: [RFE] Ability to install custom SELinux module via Ansible
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: rhel-system-roles
Version: 8.4
Hardware: All
OS: Linux
unspecified
low
Target Milestone: rc
: 8.0
Assignee: Rich Megginson
QA Contact: David Jež
Eliane Ramos Pereira
URL:
Whiteboard: role:selinux
Depends On: 1937938
Blocks:
TreeView+ depends on / blocked
 
Reported: 2020-06-18 18:16 UTC by Mauricio Teixeira
Modified: 2021-11-09 20:26 UTC (History)
7 users (show)

Fixed In Version: rhel-system-roles-1.1.0-1.el8
Doc Type: Enhancement
Doc Text:
.The `SELinux` role can now manage SELinux modules The `SElinux` RHEL System Role has the ability to manage SELinux modules. With this update, users can provide their own custom modules from `.pp` or `.cil` files, which allows for a more flexible SELinux policy management.
Clone Of:
Environment:
Last Closed: 2021-11-09 17:44:38 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Github linux-system-roles selinux pull 56 0 None open Add ability to manage SELinux modules 2020-11-12 19:27:32 UTC
Red Hat Product Errata RHBA-2021:4159 0 None None None 2021-11-09 17:44:53 UTC

Description Mauricio Teixeira 2020-06-18 18:16:34 UTC
1. Proposed title of this feature request

[RFE] Ability to install custom SELinux module via Ansible

2. Who is the customer behind the request?

Account: RED HAT IT/IS 5243891
TAM customer: yes
CSM customer: yes
Strategic: yes

3. What is the nature and description of the request?

Use case:

It would be desirable to be able to pass custom .te, .fc and .if files, which would then be compiled on demand in the target host, and installed as modules.

Optionally, the role should also be able to accept a pre-compiled .pp file, and install it.

4. Why does the customer need this? (List the business requirements here)

Custom in-house-built applications, or community applications not directly supported by official RHEL, may require custom SELinux rules.

5. How would the customer like to achieve this? (List the functional requirements here)

Introduce tasks to install .te, .fc and .if files, either by themselves or as a group, then compile them into a custom module, and enable the custom module on the target system.

A second run should be able to compare the checksum of the generated .pp file, with the currently running policy, and only reload if they differ. (requires bz#1731501).


6. For each functional requirement listed, specify how Red Hat and the customer can test to confirm the requirement is successfully implemented.

Red Hat IT maintain various in-house-built applications, and custom SELinux modules, which could be used for testing this feature.

7. Is there already an existing RFE upstream or in Red Hat Bugzilla?

No

8. Does the customer have any specific timeline dependencies and which release would they like to target (i.e. RHEL5, RHEL6)?

No

9. Is the sales team involved in this request and do they have any additional input?

No

10. List any affected packages or components.

rhel-system-roles/selinux

11. Would the customer be able to assist in testing this functionality if implemented?

Yes

Comment 4 Petr Lautrbach 2020-06-19 16:45:51 UTC
(In reply to Mauricio Teixeira from comment #0)
> 
> 3. What is the nature and description of the request?
> 
> Use case:
> 
> It would be desirable to be able to pass custom .te, .fc and .if files,
> which would then be compiled on demand in the target host, and installed as
> modules.


Is there a specific reason why to build SELinux modules on nodes? It would mean to install selinux-policy-devel, policycoreutils-devel, checkpolicy, m4, ... on every node a user wants to deploy a custom policy.

 
> Optionally, the role should also be able to accept a pre-compiled .pp file,
> and install it.

Or .cil files.

 
> 5. How would the customer like to achieve this? (List the functional
> requirements here)
> 
> Introduce tasks to install .te, .fc and .if files, either by themselves or
> as a group, then compile them into a custom module, and enable the custom
> module on the target system.


I'd say this should be core of the functionality - upload SELinux modules, either as .pp or .cil files, and install them with requested priority.

This basic functionality could be covered by a configuration like this:

    selinux_install_modules:
      - { path: 'mylocalpolicy1.pp', priority: 400 }
      - { path: 'mylocalpolicy2.cil', priority: 300 }

Then users would probably like to manage SELinux modules as well. e.g.

    selinux_modules:
      - { module: 'mylocalpolicy1', priority: 400, state: 'disabled' }
      - { module: 'mylocalpolicy2', priority: 300, state: 'absent' }

 
> A second run should be able to compare the checksum of the generated .pp
> file, with the currently running policy, and only reload if they differ.
> (requires bz#1731501).

It probably doesn't require bz#1731501, you can use 'semodule -E' to export used module and compare a new one with the exported one.

Comment 5 Rich Megginson 2020-06-22 16:10:21 UTC
Is it possible to "cross compile" a .pp file on e.g. RHEL7 and apply that file to RHEL8 and RHEL9 and Fedora and .....?  If not, then we have no choice but to install selinux-policy-devel, policycoreutils-devel, checkpolicy, m4, ... on every node a user wants to deploy a custom policy.  I don't think that will be a big problem - sure, for managing a 500 node cluster, and having to install all of those packages on every node will take a while, but is it a significant fraction of the time it takes to actually apply the policy (not to mention all of the other Ansible tasks for other roles outside of selinux . . .)

Comment 6 Petr Lautrbach 2020-06-22 19:53:26 UTC
It's possible to install one .pp or .cil file on all mentioned systems. You need to use the lowest supported policy modb version, i.e. build it on the lowest SELinux userspace version used on your nodes, and avoid classes and permissions which are unknown for any node. It should not be that hard if there's no interface used in .te file. Interfaces could bring permissions like 'compromise_kernel' which exists only on RHEL7 and such module could not be installed on Fedora.

Or a policy module could be built for different targets using chroots, containers, ... on the host and then just deployed on nodes as pre-built binary .pp, or pre-generated .cil file, and it would not be necessary to install development tools on nodes/servers.

Comment 7 Rich Megginson 2020-06-22 20:36:00 UTC
(In reply to Petr Lautrbach from comment #6)
> It's possible to install one .pp or .cil file on all mentioned systems. You
> need to use the lowest supported policy modb version, i.e. build it on the
> lowest SELinux userspace version used on your nodes, and avoid classes and
> permissions which are unknown for any node. It should not be that hard if
> there's no interface used in .te file. Interfaces could bring permissions
> like 'compromise_kernel' which exists only on RHEL7 and such module could
> not be installed on Fedora.

This sounds fragile, and sounds like it would involve a lot of conditional logic in Ansible to handle different cases (but I would think users would have to specify different .te files for different platforms/versions anyway if they wanted to take advantage of platform specific SELinux features - i.e. a myapp.te.rhel7 *and* a myapp.te.rhel8 - which we already mostly handle in the system roles).

> 
> Or a policy module could be built for different targets using chroots,
> containers, ... on the host and then just deployed on nodes as pre-built
> binary .pp, or pre-generated .cil file, and it would not be necessary to
> install development tools on nodes/servers.

Creating the necessary Ansible code to set up a .pp builder "farm" based on the minimal necessary combinations of platform/version; doing the builds; deploying the files, etc. is probably a man month i.e. quite complex to do in Ansible, and would involve considerations above and beyond the normal Ansible such as availability of chroots on the controller machine, availability of package repos for those chroots on the controller machine, availability of a container runtime, repos, availability of network/disk/ram/cpu resources on the builder machines, etc. etc.

What do we recommend (i.e. in official Red Hat documentation) for customers to do today, without Ansible, in order to manage SELinux policy across a large number of machines running heterogeneous platforms and versions?

Note that the simplest way to do this in Ansible will be to install the necessary selinux packages on the remote systems and compile the module there.  Coding that role can be done in a day, give or take.  I understand that it is inefficient in terms of the duplication of resources (network, cpu, disk, memory) used to install the same packages across multiple systems and compile the same .pp file across multiple systems, but this may be a case where the advantages of code simplicity outweighs the disadvantages.

Comment 8 Mauricio Teixeira 2020-06-22 20:52:45 UTC
As the original requester of this RFE, me and my team would prefer that the role accepts plain-text .te files, and compile them on-the-fly, because that would allow us to properly track the rules/modules changes in a version control system (Git).

An acceptable compromise would be providing two options: one for landing plain .te files (and building them), another for directly landing binary .pp files. This way the role user can choose whether they want to build the module themselves or not.

Another possible solution would be to have tasks that build the .pp files locally, before uploading them. The problem with that is any possibility of the user running SELinux modules which are incompatible with the destination host. One of those cases would be me running Fedora on my laptop, trying to run the role to install the module on a RHEL server. Or even me running RHEL8 attempting to install a module on RHEL7.

The case for having different .te or .pp files based on RHEL versions can be easily fixed appending the "ansible_distribution_major_version" fact against the file name or a directory.

Comment 9 Brian J. Atkisson 2020-06-22 21:10:55 UTC
Red Hat IT has been distributing .pp files for years with Puppet, just cased for the correct OS version. While not ideal, it works and has not been a huge management burden. Seems like something for a MVP, then add support for building from the .te files down the road. There is value in giving sysadmins the choice of building an OS-specific .pp or ensuring each node has the necessary devel packages installed on doing a .te build on the target system.

Comment 10 Petr Lautrbach 2020-06-23 07:19:40 UTC
How do you deploy binary rpms? Do you upload src.rpm on a node, and build it there before you install it?


> Creating the necessary Ansible code to set up a .pp builder "farm" based on
> the minimal necessary combinations of platform/version; doing the builds;
> deploying the files, etc. is probably a man month i.e. quite complex to do
> in Ansible, and would involve considerations above and beyond the normal
> Ansible such as availability of chroots on the controller machine,
> availability of package repos for those chroots on the controller machine,
> availability of a container runtime, repos, availability of
> network/disk/ram/cpu resources on the builder machines, etc. etc.

Does the "farm" need to be written in Ansible code? Could you a simple shell script in CI which would generate necessary binary components on every commit/release?


> What do we recommend (i.e. in official Red Hat documentation) for customers
> to do today, without Ansible, in order to manage SELinux policy across a
> large number of machines running heterogeneous platforms and versions?


I'm not sure about the past, but it's suggested to ship policy modification using <component>-selinux rpm package -  https://fedoraproject.org/wiki/SELinux/IndependentPolicy
so you don't even need this role as the policy is installed and managed by rpm

Comment 15 Rich Megginson 2020-06-23 15:18:50 UTC
(In reply to Petr Lautrbach from comment #10)
> How do you deploy binary rpms? Do you upload src.rpm on a node, and build it
> there before you install it?

See below.

> 
> 
> > Creating the necessary Ansible code to set up a .pp builder "farm" based on
> > the minimal necessary combinations of platform/version; doing the builds;
> > deploying the files, etc. is probably a man month i.e. quite complex to do
> > in Ansible, and would involve considerations above and beyond the normal
> > Ansible such as availability of chroots on the controller machine,
> > availability of package repos for those chroots on the controller machine,
> > availability of a container runtime, repos, availability of
> > network/disk/ram/cpu resources on the builder machines, etc. etc.
> 
> Does the "farm" need to be written in Ansible code? Could you a simple shell
> script in CI which would generate necessary binary components on every
> commit/release?

The "Ansible code" can be whatever you want it to be e.g. a "simple" shell script - Ansible will be just a wrapper around whatever is the ultimate implemenatation.

> 
> 
> > What do we recommend (i.e. in official Red Hat documentation) for customers
> > to do today, without Ansible, in order to manage SELinux policy across a
> > large number of machines running heterogeneous platforms and versions?
> 
> 
> I'm not sure about the past, but it's suggested to ship policy modification
> using <component>-selinux rpm package - 
> https://fedoraproject.org/wiki/SELinux/IndependentPolicy
> so you don't even need this role as the policy is installed and managed by
> rpm

I would think we wouldn't want to make customers who just want to tweak or provide custom SELinux policy to have to get into RPM management, but perhaps that is the price of admission into SELinux policy management?

At any rate, we don't have to solve this today, for this BZ, because the customer requesting the feature has said that, while not ideal, they are already used to building .pp files and distributing them.  https://bugzilla.redhat.com/show_bug.cgi?id=1848683#c9

Comment 17 Rich Megginson 2020-11-12 19:27:02 UTC
https://github.com/linux-system-roles/selinux/pull/56

Comment 21 Rich Megginson 2021-04-01 23:57:01 UTC
testing coverage is tests/tests_selinux_modules.yml

Comment 36 errata-xmlrpc 2021-11-09 17:44:38 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (rhel-system-roles bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2021:4159


Note You need to log in before you can comment on or make changes to this bug.