Skip to content

Commit

Permalink
Merge pull request #7601 from ciprianbadescu/PUP-2169/flush-selinux-c…
Browse files Browse the repository at this point in the history
…ontext-at-teardown

(PUP-2169) flush selinux at transaction teardown
  • Loading branch information
mihaibuzgau authored Jul 23, 2019
2 parents ae5ab49 + 1fee8e7 commit 857c814
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/puppet/provider/file/posix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
include Puppet::Util::Warnings

require 'etc'
require 'puppet/util/selinux'

def self.post_resource_eval
Selinux.matchpathcon_fini if Puppet::Util::SELinux.selinux_support?
end

def uid2name(id)
return id.to_s if id.is_a?(Symbol) or id.is_a?(String)
Expand Down
6 changes: 5 additions & 1 deletion lib/puppet/util/selinux.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@

module Puppet::Util::SELinux

def selinux_support?
def self.selinux_support?
return false unless defined?(Selinux)
if Selinux.is_selinux_enabled == 1
return true
end
false
end

def selinux_support?
Puppet::Util::SELinux.selinux_support?
end

# Retrieve and return the full context of the file. If we don't have
# SELinux support or if the SELinux call fails then return nil.
def get_selinux_current_context(file)
Expand Down
18 changes: 18 additions & 0 deletions spec/unit/transaction_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,24 @@ def post_resource_eval

transaction.evaluate
end

it "should call Selinux.matchpathcon_fini in case Selinux is enabled ", :if => Puppet.features.posix? do
unless defined?(Selinux)
module Selinux
def self.is_selinux_enabled
true
end
end
end

resource = Puppet::Type.type(:file).new(:path => make_absolute("/tmp/foo"))
transaction = transaction_with_resource(resource)

expect(Selinux).to receive(:matchpathcon_fini)
expect(Puppet::Util::SELinux).to receive(:selinux_support?).and_return(true)

transaction.evaluate
end
end

describe 'when checking application run state' do
Expand Down

0 comments on commit 857c814

Please sign in to comment.