Jira (PUP-10548) Wrong SELinux contexts on files if puppet installs new rpm with SELinux policy

3 views
Skip to first unread message

Adam Tkac (Jira)

unread,
Jun 24, 2020, 1:37:04 PM6/24/20
to puppe...@googlegroups.com
Adam Tkac created an issue
 
Puppet / Bug PUP-10548
Wrong SELinux contexts on files if puppet installs new rpm with SELinux policy
Issue Type: Bug Bug
Affects Versions: PUP 6.15.0
Assignee: Unassigned
Components: Types and Providers
Created: 2020/06/24 10:36 AM
Priority: Normal Normal
Reporter: Adam Tkac

Puppet Version: 6.15.0
Puppet Server Version: not applicable, we don't use it in our environment (we use "git pull && puppet apply -e <classname>" on every node)
OS Name/Version: CentOS 7.8

In our company, we have custom SELinux policy shipped in rpm. When we deploy new instance, our puppet recipes installs SELinux policy rpm and then create various file resources. However those resources are created with wrong SELinux labels because puppet doesn't refresh selinux contexts on file resources after new package is installed. To get proper file contexts, we must run puppet twice (first run install SELinux policy and the second run fixes file contexts)

In our environment, we use something like this:

  package { 'gdc-selinux':
    ensure => latest;
  }
  -> file { '/etc/gdc/gcf':
    ensure => directory;
  }
  -> file { '/etc/gdc/gcf/gcfw.json':
    ensure => present;
  }

 
The first puppet run outputs following - pkg is installed and files created, however with wrong SELinux context:

Notice: /Stage[main]/Type::Type_fake/Package[gdc-selinux]/ensure: created
Notice: /Stage[main]/Type::Type_fake/File[/etc/gdc/gcf]/ensure: created
Notice: /Stage[main]/Type::Type_fake/File[/etc/gdc/gcf/gcfw.json]/ensure: created

The second puppet run fixes the issue:

Notice: /Stage[main]/Type::Type_fake/File[/etc/gdc/gcf]/seltype: seltype changed 'etc_t' to 'gdc_etc_t'
Notice: /Stage[main]/Type::Type_fake/File[/etc/gdc/gcf/gcfw.json]/seltype: seltype changed 'etc_t' to 'gdc_gcfw_conf_t'

For your conveniency, this is also reproducer (although not with "package" resource but with custom "exec" but logic behind it is pretty similar - update SELinux policy and then deliver files)

  exec { '/usr/sbin/semanage fcontext --add --type bin_t /tmp/barani':
    logoutput => true;
  }
  -> file { '/tmp/barani':
    ensure => present;
  }

# puppet apply
...
Notice: /Stage[main]/Type::Type_fake/Exec[/usr/sbin/semanage fcontext --add --type bin_t /tmp/barani]/returns: executed successfully
Notice: /Stage[main]/Type::Type_fake/File[/tmp/barani]/ensure: created

# ls -Z /tmp/barani 
-rw-r--r--. root root unconfined_u:object_r:user_tmp_t:s0 /tmp/barani

# second puppet apply
...
Notice: /Stage[main]/Type::Type_fake/File[/tmp/barani]/seltype: seltype changed 'user_tmp_t' to 'bin_t'

Desired Behavior:
Files are created with proper SELinux contexts during one puppet run, instead of two runs needed

Actual Behavior:
Check original description for reproducer or feel free to contact me if you need more info.

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v8.5.2#805002-sha1:a66f935)
Atlassian logo

Josh Cooper (Jira)

unread,
Jun 25, 2020, 12:22:02 PM6/25/20
to puppe...@googlegroups.com

Josh Cooper (Jira)

unread,
Jun 25, 2020, 12:22:03 PM6/25/20
to puppe...@googlegroups.com

Ciprian Badescu (Jira)

unread,
Jun 26, 2020, 2:53:03 AM6/26/20
to puppe...@googlegroups.com
Ciprian Badescu commented on Bug PUP-10548
 
Re: Wrong SELinux contexts on files if puppet installs new rpm with SELinux policy

I think that having a property like `refresh_selinux_context` for file resource could solve the issue.

Mihai Buzgau (Jira)

unread,
Jun 30, 2020, 11:03:03 AM6/30/20
to puppe...@googlegroups.com

Tim Meusel (Jira)

unread,
Sep 23, 2020, 2:43:03 AM9/23/20
to puppe...@googlegroups.com
Tim Meusel commented on Bug PUP-10548
 
Re: Wrong SELinux contexts on files if puppet installs new rpm with SELinux policy

hey people,
just wanted to mention that vox pupuli hits this issue in several places as well, for example in our https://github.com/voxpupuli/puppet-hyperglass module

Bogdan Irimie (Jira)

unread,
Nov 5, 2020, 3:51:04 AM11/5/20
to puppe...@googlegroups.com

Bogdan Irimie (Jira)

unread,
Nov 5, 2020, 3:52:05 AM11/5/20
to puppe...@googlegroups.com

Ciprian Badescu (Jira)

unread,
Oct 21, 2021, 8:00:03 AM10/21/21
to puppe...@googlegroups.com
Ciprian Badescu updated an issue
Change By: Ciprian Badescu
Sprint: ready for triage
This message was sent by Atlassian Jira (v8.13.2#813002-sha1:c495a97)
Atlassian logo

Ciprian Badescu (Jira)

unread,
Oct 21, 2021, 8:00:04 AM10/21/21
to puppe...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages