osquery inotify是否在目录或文件上安装观察器

Does osquery inotify install watcher on directory or files

我正在使用 osquery 来监视文件和文件夹以获取对这些文件的任何操作的事件。 osquery配置有一个特定的语法:

我正在尝试评估在观看大量目录时的内存使用情况。在这个过程中我发现了以下统计数据:

例如:对于 "/etc/%.conf"

$ grep -r "^inotify" /proc/$PID/fdinfo/
18:inotify wd:1 ino:120001 sdev:800001 mask:3ce ignored_mask:0 fhandle-bytes:8 fhandle-type:1 f_handle:01001200bc0f1cab

$ printf "%d\n" 0x120001
1179649

$ sudo debugfs -R "ncheck 1179649" /dev/sda1
debugfs 1.43.4 (31-Jan-2017)
Inode   Pathname
1179649 //etc

inotify watch 建立在此处的整个目录上,但事件仅针对匹配的文件报告/etc/*.conf。 osquery 是否根据提供的 file_paths 过滤事件,这是我假设的,但不确定。

我为支持上述说法而进行的另一个实验是,使用 inotify(7) 中的源代码和 运行 特定文件的观察者。当我检查 inotify 观察者列表时,它只显示:

$ ./a.out /tmp/inotify.cc &

$ cat /proc/$PID/fdinfo/3
...
inotify wd:1 ino:1a1 sdev:800001 mask:38 ignored_mask:0 fhandle-bytes:8 fhandle-type:1 f_handle:a1010000aae325d7

$ sudo debugfs -R "ncheck 417" /dev/sda1
debugfs 1.43.4 (31-Jan-2017)
Inode   Pathname
417 /tmp/inotify.cc

所以,根据这个实验,在单个文件上建立观察者是可能的(从 inotify 手册页中可以清楚地看出)。这支持了 osquery 正在根据提供的文件模式进行某种过滤的说法。

有人可以验证声明或提供其他信息吗?


我的 osquery 配置:

{
  "options": {
    "host_identifier": "hostname",
    "schedule_splay_percent": 10
  },
  "schedule": {
    "file_events": {
      "query": "SELECT * FROM file_events;",
      "interval": 5
    }
  },

  "file_paths": {
    "sys": ["/etc/%.conf"]
  }
}

$ osqueryd --version
osqueryd version 3.3.2

$ uname -a
Linux lab 4.9.0-6-amd64 #1 SMP Debian 4.9.88-1+deb9u1 (2018-05-07) x86_64 GNU/Linux

听起来像是一些很棒的侦探!

我认为源代码中的注释支持这一点。值得一读。我认为相关文件: