SELinux (Security Enhanced Linux)

Linux
Security
Published

June 21, 2016

Modified

February 6, 2023

SELinux (Security Enhanced Linux)…

# context information about a file
>>> ls -Z $(mktemp)
unconfined_u:object_r:user_tmp_t:s0 /tmp/tmp.bF245MJELg
|          | |      | |        | ``----------------------- level
|          | |      | `--------`-------------------------- domaine
|          | `------`------------------------------------- role
`----------`---------------------------------------------- identity

Display of security contexts

id -Z                    # the user's context
ls -Z                    # those of the current files
ps -eZ                   # those of the processes
netstat –Z               # for network connections
lsof -Z                  # for open files
matchpathcon $path       # context of a directory

Service

SELinux…

  • …logs to /var/log/audit/audit.log
  • …configuration in /etc/selinux/config
  • Operating modes…
    • Enforcing…access restricted according to the rules
    • Permissive
      • …rules are polled, access errors are logged
      • …access will not be blocked
    • Disabled…no restrictions…no logging

Current operations mode…

getenforce
sestatus | grep mode
# temporary switch to permissiv mode...
sudo setenforce 0

Permanently disable in the configuration file …requires a node reboot

# Check configuration
>>> grep ^SELINUX= /etc/selinux/config
SELINUX=permissive

# ...modify the configuraion to disable SELinux
>>> sed -i 's/permissive/disabled/' /etc/selinux/config

# ...verify the configuration change
>>> grep ^SELINUX= /etc/selinux/config 
SELINUX=disabled

Commands

  • chcon (change context) temporary changes…
  • semanage fcontext persistent changes…

Booleans allow policy to be changed at runtime…

# list & describe available booleans
semanage boolean -l
# enable/disable a boolean
setsebool $boolean_name (on|off)