web01: Finish goaccess module #162

Merged
clan-bot merged 1 commits from Qubasa-main into main 2024-04-14 17:09:38 +00:00
2 changed files with 38 additions and 7 deletions

View File

@ -4,7 +4,7 @@ let
# make the logs for this host "public" so that they show up in e.g. metrics # make the logs for this host "public" so that they show up in e.g. metrics
publog = vhost: lib.attrsets.unionOfDisjoint vhost { publog = vhost: lib.attrsets.unionOfDisjoint vhost {
extraConfig = (vhost.extraConfig or "") + '' extraConfig = (vhost.extraConfig or "") + ''
access_log /var/log/nginx/public.log vcombined; access_log /var/log/nginx/public.log vcombined compression;
''; '';
}; };
in in

View File

@ -1,14 +1,27 @@
{ stdenv, lib, pkgs, ... }: { stdenv, lib, pkgs, ... }:
let let
domain = "metrics.gchq.icu"; domain = "metrics.clan.lol";
priv_goaccess = "/var/lib/goaccess";
pub_goaccess = "/var/www/goaccess";
user-agent-list = pkgs.writeText "browsers.list" ''
# List of browsers and their categories
# e.g., WORD delimited by tab(s) \t TYPE
# TYPE can be any type and it's not limited to the ones below.
github-actions-checkout GitHubActions
git Git
connect-go Go
Go-http-client Go
curl Curl
'';
in in
{ {
users.users.goaccess = { users.users.goaccess = {
isSystemUser = true; isSystemUser = true;
group = "nginx"; group = "nginx";
createHome = true; createHome = true;
home = "/var/www/goaccess"; home = "${pub_goaccess}";
homeMode = "0774"; homeMode = "0774";
}; };
@ -17,8 +30,18 @@ in
access_log /var/log/nginx/private.log vcombined; access_log /var/log/nginx/private.log vcombined;
''; '';
systemd.tmpfiles.rules = [
"d ${priv_goaccess} 0755 goaccess nginx -"
"d ${priv_goaccess}/db 0755 goaccess nginx -"
"d ${pub_goaccess} 0755 goaccess nginx -"
];
# --browsers-file=/etc/goaccess/browsers.list
# https://raw.githubusercontent.com/allinurl/goaccess/master/config/browsers.list
systemd.services.goaccess = { systemd.services.goaccess = {
description = "GoAccess server monitoring"; description = "GoAccess server monitoring";
serviceConfig = { serviceConfig = {
User = "goaccess"; User = "goaccess";
Group = "nginx"; Group = "nginx";
@ -26,14 +49,22 @@ in
${pkgs.goaccess}/bin/goaccess \ ${pkgs.goaccess}/bin/goaccess \
-f /var/log/nginx/public.log \ -f /var/log/nginx/public.log \
--log-format=VCOMBINED \ --log-format=VCOMBINED \
--ignore-crawlers \
--browsers-file=${user-agent-list} \
--real-time-html \ --real-time-html \
--all-static-files \
--html-refresh=30 \ --html-refresh=30 \
--persist \
--restore \
--db-path=${priv_goaccess}/db \
--no-query-string \ --no-query-string \
--unknowns-log=${priv_goaccess}/unknowns.log \
--invalid-requests=${priv_goaccess}/invalid-requests.log \
--anonymize-ip \ --anonymize-ip \
--ignore-panel=HOSTS \ --ignore-panel=HOSTS \
--ws-url=wss://${domain}:443/ws \ --ws-url=wss://${domain}:443/ws \
--port=7890 \ --port=7890 \
-o index.html -o "${pub_goaccess}/index.html"
''; '';
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID"; ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
Type = "simple"; Type = "simple";
@ -41,14 +72,14 @@ in
RestartSec = "10s"; RestartSec = "10s";
# hardening # hardening
WorkingDirectory = "/var/www/goaccess"; WorkingDirectory = "${pub_goaccess}";
NoNewPrivileges = true; NoNewPrivileges = true;
PrivateTmp = true; PrivateTmp = true;
ProtectHome = "read-only"; ProtectHome = "read-only";
ProtectSystem = "strict"; ProtectSystem = "strict";
SystemCallFilter = "~@clock @cpu-emulation @debug @keyring @memlock @module @mount @obsolete @privileged @reboot @resources @setuid @swap @raw-io"; SystemCallFilter = "~@clock @cpu-emulation @debug @keyring @memlock @module @mount @obsolete @privileged @reboot @resources @setuid @swap @raw-io";
ReadOnlyPaths = "/"; ReadOnlyPaths = "/";
ReadWritePaths = [ "/proc/self" "/var/www/goaccess" ]; ReadWritePaths = [ "/proc/self" "${pub_goaccess}" "${priv_goaccess}" ];
PrivateDevices = "yes"; PrivateDevices = "yes";
ProtectKernelModules = "yes"; ProtectKernelModules = "yes";
ProtectKernelTunables = "yes"; ProtectKernelTunables = "yes";
@ -61,7 +92,7 @@ in
services.nginx.virtualHosts."${domain}" = { services.nginx.virtualHosts."${domain}" = {
addSSL = true; addSSL = true;
enableACME = true; enableACME = true;
root = "/var/www/goaccess"; root = "${pub_goaccess}";
locations."/ws" = { locations."/ws" = {
proxyPass = "http://127.0.0.1:7890"; proxyPass = "http://127.0.0.1:7890";