Straypenguins-Tips-Inventory

SELinux Practical Tips & Modules

Overview

This sub-folder of the Straypenguins-Tips-Inventory repository provides practical, scenario-driven guides for customizing, extending, and troubleshooting SELinux policy modules on modern Linux systems (with a focus on RHEL9/CentOS Stream 9 and derivatives).
It includes step-by-step instructions, real-world examples, and reusable policy patterns for admins and developers managing their own services or customizing access for standard daemons.


Table of Contents


Environment and Conventions

For terminology and SELinux-specific labels used in these documents, see the Glossary section below.


The Gist

Allow httpd outbound access to a custom port (e.g., 7003):

# Install SELinux tools
dnf install policycoreutils-devel selinux-policy-devel

# Search for denials
ausearch -m AVC,USER_AVC,SELINUX_ERR,USER_SELINUX_ERR | grep httpd

# If needed, create and load a custom port type and allow httpd to connect:
# (See detailed steps in [SELinux Policy Module for httpd on Port 7003](/Straypenguins-Tips-Inventory/Linux/SELinux/selinux-mod_wl-allow-httpd-7003.html))

Create and load a custom policy module for your own service:

# Write your .te file (see examples)
checkmodule -M -m -o mysvcd.mod mysvcd.te
semodule_package -o mysvcd.pp -m mysvcd.mod
semodule -v -X 300 -i mysvcd.pp

Troubleshoot SELinux denials:

# Search audit logs for denials
ausearch -m AVC,USER_AVC,SELINUX_ERR,USER_SELINUX_ERR -su mysvcd_t

# Check active policy
sesearch --allow -s mysvcd_t

For more detailed how-to, see the Documents section below.


Documents


Glossary

Basic Concepts

Policy Structure & Logic

Policy File Types

Tools