Repository navigation
Expand file tree
/
Copy pathdefault.nix
More file actions
1740 lines (1601 loc) · 69.1 KB
/
Copy pathdefault.nix
File metadata and controls
1740 lines (1601 loc) · 69.1 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Edit this configuration file to define what should be installed on
# your system. Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).
{
config,
pkgs,
lib,
modulesPath,
meshos,
...
}:
let
hostName = "ghostgate";
baseDomain = "nixos.lv";
domain = "dc.${baseDomain}";
# ath10k on pciex4
onboardWifi = "wlp7s0";
wwan1 = onboardWifi;
# mt76x2u on internal M.2
internalM2Wifi = "wlp0s13f0u1";
# mt76x2u on external USB-A
externalUSBWifi = "wlp0s13f0u2";
# mt76x2u on internal USB-A
internalUSBWifi = "wlp0s20f0u4";
# mt76x0u
externalUSBTinyWifi = "wlp0s20f0u9";
wanInterface = "enp3s0";
wanInterfaces = [ wanInterface ];
nocInterfaces = [
"enp4s0"
"enp5s0"
];
arenaInterface = "enp6s0";
trunkInterface1 = "enp2s0f0np0"; # lower 10G SFP -> arena (attendee switch 10G uplink)
trunkInterface2 = "enp2s0f1np1"; # higher 10G SFP -> citadel (build+ctf VLAN trunk)
# The lower SFP joins the arena bridge so an attendee switch on it lands on the
# arena L2 over 10G (the higher SFP stays the citadel backbone).
arenaInterfaces = [
arenaInterface
trunkInterface1
];
# Shared event-router helpers (kea/knot/kresd builders).
erlib = import ../../modules/event-router/lib.nix { inherit lib pkgs; };
# NOC management network.
noc = erlib.mkNet {
id = 1;
base = "10.4.0";
subdomain = "noc";
inherit domain;
};
# Build machines.
build = erlib.mkNet {
id = 2;
base = "10.4.1";
subdomain = "build";
inherit domain;
};
# CTF machines
ctf = erlib.mkNet {
id = 3;
base = "10.4.2";
subdomain = "ctf";
inherit domain;
};
# Stupid shit
iot = erlib.mkNet {
id = 4;
base = "10.4.3";
subdomain = "iot";
inherit domain;
};
# Attendee network.
arena = erlib.mkArena {
self = "ghostgate";
inherit domain;
};
# Nebula lighthouse/relay UDP ports (the cloud nodes' entry ports). Mesh
# clients' traffic to these bypasses ghostgate's encrypted arena routing, so a
# 2420 falling back through ghostgate can bootstrap its own Nebula in the
# clear — the underlay can't be tunneled inside ghostgate's Nebula (circular).
lighthousePorts = lib.unique (
map (n: config.networking.mesh.plan.hosts.${n}.nebula.port) [
"adamantia"
"brass"
"crystal"
"dagoth"
]
);
# Public IPv4 underlay endpoints of the cloud Nebula nodes (same hosts as
# lighthousePorts). ghostgate's full-tunnel egress (below) must NEVER route
# traffic to these into the Nebula table, or it would tunnel the underlay
# through itself. Derived from the plan so it can't drift.
nebulaUnderlayV4 = lib.unique (
lib.concatMap
(
n:
builtins.filter (
a: lib.strings.hasInfix "." a
) config.networking.mesh.plan.hosts.${n}.nebula.entryAddresses
)
[
"adamantia"
"brass"
"crystal"
"dagoth"
]
);
# The Nebula service user's uid, pinned below. The full-tunnel rules match
# Nebula's own underlay by owner, but must do so numerically: the build-time
# `nft --check` runs in a sandbox with no user database, so it cannot resolve
# the name. See erlib.nebulaServiceUser for the full write-up of this gotcha.
nebulaServiceUser = erlib.nebulaServiceUser "arena";
nebulaUserUid = config.users.users.${nebulaServiceUser}.uid;
in
{
imports = [
../../modules/event-router/common.nix
../../modules/hydra.nix
../../modules/harmonia-cache.nix
../../modules/citadel-builder.nix
../../modules/pxe.nix
../../modules/home-assistant.nix
../../modules/mt76.nix
../../modules/ctf-recon-bluetooth.nix
../../modules/ctf-recon-ipxe.nix
../../modules/scraper-guard.nix
# pcscd access to the signing YubiKey (nixos-lv-ca lives on it).
../../modules/yubikey-pcscd.nix
./hardware-configuration.nix
];
# RF scavenger-hunt find (Recon7 "Ghost in the Piconet"): advertise the flag as
# this box's Bluetooth device name. Flag provisioned out-of-band at
# /etc/nixctf/flag-recon-bluetooth (not committed).
nixVegas.ctfReconBluetooth.enable = true;
# Netboot scavenger-hunt find (Recon2 "Chain Loader"): inject the flag as an
# iPXE `set` variable into the menu this box serves at /boot/menu.ipxe. Flag
# provisioned out-of-band at /etc/nixctf/flag-recon-ipxe (not committed).
nixVegas.ctfReconIpxe.enable = true;
# Trust the key the fleet's Hydra signs with (citadel's). MeshOS only injects
# a cache set's server.pubkey into CLIENTS of that set, and this box is the
# server of the `cnl` set but deliberately a client of none
# (plan cache.client.sets = [ ], to keep the dead gvh substituters out of
# nix.conf) -- so it never received its own set's key. Reference the plan's
# constant rather than duplicating the literal; additive extra-* so MeshOS's
# mkForce of trusted-public-keys can't drop it. Also what /keys on
# cache.nixos.lv serves (see the nginx vhost).
nix.settings.extra-trusted-public-keys = [
config.networking.mesh.plan.hosts.ghostgate.cache.server.pubkey
];
# Scraper / abuse control (modules/scraper-guard.nix). ghostgate sits behind
# brass's L4 SNI router, so every public packet arrives from 10.6.6.7: the
# real client address exists only via PROXY protocol (realIpFrom; the :4443
# proxyProtocol listener is in services.nginx.defaultListen), and bans must
# be enforced at the nginx layer, where that address is visible -- a
# firewall ban on the real IP would match nothing. Everything is limited;
# the caches get a high dedicated rate (a nix client sustains hundreds of
# narinfo requests per second across a build, and a nixpkgs eval bursts
# thousands) and the builder agents' gRPC endpoint a generous one -- still
# ceilings, just ones no legitimate client reaches.
nixVegas.scraperGuard = {
enable = true;
vhostLimits =
let
cacheLimit = {
rate = "200r/s";
burst = 2000;
};
in
{
"cache.${baseDomain}" = cacheLimit;
"cache.nix.vegas" = cacheLimit;
"runner.hydra.${baseDomain}" = {
rate = "100r/s";
burst = 500;
};
};
realIpFrom = [ config.networking.mesh.plan.hosts.brass.nebula.address ];
banAction = "nginx-deny";
# Per-client egress ceiling on the binary cache so one public puller can't
# hog the uplink: ~32 conns x 2 MB/s ~= 64 MB/s per client, applied only
# past the first 8 MB of a response (narinfos/small NARs untouched). Nix's
# 25 parallel connections fit under the 32-conn cap. Internal ranges (the
# never-ban set: nebula + onsite LANs) are unlimited -- citadel and the
# onsite boxes keep pulling at LAN speed.
egressLimit.vhosts = [ "cache.${baseDomain}" ];
# Every onsite range, so no attendee or fleet host can be banned by a 404
# storm (the Nebula subnet is already ignored fleet-wide).
extraIgnoreIP = [
noc.subnet
build.subnet
ctf.subnet
iot.subnet
config.networking.mesh.plan.constants.wifi.subnet # 802.11s mesh underlay
]
++ erlib.arenaCidrs; # 10.7.0/24 + each 2420's attendee LAN
};
boot.kernelParams = [
"console=ttyS1,115200n8"
# Cap the ZFS ARC at 4 GiB. Default is ~half of RAM and slow to release under
# pressure, which was OOM-killing services on this box.
"zfs.zfs_arc_max=4294967296"
];
boot.kernel.sysctl = {
"net.ipv6.conf.all.accept_ra" = 0;
"net.ipv6.conf.all.autoconf" = 0;
"net.ipv6.conf.all.use_tempaddr" = 0;
"net.ipv6.conf.${wanInterface}.accept_ra" = 2;
"net.ipv6.conf.${wanInterface}.autoconf" = 1;
# (No vm.swappiness override: swap is off now, so it has nothing to act on.)
};
boot.extraModprobeConfig = ''
# Feed the L2ARC at 256 MB/s until it's full
options zfs l2arc_noprefetch=0 l2arc_write_boost=${toString (256 * 1024 * 1024)}
'';
networking.mesh = {
nebula = {
enable = true;
networkName = "arena";
tpm2Key = true;
};
wifi = {
enable = true;
countryCode = "US";
dedicatedWifiDevices = [ internalM2Wifi ];
useForFallbackInternetAccess = false;
sharedInternetDevice = "nebula.arena";
};
cache = {
# ncps used to serve here and fought nginx for :443; nginx now owns the
# cache endpoints (cache.nixos.lv -> harmonia, upstream.cache.nixos.lv ->
# the study mirror). The mesh.nix plan entry stays: the 2420s' cnl set
# reads it to find https://cache.nixos.lv:443.
server = {
enable = false;
};
client = {
enable = true;
useHydra = false;
trustHydra = true;
useRecommendedCacheSettings = true;
};
};
};
services.nebula.networks.arena = {
tun.device = lib.mkForce "nebula.arena";
settings = {
# Socket buffers: modules/nebula-socket-buffers.nix (fleet-wide; the
# measured drop evidence in its comment came from THIS host's socket).
tun = {
unsafe_routes = [
# Default route for arena traffic sent into Nebula: exit via the
# fleet gateway (brass).
(erlib.arenaDefaultRoute { planHosts = config.networking.mesh.plan.hosts; })
]
# Full-mesh inter-arena routing: reach every other router's arena LAN
# over Nebula (cert-authorized). Kernel routes live in the postStart
# below (table arena), so install = false.
++ erlib.arenaUnsafeRoutes {
self = "ghostgate";
planHosts = config.networking.mesh.plan.hosts;
};
};
# Prefer build and ctf (10Gbit)
preferred_ranges = [
build.subnet
ctf.subnet
];
# Constrain Nebula underlay address discovery. ghostgate is a multi-homed
# router; by default Nebula advertises every local interface to the
# lighthouses and will try peers on all of theirs. The overlay (10.6) and
# the arena LANs (10.7/10.8) are routed *over* Nebula, so a handshake
# aimed at such an address routes back into the tun and never completes;
# stale private ranges just waste handshake attempts. Exclude those; keep
# the WiFi mesh (10.5, a real low-latency underlay), the 10Gbit build net
# (10.4.1) and the real uplink / any public address.
lighthouse =
let
routed = [
config.networking.mesh.plan.constants.nebula.subnet # 10.6/16 overlay
"10.3.0.0/16" # deploy/mgmt LAN — collides with ghostgate's own roamed WAN
"192.168.0.0/16" # stale roamed private nets
]
++ erlib.arenaAggregates; # 10.7/16, 10.8/16 (routed over Nebula)
deny = builtins.listToAttrs (map (c: lib.nameValuePair c false) routed);
in
{
# Also drop ghostgate's mgmt net from advertisements (peers can't
# reach it); the arena LAN is already covered by the routed aggregates.
local_allow_list = deny // {
"${noc.subnet}" = false;
"0.0.0.0/0" = true;
};
# ghostgate IS on the WiFi mesh (mesh2, 10.5.0.1), so the 2420s' mesh
# (10.5) addresses are a real low-latency underlay and they handshake
# ghostgate there directly. But remote_allow_list is bidirectional and
# unscoped: a blanket 10.5 allow made ghostgate also DIAL every peer's
# advertised 10.5 address — dead for off-mesh peers — stalling
# handshakes/relay selection fleet-wide. And a blanket deny silently
# dropped the 2420s' inbound mesh handshakes (no reply, no log —
# remote_allow_list filters the handshake source address), so they
# could never establish Nebula and their arena clients lost egress.
# Scope it instead: mesh addresses are valid ONLY for the travel
# routers (remote_allow_ranges keys on the peer's VPN address).
# "::/0" = false: the current (home) uplink has NO IPv6 route, but
# peers advertise AAAA underlays -- every handshake cycle dialed them,
# got instant `sendto: network is unreachable`, and nebula's failure
# path escalated to CreateRelayRequest churn through brass for hosts
# that were ALSO directly reachable over v4 (observed Aug 23). The
# allow lists are per-family: v4-only rules leave v6 fully allowed by
# default. Flip back to true when the uplink has real v6 again.
remote_allow_list = deny // {
"${config.networking.mesh.plan.constants.wifi.subnet}" = false; # 10.5/16 dead off-mesh
"0.0.0.0/0" = true;
"::/0" = false;
};
# The VP2420 travel routers (ayem/seht/vehk, 10.6.8.x in the plan):
# their 10.5 mesh underlay is real and is how they reach us behind
# the venue NAT.
remote_allow_ranges = {
"10.6.8.0/24" = deny // {
"${config.networking.mesh.plan.constants.wifi.subnet}" = true;
"0.0.0.0/0" = true;
"::/0" = false; # no v6 route on the current uplink (see above)
};
};
};
};
};
# Pin the Nebula service user's uid so the full-tunnel nftables rules can
# match Nebula's own underlay traffic by a fixed number (see nebulaUserUid).
# This one was what it autogenerated as, we don't feel like changing it
users.users.${nebulaServiceUser}.uid = 989;
systemd.services."nebula@arena".postStart = ''
${erlib.arenaPostStartPreamble {
ip = lib.getExe' pkgs.iproute2 "ip";
sleep = lib.getExe' pkgs.coreutils "sleep";
}}
_rule_replace from ${arena.subnet} lookup arena
_rule_replace from ${build.subnet} lookup arena
_rule_replace from ${ctf.subnet} lookup arena
_rule_replace from ${noc.subnet} lookup arena
_rule_replace from ${iot.subnet} lookup arena
_rule_replace from ${config.networking.mesh.plan.constants.wifi.subnet} lookup arena
_rule_replace from ${config.networking.mesh.plan.constants.nebula.subnet} lookup arena
# Carve-out: a 2420 falling back through ghostgate needs a *clear* path to
# the Nebula lighthouses to bootstrap its own Nebula (the underlay can't be
# tunneled inside ghostgate's). Route mesh-sourced traffic to the lighthouse
# UDP ports via the main table (real WAN) at high priority, ahead of the
# `from <wifi.subnet> lookup arena` rule above. All other mesh traffic still
# egresses encrypted over Nebula, so attendee data is unaffected.
for _lhport in ${lib.concatMapStringsSep " " toString lighthousePorts}; do
_ip rule del from ${config.networking.mesh.plan.constants.wifi.subnet} ipproto udp dport "$_lhport" lookup main priority 100 2>/dev/null
_ip rule add from ${config.networking.mesh.plan.constants.wifi.subnet} ipproto udp dport "$_lhport" lookup main priority 100
done
# Per-net local-delivery routes in the arena table. _route_replace_dev waits
# for the device first: iot and mesh2 are WiFi/hostapd-backed bridges that can
# appear after nebula@arena starts, and a bare route-replace on a not-yet-up
# device silently fails (set +e) while its policy rule succeeds -- which
# black-holes that net's ghostgate-sourced replies (ICMP, kresd DNS) into the
# tun. That was the iot "no internet / can't ping gateway" bug.
_route_replace_dev arena ${arena.subnet} table arena
_route_replace_dev build ${build.subnet} table arena
_route_replace_dev ctf ${ctf.subnet} table arena
_route_replace_dev noc ${noc.subnet} table arena
_route_replace_dev iot ${iot.subnet} table arena
_route_replace_dev mesh2 ${config.networking.mesh.plan.constants.wifi.subnet} table arena
# Reach the VP2420 arena LANs over Nebula (full mesh) — in table arena for
# LAN clients, and in the main table so ghostgate itself can reach them.
${erlib.arenaTableRoutes { }}
${erlib.arenaTableRoutes { table = "main"; }}
_ip route replace default dev nebula.arena table arena
# Full-tunnel egress: ghostgate's own marked traffic (fwmark 0x1, set by the
# nebula_egress nftables chain) uses table arena, so it exits over Nebula via
# brass. Priority 300: after the lighthouse main-table carve-out (100), well
# ahead of main (32766). Marked packets never include the underlay itself
# (the chain returns on skuid arena + the underlay IPs), so no loop.
_ip rule del fwmark 0x1 lookup arena priority 300 2>/dev/null
_ip rule add fwmark 0x1 lookup arena priority 300
'';
# List packages installed in system profile. To search, run:
# $ nix search wget
environment.systemPackages = with pkgs; [
wget
curl
tmux
psmisc
man-pages
speedtest-cli
zip
unzip
iw
hdparm
sdparm
smartmontools
gptfdisk
dosfstools
usbutils
iproute2
traceroute
unbound
bind
bridge-utils
ethtool
tcpdump
conntrack-tools
sanoid
pv
mbuffer
lzop
nebula
(openssl.withPkcs11Module { pkcs11Module = yubico-piv-tool.pkcs11Module; })
ipxe
tftp-hpa
wol
great-value-hydra.cachePkgs
great-value-hydra.cacheUnstablePkgs
great-value-hydra.cachePrevPkgs
];
networking = {
inherit hostName;
nameservers = [ "127.0.0.1" ];
iproute2 = {
enable = true;
rttablesExtraConfig = ''
200 arena
'';
};
dhcpcd.extraConfig = ''
interface wan1
metric 1000
interface ${wwan1}
metric 1001
interface wwan2
metric 1002
'';
nat.enable = lib.mkForce false;
firewall = {
enable = true;
# Loose rpf. With the noc->ctf / overlay->ctf masquerades dropped (see the
# postrouting chain), citadel replies to those flows out its noc interface,
# so the reply reaches us on noc carrying a ctf-routed source (10.4.2.2).
# Strict rpf would drop that asymmetric return; loose forwards it. Spoofing
# is still constrained by the per-zone iifname/oifname accepts below.
checkReversePath = "loose";
allowedTCPPorts = [
22
53
69
80
443
5355
];
allowedUDPPorts = [
53
67
68
69
123
5355
];
};
useDHCP = false;
# Bond bifurcated: the higher 10G SFP (trunkInterface2) is now a single link
# to citadel carrying the build+ctf VLANs; the lower SFP (trunkInterface1)
# joins the arena bridge for the attendee switch's 10G uplink (see
# arenaInterfaces above). citadel's end is de-bonded to match.
vlans = {
"trunk.build" = {
inherit (build) id;
interface = trunkInterface2;
};
"trunk.ctf" = {
inherit (ctf) id;
interface = trunkInterface2;
};
};
interfaces = {
# DHCP on the WAN interface.
wan1.useDHCP = true;
${wwan1}.useDHCP = true;
wwan2.useDHCP = true;
noc = {
ipv4.addresses = [
{
inherit (noc) address;
prefixLength = noc.prefix;
}
];
};
build = {
ipv4.addresses = [
{
inherit (build) address;
prefixLength = build.prefix;
}
];
};
ctf = {
ipv4.addresses = [
{
inherit (ctf) address;
prefixLength = ctf.prefix;
}
];
};
arena = {
ipv4.addresses = [
{
inherit (arena) address;
prefixLength = arena.prefix;
}
];
};
iot = {
ipv4.addresses = [
{
inherit (iot) address;
prefixLength = iot.prefix;
}
];
};
};
bridges = {
wan1.interfaces = wanInterfaces;
noc.interfaces = nocInterfaces;
build.interfaces = [
"trunk.build"
];
ctf.interfaces = [
"trunk.ctf"
];
arena.interfaces = arenaInterfaces;
"arena.wlan".interfaces = [ ];
# Isolated IoT VLAN (Govee lamps etc.). Memberless like arena.wlan: hostapd
# solely owns the wlan-to-bridge enslavement via the radio's `bridge =
# "iot"` setting. Do NOT also list externalUSBTinyWifi here -- double-
# managing a hostapd-AP wlan (network-setup enslaving it AND hostapd
# bridging it) leaves the bridge admin-down with the port `disabled`, so
# kea can never bind iot (the arena wifi APs aren't listed here for the
# same reason).
iot.interfaces = [ ];
};
nftables = {
enable = true;
flushRuleset = true;
tables = {
filter = {
family = "inet";
content = ''
chain output {
type filter hook output priority 100; policy accept;
# IPv6 leak guard: the Nebula overlay is IPv4-only, so ghostgate
# has no tunnelled path for IPv6. Reject its own NEW global v6
# egress out the physical WAN so nothing bypasses the tunnel over
# v6 (a rejected v6 makes clients fall straight back to the
# tunnelled v4). Exempt Nebula's own v6 underlay (user `arena`),
# established replies (incl. inbound management sessions), and
# loopback/link-local/ULA/multicast so ND, DHCPv6, RA survive.
meta nfproto ipv6 meta skuid ${toString nebulaUserUid} accept
meta nfproto ipv6 ct state { established, related } accept
meta nfproto ipv6 ip6 daddr { ::1, fe80::/10, fc00::/7, ff00::/8 } accept
oifname { "wan1", "${wwan1}", "wwan2" } meta nfproto ipv6 ct state new counter reject with icmpv6 type admin-prohibited
}
# Full-tunnel egress for ghostgate's OWN traffic: default-deny
# toward the event WAN. Everything ghostgate originates is marked
# for the `arena` routing table (default dev nebula.arena -> brass),
# so it exits from brass's VPS and nothing leaks onto the DEF CON
# WAN. `type route` so the kernel re-routes after the mark is set.
# LAN/forwarded traffic is already Nebula-only (forward chain), so
# this only governs host-originated packets.
chain nebula_egress {
type route hook output priority mangle; policy accept;
# Replies to inbound connections must leave the way they arrived
# (remote SSH deploys land on wan1) — redirecting them would go
# asymmetric and drop the session. This keeps management alive.
ct direction reply return
# Local delivery, loopback, broadcast/multicast: main table.
fib daddr type { local, broadcast, multicast, anycast } return
# Loop guard: never send the Nebula underlay endpoints into the
# tunnel, whoever originates the packet.
ip daddr { ${lib.concatStringsSep ", " nebulaUnderlayV4} } return
# Nebula's own underlay (owned by the nebula-arena service user),
# including hole-punched peers, stays on the real WAN. Matched by
# numeric uid so the sandboxed build-time nft check can resolve it.
meta skuid ${toString nebulaUserUid} return
# Everything else ghostgate originates over IPv4 -> Nebula.
meta nfproto ipv4 meta mark set 0x1
}
chain input {
type filter hook input priority filter; policy drop;
# Allow trusted networks to access the router
iifname {
"lo",
"noc",
"build",
"ctf",
"arena",
"iot",
"nebula.arena",
"mesh2"
} counter accept
# Allow returning traffic from WAN, arena, and the mesh
iifname {"wan1", "${wwan1}", "wwan2", "nebula.arena", "mesh2"} ct state { established, related } counter accept
# Allow SSH in over the wired WAN uplink so ghostgate can be
# deployed remotely. The WWAN uplinks stay closed (below).
iifname "wan1" tcp dport { ${
lib.concatMapStringsSep ", " toString config.services.openssh.ports
} } counter accept
# Allow some ICMP by default
ip protocol icmp icmp type { destination-unreachable, echo-request, time-exceeded, parameter-problem } accept
ip6 nexthdr icmpv6 icmpv6 type { destination-unreachable, echo-request, time-exceeded, parameter-problem, packet-too-big } accept
# Drop everything else from WAN
iifname "wan1" drop
iifname "${wwan1}" drop
iifname "wwan2" drop
}
# MSS clamp for everything crossing the Nebula tunnel. The tun MTU
# (1300) is smaller than the 1500 LAN, so full-size TCP segments (TLS
# handshakes, real payloads) get black-holed while tiny packets (DNS,
# small GETs) pass -- looks like "no internet". A masqueraded net
# (iot, noc) can't even self-heal via PMTUD, since the "frag needed"
# ICMP can't get back to the real client. Clamp on the tunnel
# interface in BOTH directions so both endpoints size to the tunnel
# MSS (1300-40=1260). Match SYN/SYN-ACK (where the maxseg option lives).
#
# These sit on the postrouting/prerouting hooks, NOT in `forward`,
# because ghostgate's OWN connections need clamping too and `forward`
# never sees them. Its own TCP does NOT size to the tun MTU natively:
# the socket picks its MSS from the route at connect() time, which is
# the UNMARKED lookup (main table -> wan1, MTU 1500 -> MSS 1460). Only
# afterwards does nebula_egress mark the packet and reroute it into
# the 1300 tun -- and a reroute never revisits the MSS. So ghostgate
# advertised 1460, github sent 1460-byte segments, and they could not
# enter the tunnel at brass: every ghostgate-originated download (nix
# fetches, Hydra eval) connected then hung, while forwarded clients
# worked because `forward` clamped them. postrouting runs after the
# reroute, so oifname matches the tun for local and forwarded alike;
# one pair of rules now covers every net plus ghostgate itself.
chain clamp_out {
type filter hook postrouting priority mangle; policy accept;
oifname "nebula.arena" tcp flags & (syn | rst) == syn tcp option maxseg size set 1260 counter comment "clamp MSS entering nebula tunnel"
}
chain clamp_in {
type filter hook prerouting priority mangle; policy accept;
iifname "nebula.arena" tcp flags & (syn | rst) == syn tcp option maxseg size set 1260 counter comment "clamp MSS leaving nebula tunnel"
}
chain forward {
type filter hook forward priority filter; policy drop;
# Route between arena LANs over Nebula (cert-authorized, no NAT).
iifname "arena" oifname "nebula.arena" counter accept comment "arena -> nebula (inter-arena)"
iifname "nebula.arena" oifname "arena" counter accept comment "nebula -> arena (inter-arena)"
# Attendees reach the CTF backbone with real source IPs (no NAT):
# ghostgate's own arena LAN directly, and remote arenas over Nebula.
# citadel's default gateway is ghostgate, so replies route back the
# same way.
iifname "arena" oifname "ctf" counter accept comment "arena -> ctf"
iifname "nebula.arena" oifname "ctf" counter accept comment "nebula -> ctf (remote arena)"
iifname "ctf" oifname { "arena", "nebula.arena" } counter accept comment "ctf -> arena (replies)"
# Build net (citadel = the shared remote builder): the attendee
# arenas and the 2420s reach it over Nebula via ghostgate, exactly
# like ctf. Egress to `build` is masqueraded (postrouting above),
# so citadel replies to ghostgate's build IP and rpf stays happy.
iifname "arena" oifname "build" counter accept comment "arena -> build"
iifname "nebula.arena" oifname "build" counter accept comment "nebula -> build (remote arena)"
iifname "build" oifname { "arena", "nebula.arena" } counter accept comment "build -> arena (replies)"
# Post-event: the travel routers reach citadel (the builder,
# 10.4.1.2) directly over the mesh -- no Nebula in the path.
# Egress to build is masqueraded (postrouting above), so citadel
# replies to ghostgate's build IP and the return is symmetric.
iifname "mesh2" oifname "build" counter accept comment "mesh -> build (citadel builds)"
iifname "build" oifname "mesh2" ct state established,related counter accept comment "build -> mesh (replies)"
# Allow only localhost WAN access. Everything else (mesh
# included) egresses the internet via the Nebula tunnel — the
# mesh's only direct-forward exceptions are the lighthouse
# bootstrap notch and the build net (citadel) below.
iifname {
"lo"
} oifname {
"wan1",
"${wwan1}",
"wwan2",
} counter accept comment "Allow trusted LAN to WAN"
iifname { "lo", "arena", "build", "ctf", "mesh2", "noc" } oifname { "nebula.arena" } counter accept comment "Allow Arena networks to get out"
# Isolated IoT VLAN: internet egress over Nebula ONLY. Excluding the
# arena CIDRs + the Nebula overlay means iot can reach the public
# internet (via brass) but NOT other arenas, the overlay, or remote
# ctf/build — so a compromised lamp can't pivot into the fleet. Local
# arena/ctf/build/noc are already unreachable (forward policy drop).
iifname "iot" oifname "nebula.arena" ip daddr != { ${
lib.concatStringsSep ", " (
erlib.arenaCidrs ++ [ config.networking.mesh.plan.constants.nebula.subnet ]
)
} } counter accept comment "iot -> internet only (isolated from fleet)"
# Let mesh clients (2420s falling back through ghostgate) reach the
# Nebula lighthouses via the clear WAN to bootstrap their own
# Nebula. Scoped to the lighthouse UDP ports only — all other mesh
# traffic stays encrypted over Nebula (matching the carve-out in
# the nebula@arena postStart). Cover every WAN uplink, not just
# wan1: ghostgate's active uplink is whichever it roamed onto (the
# onboard WiFi ${wwan1}, or wwan2), so a wan1-only rule drops the
# forwarded handshake when ghostgate is on WiFi — the arena's whole
# internet egress (clients route out over brass) then has no way to
# bootstrap the brass tunnel.
iifname "mesh2" oifname { "wan1", "${wwan1}", "wwan2" } udp dport { ${
lib.concatMapStringsSep ", " toString lighthousePorts
} } counter accept comment "mesh -> lighthouse (clear bootstrap)"
iifname { "wan1", "${wwan1}", "wwan2" } oifname "mesh2" ct state established,related counter accept comment "lighthouse reply -> mesh"
# Let NOC get to build, ctf, and the WiFi mesh (10.5 via mesh2).
iifname { "noc" } oifname { "build", "ctf", "mesh2" } counter accept
iifname { "build", "ctf", "mesh2" } oifname { "noc" } ct state established,related counter accept
# Allow established WAN to return
iifname {
"wan1",
"${wwan1}",
"wwan2"
} oifname {
"lo"
} ct state established,related counter accept comment "Allow established back to LANs"
iifname {
"nebula.arena"
} oifname {
"lo",
"arena",
"build",
"ctf",
"mesh2",
"noc",
"iot"
} ct state established,related counter accept comment "Allow established back to LANs"
}
'';
};
nat = {
family = "ip";
content = ''
chain prerouting {
type nat hook prerouting priority filter; policy accept;
# Redirect DNS, TFTP, and NTP queries to us
iifname {"noc", "build", "ctf", "arena", "iot", "mesh2"} udp dport {53, 123} counter redirect
iifname {"noc", "build", "ctf", "arena", "iot", "mesh2"} tcp dport {53} counter redirect
}
# Setup NAT masquerading on the wan interface
chain postrouting {
type nat hook postrouting priority filter; policy accept;
# Note: no "arena" or "ctf" here — traffic delivered to the arena
# LANs and the CTF backbone keeps its real source IP, so the CTF app
# (and per-team attribution) sees real client IPs. noc/overlay -> ctf
# was masqueraded here to satisfy citadel's strict reverse-path filter
# (citadel routes noc + 10.6/16 back out its noc interface, so a
# ctf-arriving reply was asymmetric). citadel now runs loose rpf and
# replies asymmetrically instead -- which our own loose rpf forwards --
# so no ctf masquerade is needed and citadel sees the real source.
oifname {
"build",
"noc",
"wan1",
"${wwan1}",
"wwan2",
"mesh2"
} masquerade
# NOC is a management network with no presence in Nebula, so hosts
# reached over the overlay (the builders at 10.6.9.x, other arenas)
# can't route back to it. Masquerade its Nebula egress so they reply
# to us; this must come before the real-source rule below.
oifname "nebula.arena" ip saddr ${noc.subnet} masquerade
# Attendees reaching brass's web services (owncast livestream, the
# public site) over Nebula. brass has no route back to the arena
# aggregates -- its only unsafe_route is the ctf net -- so a
# real-source 10.7/10.8 packet would strand brass's reply on its
# public default gateway. Masquerade arena->brass to ghostgate's
# Nebula source so brass replies symmetrically over the tunnel (same
# pattern as the noc->nebula masq above). Scoped to brass's overlay
# address so inter-arena traffic to the OTHER routers still keeps its
# real source (the daddr != {...} rule below).
oifname "nebula.arena" ip saddr ${arena.subnet} ip daddr ${config.networking.mesh.plan.hosts.brass.nebula.address} masquerade
# Masquerade only genuine internet egress over Nebula. Traffic to
# other arenas OR to Nebula hosts (e.g. a router's own Nebula IP,
# as when pinging from the box) keeps its real source so replies
# match conntrack and stay reachable both ways.
oifname "nebula.arena" ip daddr != { ${
lib.concatStringsSep ", " (
erlib.arenaCidrs ++ [ config.networking.mesh.plan.constants.nebula.subnet ]
)
} } masquerade
}
'';
};
tftp = {
family = "ip";
content = ''
ct helper helper-tftp {
type "tftp" protocol udp
}
chain sethelper {
type filter hook forward priority 0; policy accept;
udp dport 69 ct helper set "helper-tftp"
}
'';
};
gremlinmode = {
name = "gremlinmode";
family = "ip";
content = ''
chain raw {
type filter hook postrouting priority 0; policy accept;
ip dscp cs1 ip dscp set cs0 return
ip dscp af22 ip dscp set af21 return
ip dscp af23 ip dscp set af21 return
ip dscp af32 ip dscp set af31 return
ip dscp af33 ip dscp set af31 return
ip dscp af42 ip dscp set af41 return
ip dscp af43 ip dscp set af41 return
};
'';
};
};
};
};
security.pkcs11 = {
enable = true;
pcsc = {
enable = true;
users = [ "numinit" ];
};
tpm2.enable = true;
keypairs = {
nixos-lv-arena-core = {
enable = true;
inherit (pkgs.yubico-piv-tool) pkcs11Module;
token = "YubiKey PIV #6460026";
id = 13; # Retired Key Management #8a
keyOptions = {
algorithm = "EC";
type = "secp256r1";
usage = [ "sign" ];
soPinFile = "/etc/nixpkcs/yubikeys/6460026/so.pin";
loginAsUser = false;
softFail = true;
};
certOptions = {
digest = "SHA256";
subject = "C=US/ST=California/L=Carlsbad/O=Nix Vegas/OU=Arena/CN=Core";
validityDays = 365 * 3;
extensions = [
"v3_ca"
"keyUsage=critical,nonRepudiation,keyCertSign,digitalSignature,cRLSign"
"crlDistributionPoints=URI:http://keymaster.nixos.lv/ca.crl"
];
pinFile = "/etc/nixpkcs/yubikeys/6460026/user.pin";
writeTo = "/etc/nixpkcs/yubikeys/6460026/nixos-lv-arena-core-ca.crt";
};
};
nixos-lv-arena-aux = {
enable = true;
inherit (pkgs.yubico-piv-tool) pkcs11Module;
token = "YubiKey PIV #6460026";
id = 14; # Retired Key Management #8b
keyOptions = {
algorithm = "EC";
type = "secp256r1";
usage = [ "sign" ];
soPinFile = "/etc/nixpkcs/yubikeys/6460026/so.pin";
loginAsUser = false;
softFail = true;
};
certOptions = {
digest = "SHA256";
subject = "C=US/ST=California/L=Carlsbad/O=Nix Vegas/OU=Arena/CN=Aux";
validityDays = 365 * 3;
extensions = [
"v3_ca"
"keyUsage=critical,nonRepudiation,keyCertSign,digitalSignature,cRLSign"
"crlDistributionPoints=URI:http://keymaster.nixos.lv/ca.crl"
];
pinFile = "/etc/nixpkcs/yubikeys/6460026/user.pin";
writeTo = "/etc/nixpkcs/yubikeys/6460026/nixos-lv-arena-aux-ca.crt";
};
};
nixos-lv-ca = {
enable = true;
inherit (pkgs.yubico-piv-tool) pkcs11Module;
token = "YubiKey PIV #6460026";
id = 15; # Retired Key Management #8c
keyOptions = {
algorithm = "EC";
type = "secp384r1";
usage = [ "sign" ];
soPinFile = "/etc/nixpkcs/yubikeys/6460026/so.pin";
loginAsUser = false;
softFail = true;
};
certOptions = {
digest = "SHA384";
subject = "C=US/ST=California/L=Carlsbad/O=Nix Vegas/OU=Keymaster/CN=Nix Vegas Root CA";
validityDays = 365 * 10;
extensions = [
"v3_ca"
"keyUsage=critical,nonRepudiation,keyCertSign,digitalSignature,cRLSign"
"crlDistributionPoints=URI:http://keymaster.nixos.lv/ca.crl"
];
pinFile = "/etc/nixpkcs/yubikeys/6460026/user.pin";
writeTo = "/etc/nixpkcs/yubikeys/6460026/nixos-lv-ca.crt";
};
};
};
};
networking.wireless = {
enable = true;
interfaces = [ onboardWifi ];
};