Peter
12/15/2023, 5:25 PM%%
is used to denote that all files and folders should be matched, and thus monitored, recursively. Based on this, I should be able to recursively monitor for changes to CA certificates using /usr/share/ca-certificates/%%
?
However, when this is done, osquery is attempting to install watches on all files under the specified directory, and subdirectories, as if they were themselves directories - which fails:
W1215 15:29:47.814217 14737 inotify.cpp:371] Could not add inotify watch on: /usr/share/ca-certificates/mozilla/E-Tugra_Certification_Authority.crt/
W1215 15:29:47.814276 14737 inotify.cpp:371] Could not add inotify watch on: /usr/share/ca-certificates/mozilla/QuoVadis_Root_CA_3_G3.crt/
W1215 15:29:47.814344 14737 inotify.cpp:371] Could not add inotify watch on: /usr/share/ca-certificates/mozilla/ACCVRAIZ1.crt/
Peter
12/15/2023, 5:25 PMroot@ip-100-66-32-61:/tmp/inotify-info# find /usr/share/ca-certificates/mozilla/ -type f | wc -l
136
…but osquery isn’t installing watches on the files, just the directories.
root@ip-100-66-32-61:/tmp/inotify-info# ./_release/inotify-info 15460 | grep /usr/share/ca-certificates/
31382 [259:1] /usr/share/ca-certificates/
31383 [259:1] /usr/share/ca-certificates/mozilla/
Peter
12/15/2023, 5:28 PMroot@ip-100-66-32-61:/tmp/inotify-info# lsof | grep inotify | wc -l
134
root@ip-100-66-32-61:/tmp/inotify-info# sysctl -a | grep -i max_user_watches
fs.inotify.max_user_watches = 29900
Peter
12/15/2023, 5:49 PM/
on the file paths as if they were directories, but a watch is seemingly never installed on the files themselves.Peter
12/15/2023, 6:18 PMclong
12/15/2023, 6:19 PMRyan Breed
12/15/2023, 7:42 PM<https://github.com/osquery/osquery/blob/master/osquery/events/linux/inotify.cpp#L402>
addMonitor(canonicalized,isc,mask,false);
is setting recursive
to false
in the call to addMonitor
(leaving out param add_watch
) regardless of the value of recursive
as it was passed in, but I have no idea what that actually meansDaniel Cross
12/18/2023, 2:48 AMPeter
12/18/2023, 2:18 PM/
appended and are attempted to be watched even if they’re files.
This seems to be where this warning is originating, as files within these directories will fail to have a watch installed due to this appended /
.Peter
12/18/2023, 2:20 PMexclude_paths
to filter these for each category - where possible:
"exclude_paths": {
"configuration": [
"/tmp/%%",
"/dev/%%"
],
It does mean that there are wasted inotify handles due to these followed symlinks, but it does prevent these entries from being output at query time - reducing noise from our telemetry.Daniel Cross
12/19/2023, 3:09 AMfile_paths_query
a bunch, however I start to wonder how computationally expensive that is. I also feel like having this being able to query for the directory
column rather than path
would be better, as placing an inotify watch there rather than files is preferable (as I understand it). Something like a "SELECT DISTINCT directory FROM file"
.
Perhaps soon I’ll start logging issues and PRs 😄Finn Smith
06/25/2024, 12:50 PMfile_paths_query
a try as a better(?) / different approach, but it would be nice if this issue was fixed in the code as well.Finn Smith
06/25/2024, 1:06 PMI start to wonder how computationally expensive that isDo we know how often the
file_paths_query
queries are executed to refresh the list of files/dirs that inotify events are placed on?stefanmaerz
10/28/2024, 7:25 PMfile_paths_query
hitting watchdog limits in certain situations (like a user who had extraced the linux kernel in their home directory)...Peter
10/28/2024, 7:33 PMstefanmaerz
10/28/2024, 7:34 PM