SELinux booleans.
Before you write a custom SELinux policy, check if there's already a switch for it. Booleans are named on/off toggles that enable or disable whole pre-written chunks of policy β like 'let Apache talk to the network' β at runtime, no recompile needed.
SELinux booleans animated tutorial. Runtime policy switches, getsebool, setsebool, persistent changes with -P, semanage boolean -l, common booleans like httpd_can_network_connect, and the denial-troubleshooting workflow. RHCSA EX200 ready.SELinux ships with rules for hundreds of common situations, turned off by default. A boolean is the switch that turns one of those rule sets on β no custom policy required.
- Β·The SELinux contexts lesson (what type enforcement is)
- Β·Comfortable running commands as root / with sudo
- Β·Know that SELinux can block a working-looking service
Read a boolean's state, flip it persistently with setsebool -P, discover the right boolean for a service, and use audit2why to find which one a denial needs.
pace: 8 minutes
httpd_can_network_connectoffhttpd_enable_homedirsoffftpd_anon_writeoffnfs_export_all_rwoffsamba_enable_home_dirsoffA boolean is a switch over pre-written policy
The SELinux policy that ships with RHEL already contains rules for hundreds of common situations β they're just turned OFF by default for safety. A boolean is a named on/off switch that flips one of those rule sets on or off at runtime, no policy recompile, no custom modules. Before writing any custom policy, always ask: is there already a boolean for this?
The SELinux fix hierarchy: boolean β label β custom module, in that order. Most "SELinux is blocking my service" problems are solved by a single setsebool -P. And never forget the -P β a runtime-only flip is a time bomb that detonates at the next reboot.
$getsebool BOOL$getsebool -a$getsebool -a | grep httpd$setsebool BOOL on$setsebool -P BOOL on$semanage boolean -l$semanage boolean -l -C$ausearch -m AVC -ts recent$audit2why -al$httpd_can_network_connect$httpd_enable_homedirs$httpd_can_sendmail$ftpd_anon_write$nfs_export_all_rw$samba_enable_home_dirs$ssh_sysadm_loginApache (httpd) needs to connect to a database on another server, but SELinux is blocking it. What should you try FIRST?
You run `setsebool httpd_can_network_connect on` (no -P) and it works. Three weeks later after a reboot, Apache breaks again. Why?
Which command shows every boolean WITH its current state, default state, and a description?
What's the advantage of a boolean over writing a custom SELinux policy module?
These aren't graded β they're just for active recall, which is what actually makes the lesson stick.
SELinux contexts
Booleans toggle policy; contexts (labels) decide what can touch what. When a boolean isn't the fix, a wrong file label usually is β learn to read and restore them.
Read this lesson as text6 chapters Β· quiz answers
01A boolean is a switch over pre-written policy
The SELinux policy that ships with RHEL already contains rules for hundreds of common situations β they're just turned OFF by default for safety. A boolean is a named on/off switch that flips one of those rule sets on or off at runtime, no policy recompile, no custom modules. Before writing any custom policy, always ask: is there already a boolean for this?
02getsebool β read the current state
getsebool <name>shows whether one boolean is on or off.getsebool -alists every boolean on the system (there are hundreds).semanage boolean -lis even better β it shows the current state, the default state, AND a human description of what each one does.$ getsebool httpd_can_network_connectβ β ...off$ getsebool -aβ list all booleans$ getsebool -a | grep httpdβ just the httpd ones
03setsebool β flip it (runtime only)
setsebool httpd_can_network_connect onflips the switch immediately β Apache can now make outbound connections (e.g. to a database or an API on another host). BUT this change lives only in memory: it reverts on the next reboot. Useful for testing, dangerous if you forget it isn't permanent.$ setsebool httpd_can_network_connect onβ flip ON (this boot only)$ setsebool httpd_can_network_connect offβ flip back OFF
04Make it stick β the -P flag
Add -P (Persistent) and the change is written to disk so it survives reboots:
setsebool -P httpd_can_network_connect on. -P is a little slower because it rebuilds the policy, but for any real configuration you ALWAYS want it. The classic production bug: someone runs setsebool without -P, it works, then the service breaks weeks later after a reboot.$ setsebool -P httpd_can_network_connect onβ ON, survives reboot$ semanage boolean -l | grep httpd_can_netβ verify current vs default
05Finding the right boolean
You rarely memorize boolean names. Discover them:
getsebool -a | grep <keyword>orsemanage boolean -l | grep <keyword>. Searching for the service name (httpd, ftpd, nfs, samba) usually surfaces the switch you need. The descriptions insemanage boolean -ltell you exactly what each does.$ semanage boolean -lβ all booleans + state + description$ semanage boolean -l | grep ftpβ FTP-related switches$ sepolicy booleans -aβ richer descriptions
06The denial β boolean workflow
When a service is denied by SELinux: (1) confirm it's SELinux with
ausearch -m AVC -ts recent; (2) runaudit2why -alβ for many denials it literally says 'this can be allowed by setting the X boolean'; (3) flip that boolean withsetsebool -P. Booleans are the FIRST thing to try β far safer than relabeling files or writing a custom module.$ ausearch -m AVC -ts recentβ find the denial$ audit2why -alβ often names the boolean to set$ setsebool -P <boolean> onβ apply the fix permanently
Quiz β answers
- Apache (httpd) needs to connect to a database on another server, but SELinux is blocking it. What should you try FIRST?
- βCheck for and enable a boolean: setsebool -P httpd_can_network_connect on.There's almost always a boolean for common needs. httpd_can_network_connect is exactly this case. Booleans are the safest, simplest fix β reach for them before relabeling, custom modules, or (never) disabling SELinux.
- You run
setsebool httpd_can_network_connect on(no -P) and it works. Three weeks later after a reboot, Apache breaks again. Why? - βWithout -P, setsebool changes only the in-memory value β it reverts to the default on reboot. You needed setsebool -P to persist it.-P (Persistent) writes the change to disk so it survives reboots. Without it, the change is runtime-only. This is one of the most common 'it worked then mysteriously broke' SELinux bugs.
- Which command shows every boolean WITH its current state, default state, and a description?
- βsemanage boolean -l
getsebool -alists names and on/off only.semanage boolean -ladds the default state and a human-readable description β the best tool for discovering what a boolean actually does. - What's the advantage of a boolean over writing a custom SELinux policy module?
- βA boolean toggles pre-written, vendor-tested policy at runtime with no recompile β it's simpler, safer, and survives policy updates, whereas a custom module is more to maintain and can drift.Booleans are maintained by the distro and cover the common cases. They're a one-command, well-understood change. Custom modules are powerful but a last resort β more surface area to maintain and easier to get subtly wrong.
keep going β these pair well with what you just learned.
How SSH key auth works
The six-step handshake β key offer, challenge, signature, verification, channel open. Watch an animated client/server diagram light up each arrow.
TLS handshake, deep
Open every TLS 1.3 message β ClientHello, ServerHello, Certificate, CertificateVerify, Finished. Cipher suites, HKDF key derivation, SNI, ALPN, and why TLS 1.3 has built-in perfect forward secrecy.