Sub topic 7
Tuning Service Behavior with SELinux Booleans
Assume you know basic Linux permissions, systemctl, journalctl, and the SELinux ideas from earlier chapters. This chapter focuses on SELinux booleans, which let you turn approved policy options on or off without writing a custom policy.
What a Boolean Changes
An SELinux boolean is a named policy switch. A boolean controls a conditional part of the loaded policy. For example, the httpd_can_network_connect boolean controls whether the Apache domain, httpd_t, may make network connections to other services.
A boolean does not grant unrestricted access. It enables a specific set of rules that policy authors have already defined and reviewed.
This approach is safer than disabling SELinux because the service still runs inside its confined domain. The change affects only the behavior covered by that boolean.
List and Read Boolean Values
Use getsebool to read a boolean:
getsebool httpd_can_network_connectTypical output is:
httpd_can_network_connect --> offTo list all booleans, use:
getsebool -aTo find likely web-server options:
getsebool -a | grep '^httpd_'The name describes the policy condition, but confirm its meaning on the local system. Use semanage boolean -l for descriptions and current persistence information:
sudo semanage boolean -l | grep httpdThe semanage command is provided by the SELinux management tools package on many RHEL-family systems.
Enable a Boolean Temporarily or Persistently
Use setsebool without -P for a runtime-only change:
sudo setsebool httpd_can_network_connect onThe setting remains active until the next reboot or policy reload. Use -P to update the persistent policy configuration:
sudo setsebool -P httpd_can_network_connect onThe persistent command can take longer because it rebuilds and reloads policy data.
| Command | Runtime effect | Survives reboot |
|---|---|---|
| `setsebool NAME on` | Yes | No |
| `setsebool -P NAME on` | Yes | Yes |
| `setsebool NAME off` | Disables it now | No |
Turn a boolean off when the service no longer needs the capability:
sudo setsebool -P httpd_can_network_connect offChoose a Boolean Before Loosening Policy
When a service fails, do not enable every boolean that sounds related. First inspect the denial and determine the exact operation. A reverse proxy may need outbound connections, while a static file server usually does not.
Common examples include:
httpd_can_network_connect: allow Apache to connect to network services.httpd_can_network_connect_db: allow Apache to connect to database services.httpd_enable_homedirs: allow Apache to serve content from user home directories.nis_enabled: allow services to use NIS-related access.
If no suitable boolean exists, check file labels, port labels, and the AVC denial before creating a custom module. A boolean cannot fix a wrongly labeled file or an unlabeled non-standard port.
Exercise
You temporarily enabled httpdcannetwork_connect while testing a reverse proxy. What command makes the setting survive reboot, and what command removes it later?
Show answer
Run sudo setsebool -P httpdcannetworkconnect on to persist the setting. Later, run sudo setsebool -P httpdcannetworkconnect off to remove it.