On CentOS 7.5, Linux 3.10.0-862.3.2.el7.x86_64, I'm trying to understand how file contexts work. ls -Z, chcon and semanage seem to work as expected, but restorecon seems stubbornly silent.
For example:
$ cd $ mkdir context $ ls -laZ drwxrwxr-x liteyear liteyear ? context $ chcon -v unconfined_u:object_r:user_home_t:s0 context $ ls -laZ drwxrwxr-x. liteyear liteyear unconfined_u:object_r:user_home_t:s0 context $ rmdir context All good, and semanage:
$ mkdir context $ sudo semanage fcontext -a -t user_home_t /home/liteyear/context $ cat /etc/selinux/targeted/contexts/files/file_contexts.local # This file is auto-generated by libsemanage # Do not edit directly. /home/liteyear/context system_u:object_r:user_home_t:s0 All good, but the restorecon route:
$ restorecon -v /home/liteyear/context $ ls -laZ drwxrwxr-x liteyear liteyear ? context doesn't apply the file context.
I've tried various iterations, with existing contexts, different contexts, other folders and files, and restorecon has never produced anything. There are various similar reports (eg. [CentOS] SELinux restorecon does not work) but no one seems to have confirmed there's an issue.
Is this the way restorecon is supposed to work?
restorecon -Rv /home/liteyear/contextmade no difference to the outcomesestatus)? I find it odd that file context is not applied automatically on directory creation (your firstmkdir, I assume it is in your home directory).sestatussays disabled. So it's silently ineffective? This all came about when I was trying to recreate/var/lib/php/sessionto suit nginx - it had a file context and so I set about restoring it. If you could add an answer with "because its disabled" and add why it would be disabled and whether to worry about it, I'd be happy to accept it.