tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
lol
0
fork
atom
overview
issues
pulls
pipelines
osquery: init at 2.5.2
Charles Strahan
8 years ago
53426f6c
29d2fe4a
+318
6 changed files
expand all
collapse all
unified
split
nixos
modules
module-list.nix
services
monitoring
osquery.nix
pkgs
tools
system
osquery
default.nix
misc.patch
platform-nixos.patch
top-level
all-packages.nix
+1
nixos/modules/module-list.nix
···
350
350
./services/monitoring/munin.nix
351
351
./services/monitoring/nagios.nix
352
352
./services/monitoring/netdata.nix
353
353
+
./services/monitoring/osquery.nix
353
354
./services/monitoring/prometheus/default.nix
354
355
./services/monitoring/prometheus/alertmanager.nix
355
356
./services/monitoring/prometheus/blackbox-exporter.nix
+91
nixos/modules/services/monitoring/osquery.nix
···
1
1
+
{ config, lib, pkgs, ... }:
2
2
+
3
3
+
with builtins;
4
4
+
with lib;
5
5
+
6
6
+
let
7
7
+
cfg = config.services.osquery;
8
8
+
9
9
+
in
10
10
+
11
11
+
{
12
12
+
13
13
+
options = {
14
14
+
15
15
+
services.osquery = {
16
16
+
17
17
+
enable = mkEnableOption "osquery";
18
18
+
19
19
+
loggerPath = mkOption {
20
20
+
type = types.path;
21
21
+
description = "Base directory used for logging.";
22
22
+
default = "/var/log/osquery";
23
23
+
};
24
24
+
25
25
+
pidfile = mkOption {
26
26
+
type = types.path;
27
27
+
description = "Path used for pid file.";
28
28
+
default = "/var/osquery/osqueryd.pidfile";
29
29
+
};
30
30
+
31
31
+
utc = mkOption {
32
32
+
type = types.bool;
33
33
+
description = "Attempt to convert all UNIX calendar times to UTC.";
34
34
+
default = true;
35
35
+
};
36
36
+
37
37
+
databasePath = mkOption {
38
38
+
type = types.path;
39
39
+
description = "Path used for database file.";
40
40
+
default = "/var/osquery/osquery.db";
41
41
+
};
42
42
+
43
43
+
extraConfig = mkOption {
44
44
+
type = types.attrs // {
45
45
+
merge = loc: foldl' (res: def: recursiveUpdate res def.value) {};
46
46
+
};
47
47
+
description = "Extra config to be recursively merged into the JSON config file.";
48
48
+
default = { };
49
49
+
};
50
50
+
};
51
51
+
52
52
+
};
53
53
+
54
54
+
config = mkIf cfg.enable {
55
55
+
56
56
+
environment.systemPackages = [ pkgs.osquery ];
57
57
+
58
58
+
environment.etc."osquery/osquery.conf".text = toJSON (
59
59
+
recursiveUpdate {
60
60
+
options = {
61
61
+
config_plugin = "filesystem";
62
62
+
logger_plugin = "filesystem";
63
63
+
logger_path = cfg.loggerPath;
64
64
+
database_path = cfg.databasePath;
65
65
+
utc = cfg.utc;
66
66
+
};
67
67
+
} cfg.extraConfig
68
68
+
);
69
69
+
70
70
+
systemd.services.osqueryd = {
71
71
+
description = "The osquery Daemon";
72
72
+
after = [ "network.target" "syslog.service" ];
73
73
+
wantedBy = [ "multi-user.target" ];
74
74
+
path = [ pkgs.osquery ];
75
75
+
preStart = ''
76
76
+
mkdir -p ${escapeShellArg cfg.loggerPath}
77
77
+
mkdir -p "$(dirname ${escapeShellArg cfg.pidfile})"
78
78
+
mkdir -p "$(dirname ${escapeShellArg cfg.databasePath})"
79
79
+
'';
80
80
+
serviceConfig = {
81
81
+
TimeoutStartSec = 0;
82
82
+
ExecStart = "${pkgs.osquery}/bin/osqueryd --logger_path ${escapeShellArg cfg.loggerPath} --pidfile ${escapeShellArg cfg.pidfile} --database_path ${escapeShellArg cfg.databasePath}";
83
83
+
KillMode = "process";
84
84
+
KillSignal = "SIGTERM";
85
85
+
Restart = "on-failure";
86
86
+
};
87
87
+
};
88
88
+
89
89
+
};
90
90
+
91
91
+
}
+76
pkgs/tools/system/osquery/default.nix
···
1
1
+
{ stdenv, lib, fetchFromGitHub, pkgconfig, cmake, pythonPackages
2
2
+
, udev, audit, aws-sdk-cpp, cryptsetup, lvm2, libgcrypt, libarchive
3
3
+
, libgpgerror, libuuid, iptables, apt, dpkg, lzma, lz4, bzip2, rpm
4
4
+
, beecrypt, augeas, libxml2, sleuthkit, yara, lldpd, google-gflags
5
5
+
, thrift, boost, rocksdb_lite, cpp-netlib, glog, gbenchmark, snappy
6
6
+
, openssl, linenoise-ng, file, doxygen, devicemapper
7
7
+
}:
8
8
+
9
9
+
let
10
10
+
thirdparty = fetchFromGitHub {
11
11
+
owner = "osquery";
12
12
+
repo = "third-party";
13
13
+
rev = "6919841175b2c9cb2dee8986e0cfe49191ecb868";
14
14
+
sha256 = "1kjxrky586jd1b2z1vs9cm7x1dxw51cizpys9kddiarapc2ih65j";
15
15
+
};
16
16
+
17
17
+
in
18
18
+
19
19
+
stdenv.mkDerivation rec {
20
20
+
name = "osquery-${version}";
21
21
+
version = "2.5.2";
22
22
+
23
23
+
# this is what `osquery --help` will show as the version.
24
24
+
OSQUERY_BUILD_VERSION = version;
25
25
+
26
26
+
src = fetchFromGitHub {
27
27
+
owner = "facebook";
28
28
+
repo = "osquery";
29
29
+
rev = version;
30
30
+
sha256 = "16isplk66qpvhrf041l0lxb4z6k7wwd1sg7kpsw2q6kivkxpnk3z";
31
31
+
};
32
32
+
33
33
+
patches = [ ./misc.patch ] ++ lib.optional stdenv.isLinux ./platform-nixos.patch;
34
34
+
35
35
+
nativeBuildInputs = [
36
36
+
pkgconfig cmake pythonPackages.python pythonPackages.jinja2
37
37
+
];
38
38
+
39
39
+
buildInputs = [
40
40
+
udev audit
41
41
+
42
42
+
(aws-sdk-cpp.override {
43
43
+
apis = [ "firehose" "kinesis" "sts" ];
44
44
+
customMemoryManagement = false;
45
45
+
})
46
46
+
47
47
+
lvm2 libgcrypt libarchive libgpgerror libuuid iptables.dev apt dpkg
48
48
+
lzma lz4 bzip2 rpm beecrypt augeas libxml2 sleuthkit
49
49
+
yara lldpd google-gflags thrift boost
50
50
+
cpp-netlib glog gbenchmark snappy openssl linenoise-ng
51
51
+
file doxygen devicemapper cryptsetup
52
52
+
53
53
+
# need to be consistent about the malloc implementation
54
54
+
(rocksdb_lite.override { jemalloc = null; gperftools = null; })
55
55
+
];
56
56
+
57
57
+
preConfigure = ''
58
58
+
export NIX_CFLAGS_COMPILE="-I${libxml2.dev}/include/libxml2 $NIX_CFLAGS_COMPILE"
59
59
+
60
60
+
cmakeFlagsArray+=(
61
61
+
-DCMAKE_LIBRARY_PATH=${cryptsetup}/lib
62
62
+
-DCMAKE_VERBOSE_MAKEFILE=ON
63
63
+
)
64
64
+
65
65
+
cp -r ${thirdparty}/* third-party
66
66
+
chmod +w -R third-party
67
67
+
'';
68
68
+
69
69
+
meta = with lib; {
70
70
+
description = "SQL powered operating system instrumentation, monitoring, and analytics";
71
71
+
homepage = "https://osquery.io/";
72
72
+
license = licenses.bsd3;
73
73
+
platforms = platforms.linux;
74
74
+
maintainers = with maintainers; [ cstrahan ];
75
75
+
};
76
76
+
}
+126
pkgs/tools/system/osquery/misc.patch
···
1
1
+
diff --git a/CMakeLists.txt b/CMakeLists.txt
2
2
+
index a976a46d..73a95575 100644
3
3
+
--- a/CMakeLists.txt
4
4
+
+++ b/CMakeLists.txt
5
5
+
@@ -125,14 +125,13 @@ else()
6
6
+
set(CXX_COMPILE_FLAGS "${CXX_COMPILE_FLAGS} -std=c++14 -stdlib=libc++")
7
7
+
else()
8
8
+
set(LINUX TRUE)
9
9
+
- set(CXX_COMPILE_FLAGS "${CXX_COMPILE_FLAGS} -std=c++14 -stdlib=libstdc++")
10
10
+
+ set(CXX_COMPILE_FLAGS "${CXX_COMPILE_FLAGS} -std=c++14")
11
11
+
endif()
12
12
+
set(POSIX TRUE)
13
13
+
endif()
14
14
+
15
15
+
if(POSIX)
16
16
+
add_compile_options(
17
17
+
- -Qunused-arguments
18
18
+
-Wstrict-aliasing
19
19
+
-Wno-missing-field-initializers
20
20
+
-Wno-unused-local-typedef
21
21
+
@@ -154,7 +153,6 @@ if(POSIX)
22
22
+
)
23
23
+
if(NOT FREEBSD)
24
24
+
add_compile_options(
25
25
+
- -Werror=shadow
26
26
+
-fvisibility=hidden
27
27
+
-fvisibility-inlines-hidden
28
28
+
)
29
29
+
@@ -439,6 +437,8 @@ endif()
30
30
+
31
31
+
if(APPLE)
32
32
+
LOG_PLATFORM("OS X")
33
33
+
+elseif(OSQUERY_BUILD_PLATFORM STREQUAL "nixos")
34
34
+
+ LOG_PLATFORM("NixOS")
35
35
+
elseif(OSQUERY_BUILD_PLATFORM STREQUAL "debian")
36
36
+
LOG_PLATFORM("Debian")
37
37
+
elseif(OSQUERY_BUILD_PLATFORM STREQUAL "ubuntu")
38
38
+
diff --git a/include/osquery/core.h b/include/osquery/core.h
39
39
+
index b597edee..b0628037 100644
40
40
+
--- a/include/osquery/core.h
41
41
+
+++ b/include/osquery/core.h
42
42
+
@@ -15,8 +15,9 @@
43
43
+
#include <string>
44
44
+
#include <vector>
45
45
+
46
46
+
-#if defined(__APPLE__) || defined(__FreeBSD__)
47
47
+
+#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__linux__)
48
48
+
#include <boost/thread/shared_mutex.hpp>
49
49
+
+#include <boost/thread/recursive_mutex.hpp>
50
50
+
#else
51
51
+
#include <shared_mutex>
52
52
+
#endif
53
53
+
@@ -188,7 +189,7 @@ inline bool isPlatform(PlatformType a, const PlatformType& t = kPlatformType) {
54
54
+
return (static_cast<int>(t) & static_cast<int>(a)) != 0;
55
55
+
}
56
56
+
57
57
+
-#if defined(__APPLE__) || defined(__FreeBSD__)
58
58
+
+#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__linux__)
59
59
+
#define MUTEX_IMPL boost
60
60
+
#else
61
61
+
#define MUTEX_IMPL std
62
62
+
@@ -204,10 +205,10 @@ using WriteLock = MUTEX_IMPL::unique_lock<Mutex>;
63
63
+
using ReadLock = MUTEX_IMPL::shared_lock<Mutex>;
64
64
+
65
65
+
/// Helper alias for defining recursive mutexes.
66
66
+
-using RecursiveMutex = std::recursive_mutex;
67
67
+
+using RecursiveMutex = MUTEX_IMPL::recursive_mutex;
68
68
+
69
69
+
/// Helper alias for write locking a recursive mutex.
70
70
+
-using RecursiveLock = std::lock_guard<std::recursive_mutex>;
71
71
+
+using RecursiveLock = MUTEX_IMPL::lock_guard<MUTEX_IMPL::recursive_mutex>;
72
72
+
}
73
73
+
74
74
+
/**
75
75
+
diff --git a/osquery/CMakeLists.txt b/osquery/CMakeLists.txt
76
76
+
index 77913d31..c833c289 100644
77
77
+
--- a/osquery/CMakeLists.txt
78
78
+
+++ b/osquery/CMakeLists.txt
79
79
+
@@ -157,6 +157,7 @@ ADD_OSQUERY_LINK_ADDITIONAL("cppnetlib-client-connections${WO_KEY}")
80
80
+
ADD_OSQUERY_LINK_CORE("glog${WO_KEY}")
81
81
+
82
82
+
if(POSIX)
83
83
+
+ ADD_OSQUERY_LINK_ADDITIONAL("benchmark")
84
84
+
ADD_OSQUERY_LINK_ADDITIONAL("snappy")
85
85
+
ADD_OSQUERY_LINK_ADDITIONAL("ssl")
86
86
+
ADD_OSQUERY_LINK_ADDITIONAL("crypto")
87
87
+
@@ -336,13 +337,6 @@ if(NOT OSQUERY_BUILD_SDK_ONLY)
88
88
+
89
89
+
install(DIRECTORY "${CMAKE_SOURCE_DIR}/packs/"
90
90
+
DESTINATION "${CMAKE_INSTALL_PREFIX}/share/osquery/packs" COMPONENT main)
91
91
+
- if(APPLE)
92
92
+
- install(FILES "${CMAKE_SOURCE_DIR}/tools/deployment/com.facebook.osqueryd.plist"
93
93
+
- DESTINATION "${CMAKE_INSTALL_PREFIX}/share/osquery/" COMPONENT main)
94
94
+
- else()
95
95
+
- install(PROGRAMS "${CMAKE_SOURCE_DIR}/tools/deployment/osqueryd.initd"
96
96
+
- DESTINATION "/etc/init.d/" RENAME "osqueryd" COMPONENT main)
97
97
+
- endif()
98
98
+
endif()
99
99
+
100
100
+
if(NOT SKIP_TESTS)
101
101
+
diff --git a/osquery/tables/system/linux/tests/md_tables_tests.cpp b/osquery/tables/system/linux/tests/md_tables_tests.cpp
102
102
+
index 126be362..119d361d 100644
103
103
+
--- a/osquery/tables/system/linux/tests/md_tables_tests.cpp
104
104
+
+++ b/osquery/tables/system/linux/tests/md_tables_tests.cpp
105
105
+
@@ -72,7 +72,7 @@ void GetDrivesForArrayTestHarness(std::string arrayName,
106
106
+
EXPECT_CALL(md, getArrayInfo(arrayDevPath, _))
107
107
+
.WillOnce(DoAll(SetArgReferee<1>(arrayInfo), Return(true)));
108
108
+
109
109
+
- Sequence::Sequence s1;
110
110
+
+ Sequence s1;
111
111
+
for (int i = 0; i < MD_SB_DISKS; i++) {
112
112
+
mdu_disk_info_t diskInfo;
113
113
+
diskInfo.number = i;
114
114
+
diff --git a/specs/windows/services.table b/specs/windows/services.table
115
115
+
index 4ac24ee9..657d8b99 100644
116
116
+
--- a/specs/windows/services.table
117
117
+
+++ b/specs/windows/services.table
118
118
+
@@ -12,7 +12,7 @@ schema([
119
119
+
Column("path", TEXT, "Path to Service Executable"),
120
120
+
Column("module_path", TEXT, "Path to ServiceDll"),
121
121
+
Column("description", TEXT, "Service Description"),
122
122
+
- Column("user_account", TEXT, "The name of the account that the service process will be logged on as when it runs. This name can be of the form Domain\UserName. If the account belongs to the built-in domain, the name can be of the form .\UserName."),
123
123
+
+ Column("user_account", TEXT, "The name of the account that the service process will be logged on as when it runs. This name can be of the form Domain\\UserName. If the account belongs to the built-in domain, the name can be of the form .\\UserName."),
124
124
+
])
125
125
+
implementation("system/windows/services@genServices")
126
126
+
examples([
+22
pkgs/tools/system/osquery/platform-nixos.patch
···
1
1
+
diff --git a/tools/get_platform.py b/tools/get_platform.py
2
2
+
index 3dd34516..f53ca83a 100644
3
3
+
--- a/tools/get_platform.py
4
4
+
+++ b/tools/get_platform.py
5
5
+
@@ -26,6 +26,8 @@ DEBIAN_VERSION = "/etc/debian_version"
6
6
+
GENTOO_RELEASE = "/etc/gentoo-release"
7
7
+
8
8
+
def _platform():
9
9
+
+ return ("nixos", "nixos")
10
10
+
+
11
11
+
osType, _, _, _, _, _ = platform.uname()
12
12
+
13
13
+
if osType == "Windows":
14
14
+
@@ -75,6 +77,8 @@ def _platform():
15
15
+
return (None, osType.lower())
16
16
+
17
17
+
def _distro(osType):
18
18
+
+ return "unknown_version"
19
19
+
+
20
20
+
def getRedhatDistroVersion(pattern):
21
21
+
with open(SYSTEM_RELEASE, "r") as fd:
22
22
+
contents = fd.read()
+2
pkgs/top-level/all-packages.nix
···
15340
15340
15341
15341
osmo = callPackage ../applications/office/osmo { };
15342
15342
15343
15343
+
osquery = callPackage ../tools/system/osquery { };
15344
15344
+
15343
15345
palemoon = callPackage ../applications/networking/browsers/palemoon {
15344
15346
# https://forum.palemoon.org/viewtopic.php?f=57&t=15296#p111146
15345
15347
stdenv = overrideCC stdenv gcc49;