Skip to content
This repository was archived by the owner on Jul 1, 2026. It is now read-only.

Commit 015cbee

Browse files
author
Moritz Baumeister
committed
sre(layer10): deep-refactoring and hardening of all infrastructure services to aviation grade level
1 parent 94f4a45 commit 015cbee

5 files changed

Lines changed: 188 additions & 82 deletions

File tree

10-infrastructure/adguardhome.nix

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,20 @@ in
3636
bootstrap_dns = dnsBootstrap;
3737
fallback_dns = config.my.configs.network.dnsFallback;
3838

39-
# Performance Tuning
40-
cache_size = 33554432;
41-
cache_ttl_min = 300;
42-
cache_ttl_max = 86400;
39+
# 🚀 Ultra Performance Tuning (NixOS 25.11 / 16GB RAM)
40+
cache_size = 67108864; # 64MB Cache (Verdoppelt für 16GB RAM)
41+
cache_ttl_min = 600; # 10 Minuten Minimum (Reduziert Upstream Last)
42+
cache_ttl_max = 86400; # 24 Stunden Maximum
4343
cache_optimistic = true;
4444
fastest_addr = true;
4545

46-
# Privacy & Security
46+
# Security & Privacy
4747
edns_cs_enabled = false;
4848
dnssec_enabled = true;
49+
anonymize_client_ip = true; # SRE: Privacy First
4950
};
5051

5152
# ── EXPERT BLOCKLISTS (Single Source of Truth) ────────────────────────
52-
# Diese Listen decken 99% aller Werbung, Tracker und Malware ab.
5353
filtering = {
5454
protection_enabled = true;
5555
filtering_enabled = true;
@@ -86,24 +86,31 @@ in
8686
'';
8787
};
8888

89-
# ── SRE SANDBOXING ───────────────────────────────────────────────────────
90-
systemd.services.AdGuardHome.serviceConfig = {
89+
# ── SRE SANDBOXING (Aviation Grade) ──────────────────────────────────────
90+
systemd.services.adguardhome.serviceConfig = { # SSoT: Korrekter Service Name
9191
ProtectSystem = "strict";
9292
ProtectHome = true;
9393
PrivateTmp = true;
9494
PrivateDevices = true;
9595
NoNewPrivileges = true;
9696
CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" "CAP_NET_RAW" ];
9797
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" "CAP_NET_RAW" ];
98-
ReadWritePaths = [ "/var/lib/AdGuardHome" ];
98+
ReadWritePaths = [ "/var/lib/adguardhome" ]; # SSoT: Lowercase Pfad prüfen
9999
LockPersonality = true;
100100
RestrictRealtime = true;
101101
RestrictSUIDSGID = true;
102-
SystemCallFilter = [ "@system-service" ];
102+
MemoryDenyWriteExecute = true; # SRE Hardening
103+
ProtectControlGroups = true;
104+
ProtectKernelModules = true;
105+
ProtectKernelTunables = true;
106+
SystemCallFilter = [ "@system-service" "~@privileged" "~@resources" ];
103107
OOMScoreAdjust = -200;
104108
};
105109
}
106110
/**
107111
* technical_integrity:
108112
* eof_marker: NIXHOME_VALID_EOF
113+
* audit_trail:
114+
* last_reviewed: 2026-03-02
115+
* ---
109116
*/

10-infrastructure/clamav.nix

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,53 +3,78 @@
33
* nms_version: 2.3
44
* identity:
55
* id: NIXH-10-INF-003
6-
* title: "ClamAV (SRE Hardened)"
6+
* title: "ClamAV (SRE Exhausted)"
77
* layer: 10
8-
* summary: Antivirus protection with resource limits and automated updates.
8+
* summary: Professional antivirus protection with resource-aware scheduling and sandboxing.
99
* source_nixpkgs: https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/services/security/clamav.nix
1010
* ---
1111
*/
1212
{ config, lib, pkgs, ... }:
1313
{
14-
# ── CLAMAV DAEMON & UPDATER ──────────────────────────────────────────────
14+
# ── CLAMAV DAEMON & UPDATER (NMS v2.3 Standard) ────────────────────────
1515
services.clamav = {
1616
daemon.enable = true;
1717
updater.enable = true; # freshclam
1818

1919
# 🕵️ SRE SCANNER (Wöchentlicher Scan)
2020
scanner = {
2121
enable = true;
22-
interval = "Sat *-*-* 03:00:00"; # Samstags nachts
22+
interval = "Sat *-*-* 03:00:00"; # Samstags nachts (Minimale Last)
2323
scanDirectories = [ "/home" "/var/lib" "/etc" ];
24+
# SRE: Exclude media (zu groß für wöchentlichen Clam-Scan)
25+
excludePath = [ "/mnt/media" "/mnt/fast-pool/downloads" ];
26+
};
27+
28+
# Advanced Options (Aviation Grade)
29+
daemon.settings = {
30+
LogTime = true;
31+
LogVerbose = false;
32+
MaxScanSize = "100M";
33+
MaxFileSize = "50M";
34+
PCREMatchLimit = 10000;
35+
PCREMaxRecurse = 1000;
2436
};
2537
};
2638

27-
# ── RESSOURCENSCHUTZ (Schutz vor CPU-Heißlaufen) ────────────────────────
39+
# ── RESSOURCENSCHUTZ (Schutz vor CPU-Heißlaufen auf i3-9100) ─────────────
2840
# ClamAV kann beim Scannen extrem viel CPU fressen.
29-
# Wir limitieren den Scan-Prozess auf 2 Kerne und geben ihm 'idle' Priorität.
41+
# Wir limitieren den Scan-Prozess auf 'idle' Priorität.
3042
systemd.services.clamdscan = {
3143
serviceConfig = {
3244
CPUWeight = 20;
3345
IOWeight = 20;
3446
CPUSchedulingPolicy = "idle";
3547
IOSchedulingClass = "idle";
48+
# SRE: Ressourcen-Isolation
49+
Slice = "system-security.slice";
3650
};
3751
};
3852

39-
# ── SRE SANDBOXING ───────────────────────────────────────────────────────
53+
# ── SRE SANDBOXING (Level: Exhausted) ──────────────────────────────────
4054
systemd.services.clamav-daemon.serviceConfig = {
41-
# Aus nixpkgs übernommen
4255
ProtectSystem = "strict";
56+
ProtectHome = true;
4357
PrivateTmp = true;
4458
PrivateDevices = true;
4559
NoNewPrivileges = true;
46-
# ClamAV braucht keine Netzwerk-Capabilities
60+
# ClamAV braucht keine Netzwerk-Capabilities außer DNS für Updates
4761
CapabilityBoundingSet = [ "" ];
4862
# OOM-Schutz: ClamAV darf im Zweifel als erstes sterben
4963
OOMScoreAdjust = 1000;
64+
65+
# Aviation Grade Hardening
66+
MemoryDenyWriteExecute = true;
67+
ProtectControlGroups = true;
68+
ProtectKernelModules = true;
69+
ProtectKernelTunables = true;
70+
RestrictRealtime = true;
71+
RestrictSUIDSGID = true;
5072
};
5173
}
5274
/**
5375
* technical_integrity:
5476
* eof_marker: NIXHOME_VALID_EOF
77+
* audit_trail:
78+
* last_reviewed: 2026-03-02
79+
* ---
5580
*/

10-infrastructure/cloudflared-tunnel.nix

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* nms_version: 2.3
44
* identity:
55
* id: NIXH-10-INF-004
6-
* title: "Cloudflared Tunnel"
6+
* title: "Cloudflared Tunnel (SRE Exhausted)"
77
* layer: 10
88
* architecture:
99
* req_refs: [REQ-INF]
@@ -51,13 +51,37 @@ in
5151
}
5252
];
5353

54-
systemd.services."cloudflared-tunnel-${cfg.tunnelId}".preStart = ''
55-
if [ ! -f "${creds}" ]; then
56-
echo "FEHLER: Cloudflared-Credentials fehlen unter ${creds}"
57-
echo "Lösung: sops -d /etc/nixos/secrets.yaml | jq -r '.[\"cloudflared_creds\"]' > ${creds}"
58-
exit 1
59-
fi
60-
'';
54+
systemd.services."cloudflared-tunnel-${cfg.tunnelId}" = {
55+
preStart = ''
56+
if [ ! -f "${creds}" ]; then
57+
echo "FEHLER: Cloudflared-Credentials fehlen unter ${creds}"
58+
echo "Lösung: sops -d /etc/nixos/secrets.yaml | jq -r '.[\"cloudflared_creds\"]' > ${creds}"
59+
exit 1
60+
fi
61+
'';
62+
63+
# ── SRE SANDBOXING (Level: High) ──────────────────────────────────────
64+
serviceConfig = {
65+
ProtectSystem = "strict";
66+
ProtectHome = true;
67+
PrivateTmp = true;
68+
PrivateDevices = true;
69+
NoNewPrivileges = true;
70+
# Cloudflared braucht Netz-Caps für UDP (QUIC)
71+
CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" "CAP_NET_RAW" ];
72+
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" "CAP_NET_RAW" ];
73+
74+
# Aviation Grade Hardening
75+
ProtectControlGroups = true;
76+
ProtectKernelModules = true;
77+
ProtectKernelTunables = true;
78+
RestrictRealtime = true;
79+
RestrictSUIDSGID = true;
80+
81+
# OOM-Schutz: Edge-Anbindung ist kritisch
82+
OOMScoreAdjust = -500;
83+
};
84+
};
6185

6286
services.cloudflared = {
6387
enable = true;
@@ -69,6 +93,9 @@ in
6993
originRequest = {
7094
noTLSVerify = true;
7195
originServerName = "${cfg.wildcardPrefix}.${cfg.domain}";
96+
# Performance Tuning
97+
http2Origin = true;
98+
keepAliveConnections = 128;
7299
};
73100
};
74101
};
@@ -77,25 +104,10 @@ in
77104
};
78105
};
79106
}
80-
81-
82-
83-
84-
85-
86-
87-
88-
89-
90-
91-
92107
/**
93-
* ---
94108
* technical_integrity:
95-
* checksum: sha256:eb34038a82b8ef8762e4bcbe1dc0b5584943d865fc3bd8f95f65a8f3036dc8b9
96109
* eof_marker: NIXHOME_VALID_EOF
97110
* audit_trail:
98-
* last_reviewed: 2026-02-28
99-
* complexity_score: 2
111+
* last_reviewed: 2026-03-02
100112
* ---
101113
*/

10-infrastructure/netdata.nix

Lines changed: 63 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,57 +3,81 @@
33
* nms_version: 2.3
44
* identity:
55
* id: NIXH-10-INF-011
6-
* title: "Netdata (SRE Hardened)"
6+
* title: "Netdata (SRE Exhaustion)"
77
* layer: 10
8-
* summary: Real-time performance monitoring with dbengine storage and strict sandboxing.
8+
* summary: Real-time performance monitoring with high-retention dbengine and strict sandboxing.
99
* source_nixpkgs: https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/services/monitoring/netdata.nix
1010
* ---
1111
*/
1212
{ config, lib, ... }:
1313
let
14-
myLib = import ../lib/helpers.nix { inherit lib; };
1514
port = config.my.ports.netdata;
16-
serviceBase = myLib.mkService {
17-
inherit config;
18-
name = "netdata";
19-
port = port;
20-
useSSO = true;
21-
description = "Real-time performance monitoring (Exhausted)";
22-
};
15+
domain = config.my.configs.identity.domain;
2316
in
24-
lib.mkMerge [
25-
serviceBase
26-
{
27-
# 🚀 NETDATA EXHAUSTION
28-
services.netdata = {
29-
enable = true;
30-
31-
# VOLL-DEKLARATIVE CONFIG
32-
config = {
33-
global = {
34-
"memory mode" = "dbengine";
35-
"history" = 86400; # 24 Stunden Historie
36-
};
37-
web = {
38-
"allow connections from" = "localhost 127.0.0.1";
39-
"default port" = toString port;
40-
};
41-
db = {
42-
"dbengine tier 1 retention days" = 7; # SRE: Retention Policy
43-
};
17+
{
18+
# 🚀 NETDATA EXHAUSTION
19+
services.netdata = {
20+
enable = true;
21+
22+
# ── VOLL-DEKLARATIVE CONFIG (SRE Optimized) ──────────────────────────
23+
config = {
24+
global = {
25+
"memory mode" = "dbengine";
26+
"page cache size" = "256"; # MB (Optimiert für 16GB RAM)
27+
"dbengine disk space" = "4096"; # 4GB Disk-Speicher für Metriken
28+
"history" = 86400; # 24 Stunden High-Res
29+
};
30+
web = {
31+
"allow connections from" = "localhost 127.0.0.1";
32+
"default port" = toString port;
33+
"mode" = "static-threaded"; # Performance Boost
34+
};
35+
db = {
36+
"dbengine tier 1 retention days" = 30; # SRE: Langzeit-Metriken (30 Tage)
37+
};
38+
# SRE: Health Monitoring (Alarme)
39+
health = {
40+
"enabled" = "yes";
4441
};
4542
};
43+
};
44+
45+
# ── CADDY INTEGRATION ────────────────────────────────────────────────────
46+
services.caddy.virtualHosts."netdata.${domain}" = {
47+
extraConfig = ''
48+
import sso_auth
49+
reverse_proxy 127.0.0.1:${toString port}
50+
'';
51+
};
52+
53+
# ── SRE SANDBOXING (Level: Exhausted) ──────────────────────────────────
54+
systemd.services.netdata.serviceConfig = {
55+
ProtectSystem = "full";
56+
ProtectHome = true;
57+
PrivateTmp = true;
58+
PrivateDevices = true;
59+
NoNewPrivileges = true;
60+
# SRE: Nur absolut notwendige Capabilities
61+
CapabilityBoundingSet = [ "CAP_DAC_READ_SEARCH" "CAP_SYS_PTRACE" "CAP_NET_RAW" ];
62+
AmbientCapabilities = [ "CAP_DAC_READ_SEARCH" "CAP_SYS_PTRACE" "CAP_NET_RAW" ];
4663

47-
# systemd Hardening
48-
systemd.services.netdata.serviceConfig = {
49-
ProtectSystem = lib.mkForce "full";
50-
# SRE: Nur absolut notwendige Capabilities
51-
CapabilityBoundingSet = [ "CAP_DAC_READ_SEARCH" "CAP_SYS_PTRACE" "CAP_NET_RAW" ];
52-
OOMScoreAdjust = 1000; # Monitoring darf im Notfall zuerst sterben
53-
};
54-
}
55-
]
64+
# Ressourcen-Limitierung (Monitoring darf System nicht lahmlegen)
65+
MemoryMax = "1G";
66+
CPUWeight = 50;
67+
OOMScoreAdjust = 1000; # Monitoring darf im Notfall zuerst sterben
68+
69+
# Hardening
70+
RestrictRealtime = true;
71+
RestrictSUIDSGID = true;
72+
ProtectControlGroups = true;
73+
ProtectKernelModules = true;
74+
ProtectKernelTunables = true;
75+
};
76+
}
5677
/**
5778
* technical_integrity:
5879
* eof_marker: NIXHOME_VALID_EOF
80+
* audit_trail:
81+
* last_reviewed: 2026-03-02
82+
* ---
5983
*/

0 commit comments

Comments
 (0)