Cookbooks
selinux
documentation
Selinux Fcontext

Back to resource list

selinux_fcontext

Set the SELinux context of files with semanage fcontext.

Actions

ActionDescription
:manage(Default) Assigns the file to the right context regardless of previous state.
:addAssigns the file context if not set.(-a)
:modifyUpdates the file context if previously set.(-m)
:deleteRemoves the file context if set. (-d)

Properties

NameTypeDefaultDescription
file_specStringResource namePath or regular expression to files to modify.
secontextStringThe SELinux context to assign the file to.
file_typeStringa (all files)Restrict the resource to only modifying specific file types. See list below.

Supported file types:

  • a - All files
  • f - Regular files
  • d - Directory
  • c - Character device
  • b - Block device
  • s - Socket
  • l - Symbolic link
  • p - Named pipe

Examples

# Allow http servers (e.g. nginx/apache) to modify moodle files
selinux_policy_fcontext '/var/www/moodle(/.*)?' do
  secontext 'httpd_sys_rw_content_t'
end
 
# Adapt a symbolic link
selinux_policy_fcontext '/var/www/symlink_to_webroot' do
  secontext 'httpd_sys_rw_content_t'
  file_type 'l'
end