Lesson 3 of 9 · 23m
Booleans, Policy Modules, Ports, and the Shape of Real SELinux Policy
Learn the supported adjustment points administrators are expected to use before writing or disabling policy.
SELinux is not one immutable blob. Distribution policy ships with deliberate tuning knobs: booleans, manageable file contexts, port labels, user mappings, and local policy modules. Senior administrators reach for these knobs because they preserve the policy's intent while adapting it to real services. Junior administrators reach for permissive mode because nobody showed them the knobs.
Booleans are maintained policy branches
A boolean toggles a group of allow rules the distribution already understands:
getsebool -a | grep '^httpd'
setsebool -P httpd_can_network_connect_db on
semanage boolean -l | grep -E 'httpd_can_network_connect(_db)?\s'-P makes the change persistent. Prefer narrow booleans: httpd_can_network_connect_db covers database egress; httpd_can_network_connect allows much broader outbound access. Validate the description before enabling anything.
Ports are labeled objects too
SELinux can restrict which domains bind or connect to ports:
semanage port -l | grep -E '^(http|ssh|postgresql)_'
sudo semanage port -a -t http_port_t -p tcp 8443
# use port -m instead when tcp/8443 is already definedDo not add duplicates. A missing port label cannot be fixed with file contexts, and perfectly labeled content cannot fix a missing port type.
File contexts and process types are separate adjustment surfaces
A service failing to read /srv/app/config.yaml does not need network booleans. It needs the file type relationship corrected. Conversely, perfectly labeled content cannot fix a missing port type. Diagnose the object class before choosing the tool:
file, dir, sock_file -> labels and file type rules
tcp_socket, udp_socket -> network peer or port rules
port -> semanage port
capability -> least privilege; investigate before allowingLocal policy modules are the last supported customization layer
When a vendor service legitimately needs behavior not covered by booleans or standard types, a local module can encode that exception. The key word is local. You are not patching away SELinux; you are documenting one system-specific contract in policy.
A mature workflow keeps module source, installation commands, and rollback notes in configuration management:
semodule -l | grep '^localapp'
sudo semodule -i localapp.pp
sudo semodule -r localappField notes
- Use
getseboolfor runtime state andsemanage boolean -lfor persistent state plus descriptions. - Boolean changes can take time to commit because policy stores are rebuilt; do not interrupt the command.
- Never blindly paste
setseboollines from forums. Validate that the boolean exists on your distro release and matches the actual denial. - A local module is a changelog in security policy. Name it after the service, not
fix.pportest1.pp.
Was this lesson helpful?