From 88ea6772d5c6283af873f902ca68b149a5320f51 Mon Sep 17 00:00:00 2001 From: Pavel Skrylev Date: Thu, 11 Sep 2025 01:09:29 +0300 Subject: [PATCH] maint: Fix owner for the facts folder * When retrieving facts and string them to the facts fils as yaml, the folder is created as of root, so changing them to puppet defaults. --- lib/puppet/file_system/file_impl.rb | 4 ++-- lib/puppet/indirector/yaml.rb | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/puppet/file_system/file_impl.rb b/lib/puppet/file_system/file_impl.rb index fb7e16e6107..1b36b353c80 100644 --- a/lib/puppet/file_system/file_impl.rb +++ b/lib/puppet/file_system/file_impl.rb @@ -161,8 +161,8 @@ def chmod(mode, path) def replace_file(path, mode = nil) begin stat = lstat(path) - gid = stat.gid - uid = stat.uid + gid = Puppet::Type.type(:group).new(name: Puppet[:group]).exists? ? Puppet[:group] : stat.gid + uid = Puppet::Type.type(:user).new(name: Puppet[:user]).exists? ? Puppet[:user] : stat.uid mode ||= stat.mode & 0o7777 rescue Errno::ENOENT mode ||= 0o640 diff --git a/lib/puppet/indirector/yaml.rb b/lib/puppet/indirector/yaml.rb index 85b900f7e36..8c7fc7599d9 100644 --- a/lib/puppet/indirector/yaml.rb +++ b/lib/puppet/indirector/yaml.rb @@ -26,7 +26,7 @@ def save(request) basedir = File.dirname(file) # This is quite likely a bad idea, since we're not managing ownership or modes. - Dir.mkdir(basedir) unless Puppet::FileSystem.exist?(basedir) + touch_dir(basedir) unless Puppet::FileSystem.exist?(basedir) begin Puppet::Util::Yaml.dump(request.instance, file) @@ -59,6 +59,15 @@ def search(request) protected + def touch_dir(dir) + Dir.mkdir(dir) + + user = Puppet::Type.type(:user).new(name: Puppet[:user]).exists? ? Puppet[:user] : nil + group = Puppet::Type.type(:group).new(name: Puppet[:group]).exists? ? Puppet[:group] : nil + Puppet.debug("Fixing perms for #{user}:#{group} on #{dir}") + FileUtils.chown(user, group, dir) if user || group + end + def load_file(file) Puppet::Util::Yaml.safe_load_file(file, [model, Symbol]) end