Pcornel
Linux · SELinux

Contexts

Cheat sheet · https://pcornel.dk/topic.php?topic=2858

Back to the Topic

Answer

An SELinux context (label) has user:role:type:level, e.g. system_u:object_r:httpd_sys_content_t:s0. The type is what most policy rules use.

Remember

Files moved with mv keep their old label; copied files get the target directory's label. Set permanent rules with semanage fcontext -a -t <type> '<path>(/.*)?' then restorecon -Rv <path>. chcon changes are lost on relabel.

First checks

  • getenforce / sestatus — mode and policy
  • ls -Z <path> — file context
  • ps -eZ | grep <proc> — process context
  • ausearch -m AVC -ts recent — recent denials
  • semanage fcontext -l | grep <path> — context rules for a path

Commands

id -Z
ss -Z

Verify in this order

file label (type) and process domain → policy allows the domain to access the type

Where it usually breaks

First mismatch in identity/group resolution → Unix mode/ACL/capability → mount/sandbox constraint → SELinux/AppArmor policy → credential/TLS trust → protected operation; preserve identity/native diagnostic/pre-state before mutation.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=2858

Confirmation

Confirm action

Continue?