Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(PUP-2169) flush selinux at transaction teardown #7601

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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