How to make Puppet fix SELinux types for home directories

puppetrhel6selinux

We are using pam_mkhomedir.so to automatically create the home directories of users logging in with SSH. There is a bug in pam_mkhomedir that sets the SELinux contexts to home_root_t instead of user_home_dir_t. The solution is using pam_oddjob_mkhomedir, which we've implemented.

We however still have many home directories with invalid SELinux contexts.

drwxr-xr-x. jdoe users unconfined_u:object_r:home_root_t:s0 jdoe

How can we design a Puppet module that would correct SELinux contexts on all user home directories?

I was thinking about a solution like this:

file { '/home/*':
    ensure => "directory",
    seltype => "user_home_dir_t"
}

Unfortunately the wildcard doesn't work.

Best Answer

Maybe this would be helpful? http://projects.puppetlabs.com/issues/2856

Recurselimit seems to work for /home/user1, but also sets /home to user_home_dir_t.

file { '/home/':
  ensure => "directory",
  recurse => true,
  recurselimit => 1,
  seltype => "user_home_dir_t"
}

You could set up a custom fact that returns all home directories in an array (too many users could be a problem here):

$fact_home_dirs = ['/home/user1', '/home/user2']

file { $fact_home_dirs:
  ensure => "directory",
  seltype => "user_home_dir_t"
}

Perhaps the best option in this case would be to run restorecon since you seem to have implemented a solution for newly created directories.