Security Administration: SELinux, firewalld, and System Hardening
This domain tests the two access-control layers that most often break services on Oracle Linux: SELinux mandatory access control and firewalld zone-based filtering.
SELinux
- Modes:
getenforce/sestatusshow Enforcing, Permissive, or Disabled./etc/selinux/configsets the persistent mode; changing to or from Disabled requires a reboot and often a full relabel. - Contexts:
ls -Z,ps -eZ,id -Z. Temporary change withchcon; persistent mapping withsemanage fcontext -a -t httpd_sys_content_t "/web(/.*)?"followed byrestorecon -Rv /web. - Booleans:
getsebool -a,semanage boolean -l,setsebool -P httpd_can_network_connect on(-Pmakes it persistent). - Ports:
semanage port -a -t http_port_t -p tcp 8080;semanage port -l | grep http. - Denials:
ausearch -m avc -ts recent,sealert -a /var/log/audit/audit.log; policy generation withaudit2allow -M mypolthensemodule -i mypol.pp.
firewalld
firewall-cmd --state,--get-default-zone,--list-all,--list-all-zones.- Change runtime or permanent:
firewall-cmd --permanent --add-service=https,--add-port=8080/tcp,--add-source=192.0.2.0/24 --zone=trusted, thenfirewall-cmd --reload.--runtime-to-permanentpromotes the running config. - Zones:
public(default),trusted(accept all),drop(silent discard). Interfaces are assigned with--add-interface=ens3 --zone=internal.
Hardening
- sshd:
PermitRootLogin no,PasswordAuthentication no,AllowGroups sshusers; validate withsshd -tbefore restarting. - Enable
auditd, useauthselectfor PAM profiles, and reviewaidefor file integrity.
Worked example
Apache must listen on 8080. Open the port with firewall-cmd --permanent --add-port=8080/tcp && firewall-cmd --reload, then allow SELinux to bind: semanage port -a -t http_port_t -p tcp 8080, restart httpd. Reasoning: without the SELinux port label, httpd is denied even though the firewall is open.
Traps
--permanentchanges do not take effect until--reload.- Runtime-only firewall changes vanish on reload or restart.
chconlabels are lost on the next relabel; usesemanage fcontextplusrestorecon.setseboolwithout-Pdoes not survive a reboot.