blob: dd6b26da95b2286f1403706734ae09b06eea542e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
{
lib,
pkgs,
config,
inputs,
...
}: let
cfg = config.goaccess;
in {
options."caddy-goaccess" = {
timeZone = lib.mkOption {
type = lib.types.str;
description = "time zone";
};
logFile = lib.mkOption {
type = lib.types.str;
description = "caddy log file for goaccess to read (must be chmod 775)";
};
websocketUrl = lib.mkOption {
type = lib.types.str;
description = "url that the frontend should use to attach to the service websocket";
};
};
config = let
settings = {
unix-socket = "/run/caddy-goaccess/socket";
ws-url = cfg.websocketUrl;
date-format = "%s";
log-format = "CADDY";
tz = cfg.timeZone;
log-file = cfg.logFile;
geoip-database = inputs.geolite-db;
output = "/run/caddy-goaccess/index.html";
real-time-html = "true";
external-assets = "true";
all-static-files = "false";
html-report-title = "stats@ganymede";
hl-header = "true";
agent-list = "false";
with-output-resolver = "false";
http-method = "yes";
http-protocol = "yes";
"4xx-to-unique-count" = "false";
ignore-crawlers = "false";
crawlers-only = "false";
unknowns-as-crawlers = "false";
real-os = "true";
};
in {
configData."goaccess.conf".text = settings |> builtins.mapAttrs (k: v: "${k} ${toString v}") |> builtins.attrValues |> lib.concatStringsSep "\n";
services."caddy-goaccess" = {
systemd.socket = {
description = "caddy-goaccess uds";
socketConfig = {
ListenStream = "/run/caddy-goaccess/socket";
SocketMode = "0660";
SocketUser = "goaccess";
SocketGroup = "caddy";
};
wantedBy = ["sockets.target"];
};
systemd.service = {
description = "GoAccess Real-Time Log Analyzer";
restartIfChanged = true;
wants = ["network-online.target" "caddy.service"];
after = ["network-online.target" "caddy.service"];
requires = ["caddy-goaccess.socket"];
serviceConfig = {
Type = "simple";
DynamicUser = true;
SupplimentaryGroup = "caddy"; # to read caddy log files
RuntimeDirectory = "caddy-goaccess"; # /run/caddy-goaccess
ExecStart = "${pkgs.goaccess}/bin/goaccess -p ${config.configData."goaccess.conf".path}";
# hardening stuff
AmbientCapabilities = [];
CapabilityBoundingSet = [
"~CAP_RAWIO"
"~CAP_MKNOD"
"~CAP_AUDIT_CONTROL"
"~CAP_AUDIT_READ"
"~CAP_AUDIT_WRITE"
"~CAP_SYS_BOOT"
"~CAP_SYS_TIME"
"~CAP_SYS_MODULE"
"~CAP_SYS_PACCT"
"~CAP_LEASE"
"~CAP_LINUX_IMMUTABLE"
"~CAP_IPC_LOCK"
"~CAP_BLOCK_SUSPEND"
"~CAP_WAKE_ALARM"
"~CAP_SYS_TTY_CONFIG"
"~CAP_MAC_ADMIN"
"~CAP_MAC_OVERRIDE"
"~CAP_NET_ADMIN"
"~CAP_NET_BROADCAST"
"~CAP_NET_RAW"
"~CAP_SYS_ADMIN"
"~CAP_SYS_PTRACE"
"~CAP_SYSLOG"
];
DevicePolicy = "closed";
KeyringMode = "private";
LockPersonality = true;
NoNewPrivileges = true;
PrivateDevices = true;
PrivateMounts = true;
PrivateTmp = true;
ProtectClock = true;
ProtectControlGroups = true;
ProtectHome = true;
ProtectHostname = true;
ProtectKernelLogs = true;
ProtectKernelModules = true;
ProtectKernelTunables = true;
ProtectSystem = "full";
RemoveIPC = true;
RestrictAddressFamilies = [
"AF_UNIX"
"AF_INET"
"AF_INET6"
];
RestrictNamespaces = true;
RestrictRealtime = true;
};
wantedBy = ["multi-user.target"];
};
};
};
}
|