question ... the team that manages our production ...
# puppet
j
question ... the team that manages our production machines (i.e. at client sites) came to me earlier with an issue where the agent is taking almost five hours to finish (where the normal time is 45-120 seconds, depending on hardware) ... they sent me the output of
puppet agent -t --debug
, and it turns out the problem is one
file
resource with
ensure => directory
and
recurse => true
, where that directory tree on the target server contains about 450K individual files (this is an expected condition, but it's something that our QA people aren't testing) ... the debug logs show that the agent is looking up the expected SELinux (user, role, type, range) for EVERY SINGLE FILE, apparently so it can check/fix every single file
it's obvious to me that the
recurse => true
needs to go.
b
Yeah, don't do that
j
and while the files' uid/gid/mode and SELinux info shouldn't change over time (the files are created by our app, with the correct attributes), there may be cases where somebody fat-fingers a command and messes them up, so i'm planning to add a script that they can run by hand with
chown -R
,
chmod -R
, and
restorecon -R
commands to "put things back to rights"
my actual question is ... this is all happening under PE2016.2.0, has anything changed since then? would PE2023.8 behave the same way, explicitly checking every single file under the directory tree?
b
Yes
That's what recurse is supposed to do
j
okay ... i hadn't really thought about it until now, i'm wondering if there might be a way to make the
file
provider run
chown -R
etc. instead of trying to process every individual file ...
b
Where are all those files coming from?
j
i can't go into too much detail, but ... part of the product involves something like a "chat server", and these are files that users have been sending back and forth to each other for (some configurable length of time, typically 90-365 days, not sure about this particular server), some client sites use this part of the system more heavily than others ... point is, this is an expected state of the machines, one that nobody realized would be a problem.
b
Use a systemd timer to check permissions or prohibit users from changing permissions
j
NORMALLY users can't. the files are created and used by our software, puppet sets up the directory where the files are stored. most users don't have SSH access to the machines. problem is, the ones that do have access are human, and sometimes make typos. (plus some of the clients "break into" the machines, but that's a different discussion.) i had originally written the code that way many years ago (
git blame
says i wrote it 2016-11-01) to help prevent the production guys from shooting themselves in the foot, and then forgot all about it since then.
s/systemd timer/cron job/
... i have an almost pathological loathing for systemd, it is the exact opposite of the unix philosophy that a tool should "do one thing and do it well" ... i only tolerate it because redhat has made it pretty much impossible not to.
k
systemd timer and service is superior to cron. you get proper logging, the ability to run the job manually, and all the benefits of systemd services.
j
normal cron jobs also have "proper logging" and "the ability to run the job manually", if they're written correctly ... and the value of "all the benefits of systemd services" is a negative number to me, i've always found systemd to be more trouble than it claims to be worth ... the only possible benefit i've ever heard of is starting services in parallel, which i guess is nice if you're obsessed with shaving ten seconds off of how long it takes a machine to boot.
again, i've learned to tolerate it, but that doesn't mean i have to like it.
a
Use https://forge.puppet.com/modules/npwalker/recursive_file_permissions/readme or write your own
exec
modeled after it. Why this never made it into the product and people are still feeling the negative effects of
recurse => true
, I'll never know
j
any chance it can also recursively set SELinux contexts? even if it's just running
restorecon -r
under the covers?
a
That module I don't think so, but I know little about Puppet + SELinux admittedly