Skip to content

Commit 6b33528

Browse files
blackbox
1 parent 2b435c5 commit 6b33528

File tree

5 files changed

+125
-10
lines changed

5 files changed

+125
-10
lines changed

hp/hp4/blackbox.nix

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,13 +318,36 @@ let
318318

319319
in {
320320
# Blackbox exporter configuration
321+
# systemctl status prometheus-blackbox-exporter
322+
# journalctl -u prometheus-blackbox-exporter -f -n 20
321323
services.prometheus.exporters.blackbox = {
322324
enable = true;
323325
port = 9115;
324-
listenAddress = "::1";
326+
listenAddress = "127.0.0.1";
325327
configFile = pkgs.writeText "blackbox.yml" (builtins.toJSON blackboxConfig);
326328
};
327329

330+
# Systemd service configuration for blackbox exporter with memory limits
331+
systemd.services.prometheus-blackbox-exporter = {
332+
serviceConfig = {
333+
# Resource limits
334+
MemoryMax = "300M";
335+
MemoryHigh = "280M";
336+
CPUQuota = "25%";
337+
TasksMax = 100;
338+
339+
# Process limits
340+
LimitNOFILE = 1024;
341+
LimitNPROC = 50;
342+
343+
# Environment variable for Go memory limit (260MB = ~90% of 300MB)
344+
Environment = [ "GOMEMLIMIT=260MiB" ];
345+
346+
# Nice priority
347+
Nice = 10;
348+
};
349+
};
350+
328351
# Export targets for use in prometheus.nix
329352
_module.args.blackboxTargets = targets;
330353
_module.args.wireguardTargets = flatWireguardTargets;

hp/hp4/grafana.nix

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# https://search.nixos.org/options?query=services.grafana
55
# https://xeiaso.net/blog/prometheus-grafana-loki-nixos-2020-11-20/
66
# https://grafana.com/grafana/dashboards/1860-node-exporter-full/
7+
# https://grafana.com/grafana/dashboards/7587-prometheus-blackbox-exporter/
78
services.grafana = {
89
enable = true;
910
#openFirewall = true; # this doesn't exist
@@ -19,6 +20,25 @@
1920
serve_from_sub_path = true;
2021
enable_gzip = true;
2122
};
23+
24+
# Security settings - set persistent admin password
25+
security = {
26+
admin_user = "admin";
27+
admin_password = "adin"; # Change this to your desired password
28+
admin_email = "admin@localhost";
29+
# Disable initial admin creation to prevent password resets
30+
disable_initial_admin_creation = false;
31+
};
32+
33+
# User settings
34+
users = {
35+
# Allow sign up (optional - set to false for more security)
36+
allow_sign_up = false;
37+
# Auto assign new users to main organization
38+
auto_assign_org = true;
39+
# Default role for new users
40+
auto_assign_org_role = "Viewer";
41+
};
2242
};
2343
};
2444
}

hp/hp4/nginx.nix

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,24 @@
9898
process.group = "smokeping";
9999
socket = { inherit (config.services.nginx) user group; };
100100
};
101+
102+
# Systemd service configuration for nginx with resource limits
103+
systemd.services.nginx = {
104+
serviceConfig = {
105+
# Resource limits - moderate for web server
106+
MemoryMax = "300M";
107+
MemoryHigh = "250M";
108+
CPUQuota = "20%";
109+
TasksMax = 200;
110+
111+
# Process limits
112+
LimitNOFILE = 65536;
113+
LimitNPROC = 100;
114+
115+
# Nice priority
116+
Nice = 10;
117+
};
118+
};
101119
}
102120
# {
103121
# # https://nixos.wiki/wiki/Nginx

hp/hp4/pdns-recursor.nix

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,75 @@
11
{ config, lib, pkgs, ... }:
22

33
{
4-
# PowerDNS Recursor configuration
4+
# PowerDNS Recursor
55
# This acts as a local DNS cache and forwards queries to 172.16.50.1
6+
# sudo lsof -i :53
7+
# systemctl status pdns-recursor
68
services.pdns-recursor = {
79
enable = true;
810

911
# Bind to localhost only for security
1012
dns.address = [ "::1" "127.0.0.1" ];
1113

1214
# Allow queries from localhost only
13-
dns.allowFrom = [ "127.0.0.0/8" "::1/128" ];
15+
dns.allowFrom = [ "::1/128" "127.0.0.0/8" ];
1416

1517
# API configuration (for monitoring)
1618
api.address = "::1";
1719
api.port = 8082;
1820
api.allowFrom = [ "127.0.0.1" "::1" ];
1921

20-
# Forward all zones to the upstream DNS server
21-
forwardZones = {
22-
"." = "172.16.50.1"; # Forward all queries to upstream DNS
22+
# Configure DNS settings for proper DNSSEC validation
23+
settings = {
24+
# Enable DNSSEC validation
25+
dnssec = "validate";
26+
# Set query local address to enable IPv6 for outgoing queries
27+
query-local-address = "::";
28+
# Disable security polling to avoid external queries
29+
security-poll-suffix = "";
30+
# Configure forward zones for specific domains if needed
31+
# forward-zones = "example.com=172.16.50.1";
2332
};
2433

25-
# DNSSEC validation
26-
dnssecValidation = "validate";
27-
2834
# Export /etc/hosts entries
2935
exportHosts = true;
3036

3137
# Serve RFC1918 reverse zones locally
3238
serveRFC1918 = true;
3339
};
3440

41+
# Systemd service configuration for pdns-recursor with resource limits
42+
systemd.services.pdns-recursor = {
43+
serviceConfig = {
44+
# Resource limits - conservative for DNS service
45+
MemoryMax = "100M";
46+
MemoryHigh = "90M";
47+
CPUQuota = "15%";
48+
TasksMax = 50;
49+
50+
# Process limits
51+
LimitNPROC = 100;
52+
53+
# Nice priority
54+
Nice = 15;
55+
};
56+
};
57+
3558
# Firewall rules for pdns-recursor
3659
networking.firewall.allowedUDPPorts = [ 53 ];
3760
networking.firewall.allowedTCPPorts = [ 53 8082 ];
3861

3962
# Configure system to use local pdns-recursor
40-
networking.nameservers = [ "::1" "127.0.0.1" ];
63+
#networking.nameservers = [ "::1" "127.0.0.1" ];
64+
networking.nameservers = [ "172.16.50.1" ];
4165
networking.resolvconf.useLocalResolver = true;
66+
67+
environment.etc."resolv.conf".text = ''
68+
# pdns
69+
nameserver ::1
70+
nameserver 127.0.0.1
71+
# emergency cloudflare
72+
nameserver 2606:4700:4700::1111
73+
nameserver 1.1.1.1
74+
'';
4275
}

hp/hp4/prometheus.nix

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,27 @@ in {
158158
];
159159
};
160160

161+
# Systemd service configuration for Prometheus with security restrictions
162+
systemd.services.prometheus = {
163+
serviceConfig = {
164+
# Resource limits - generous for time series storage
165+
MemoryMax = "10G";
166+
MemoryHigh = "9.5G";
167+
CPUQuota = "50%";
168+
TasksMax = 500;
169+
170+
# Process limits
171+
LimitNOFILE = 65536;
172+
LimitNPROC = 200;
173+
174+
# Environment variable for Go memory limit (9GB = ~90% of 10GB limit)
175+
Environment = [ "GOMEMLIMIT=9GiB" ];
176+
177+
# Nice priority
178+
Nice = 5;
179+
};
180+
};
181+
161182
# Firewall rules for Prometheus
162183
networking.firewall.allowedTCPPorts = [ 9090 ];
163184
}

0 commit comments

Comments
 (0)