saklas.scm (19973B)
1 (define-module (epistemia systems saklas) 2 #:use-module (gnu) 3 #:use-module (gnu packages bash) 4 #:use-module (gnu packages emacs) 5 #:use-module (gnu packages golang-crypto) 6 #:use-module (gnu packages linux) 7 #:use-module (gnu packages mail) 8 #:use-module (gnu packages messaging) 9 #:use-module (gnu packages rsync) 10 #:use-module (gnu packages version-control) 11 #:use-module (gnu services certbot) 12 #:use-module (gnu services cgit) 13 #:use-module (gnu services dns) 14 #:use-module (gnu services file-sharing) 15 #:use-module (gnu services linux) 16 #:use-module (gnu services mail) 17 #:use-module (gnu services messaging) 18 #:use-module (gnu services networking) 19 #:use-module (gnu services security) 20 #:use-module (gnu services shepherd) 21 #:use-module (gnu services ssh) 22 #:use-module (gnu services vpn) 23 #:use-module (gnu services web) 24 #:use-module (gnu system accounts) 25 #:use-module (guix) 26 #:use-module (guix gexp) 27 #:use-module (guix transformations) 28 #:use-module (guix utils) 29 #:use-module (nongnu packages linux) 30 #:use-module (nongnu system linux-initrd) 31 #:use-module (epistemia bootloader) 32 #:use-module (epistemia systems base-system) 33 #:use-module (epistemia systems linux-initrd) 34 #:use-module (epistemia services age-secret) 35 #:use-module (epistemia services zfs) 36 #:use-module (epistemia packages bittorrent) 37 #:use-module (epistemia packages zfs) 38 #:use-module (ice-9 format)) 39 40 (define %nginx-badboi 41 (plain-file "nginx-badboi.conf" 42 "\ 43 set $bad_boi 0; 44 if ($http_user_agent ~* \"(AI2Bot|Ai2Bot\\-Dolma|aiHitBot|Amazonbot|Andibot|anthropic\\-ai|Applebot|Applebot\\-Extended|bedrockbot|Brightbot\\ 1\\.0|Bytespider|CCBot|ChatGPT\\-User|Claude\\-SearchBot|Claude\\-User|Claude\\-Web|ClaudeBot|cohere\\-ai|cohere\\-training\\-data\\-crawler|Cotoyogi|Crawlspace|Diffbot|DuckAssistBot|FacebookBot|Factset_spyderbot|FirecrawlAgent|FriendlyCrawler|Google\\-CloudVertexBot|Google\\-Extended|GoogleOther|GoogleOther\\-Image|GoogleOther\\-Video|GPTBot|iaskspider/2\\.0|ICC\\-Crawler|ImagesiftBot|img2dataset|ISSCyberRiskCrawler|Kangaroo\\ Bot|meta\\-externalagent|Meta\\-ExternalAgent|meta\\-externalfetcher|Meta\\-ExternalFetcher|MistralAI\\-User/1\\.0\\|MJ12|NovaAct|OAI\\-SearchBot|omgili|omgilibot|Operator|PanguBot|Panscient|panscient\\.com|Perplexity\\-User|PerplexityBot|PetalBot|PhindBot|QualifiedBot|QuillBot|quillbot\\.com|SBIntuitionsBot|Scrapy|SemrushBot\\-OCOB|SemrushBot\\-SWA|Sidetrade\\ indexer\\ bot|TikTokSpider|Timpibot|VelenPublicWebCrawler|Webzio\\-Extended|wpbot|YandexAdditional|YandexAdditionalBot|YouBot)\") { 45 set $bad_boi 1; 46 } 47 if ($request_uri = \"/robots.txt\") { 48 set $bad_boi 0; 49 } 50 if ($bad_boi = 1) { 51 return 307 https://planet.openstreetmap.org/pbf/planet-latest.osm.pbf; 52 } 53 ")) 54 55 (define %opensmtpd-config 56 (mixed-text-file "opensmtpd.conf" 57 "table domains { vineetk.net, 13f0.net, vinbiz.ca }\n" 58 "table virtuals file:/run/secrets/saklas_smtpd_virtuals\n" 59 "table passwd file:/run/secrets/saklas_smtpd_passwd\n" 60 "\n" 61 "pki mail.vineetk.net cert \"/etc/certs/vineetk.net/fullchain.pem\"\n" 62 "pki mail.vineetk.net key \"/etc/certs/vineetk.net/privkey.pem\"\n" 63 "\n" 64 "filter check_dyndns phase connect match rdns regex { '.*\\.dyn\\..*', '.*\\.dsl\\..*' } disconnect \"550 no residential connections\"\n" 65 "filter check_rdns phase connect match !rdns disconnect \"550 no connections without an rDNS\"\n" 66 "filter check_fcrdns phase connect match !fcrdns disconnect \"550 no connections without an FCrDNS\"\n" 67 "#filter sendscore proc-exec \"filter-sendscore -blockBelow 10 -junkBelow 70 -slowFactor 5000\"\n" 68 "filter dkimsign_rsa proc-exec \"" 69 (file-append opensmtpd-filter-dkimsign "/libexec/opensmtpd/filter-dkimsign") 70 " -d 13f0.net -d vinbiz.ca -d vineetk.net -s mail -k /run/secrets/saklas_smtpd_dkim\"" 71 " user smtpd group nogroup\n" 72 "\n" 73 "listen on socket\n" 74 "listen on eth0 port 25 tls pki mail.vineetk.net filter { check_dyndns, check_rdns, check_fcrdns }\n" 75 "listen on eth0 port 465 smtps pki mail.vineetk.net auth <passwd> filter dkimsign_rsa\n" 76 "\n" 77 "action \"inbound\" lmtp \"/var/run/dovecot/lmtp\" rcpt-to virtual <virtuals>\n" 78 "action \"outbound\" relay helo mail.vineetk.net\n" 79 "\n" 80 "match from local for local action \"inbound\"\n" 81 "match from any for domain <domains> action \"inbound\"\n" 82 "match from local for any action \"outbound\"\n" 83 "match from any auth for any action \"outbound\"\n")) 84 85 ;; adapted from my pf.conf 86 (define %nftables-ruleset 87 (plain-file "nftables.conf" "\ 88 define ext_if = \"eth0\" 89 define vpn_if = \"wg0\" 90 91 define tcp_ports = { 92 http, https, 93 smtp, smtps, imaps, 94 xmpp-client, xmpp-server, 5281, 5201, 95 6060 96 } 97 98 define udp_ports = { 99 3478, 5201, 51413, 51820 100 } 101 102 table inet filter { 103 set ssh_whitelist_ipv4 { 104 type ipv4_addr 105 flags interval 106 elements = { 107 47.201.69.0/24, 108 185.157.162.25/24 109 } 110 } 111 112 set ssh_whitelist_ipv6 { 113 type ipv6_addr 114 flags interval 115 elements = { 116 2001:470:d851:b0ba::/64, 117 2a07:a880:3101:102a:2b39:4fb9:4975:4c1d 118 } 119 } 120 121 chain input { 122 type filter hook input priority 0; policy drop; 123 124 # set skip on lo 125 iifname lo accept 126 # drop connections to lo not coming from lo 127 iif != lo ip daddr 127.0.0.1/8 drop 128 iif != lo ip6 daddr ::1/128 drop 129 130 # early drop of invalid connections 131 ct state invalid drop 132 # allow established/related connections 133 ct state { established, related } accept 134 135 # unblock pings 136 ip protocol icmp icmp type echo-request accept 137 ip6 nexthdr icmpv6 icmpv6 type { packet-too-big, echo-request } accept 138 ip6 nexthdr icmpv6 icmpv6 \ 139 type { echo-request, nd-router-solicit, nd-router-advert, 140 nd-neighbor-solicit, nd-neighbor-advert, nd-redirect } accept 141 142 iifname $ext_if tcp dport $tcp_ports ct state new accept 143 iifname $ext_if udp dport $udp_ports ct state new accept 144 145 iifname $vpn_if tcp dport { 9090, 9100 } ct state new accept 146 147 # allow public ssh only to my normal home address and mullvad ips 148 iifname $ext_if tcp dport ssh ip saddr @ssh_whitelist_ipv4 ct state new log prefix \"SSH_V4: \" accept 149 iifname $ext_if tcp dport ssh ip6 saddr @ssh_whitelist_ipv6 ct state new log prefix \"SSH_V6: \" accept 150 151 iifname wg1 accept 152 153 # reject everything else 154 reject with icmpx type port-unreachable 155 } 156 157 chain forward { 158 type filter hook forward priority 0; policy drop; 159 } 160 161 chain output { 162 type filter hook output priority 0; policy accept; 163 } 164 } 165 ")) 166 167 168 (operating-system 169 (inherit base-system) 170 (host-name "saklas.epistemia") 171 172 (users (cons* (user-account 173 (name "vin") 174 (comment "Vineet") 175 (shell (file-append bash "/bin/bash")) 176 (group "users") 177 (supplementary-groups '("wheel" "git" "torrents"))) 178 (user-account 179 (name "torrents") 180 (comment "torrenting account") 181 (group "torrents") 182 (shell "/dev/null") 183 (home-directory "/var/empty") 184 (system? #t)) 185 (user-account 186 (name "vmail") 187 (comment "virtual mail account") 188 (group "vmail") 189 (shell "/dev/null") 190 (home-directory "/var/vmail") 191 (system? #t)) 192 %base-user-accounts)) 193 (groups (cons* (user-group 194 (name "git")) 195 (user-group 196 (name "torrents")) 197 (user-group 198 (name "vmail")) 199 %base-groups)) 200 201 (kernel linux-libre-lts) 202 (kernel-arguments (list "net.ifnames=0" "nomodeset")) 203 204 (bootloader (bootloader-configuration 205 (bootloader grub-zfs-bios) 206 (targets '("/dev/sda")))) 207 208 (file-systems (append 209 (list (file-system 210 (device "zroot/root") 211 (mount-point "/") 212 (type "zfs") 213 (check? #f) 214 (needed-for-boot? #t)) 215 (file-system 216 (device "zroot/gnu") 217 (mount-point "/gnu") 218 (type "zfs") 219 (check? #f) 220 (needed-for-boot? #t)) 221 (file-system 222 (device "zroot/var") 223 (mount-point "/var") 224 (type "zfs") 225 (check? #f) 226 (needed-for-boot? #t)) 227 (file-system 228 (device "zroot/home") 229 (mount-point "/home") 230 (type "zfs") 231 (check? #f) 232 (needed-for-boot? #t))) 233 %base-file-systems)) 234 235 (packages (append (list emacs-no-x 236 git 237 rsync 238 zfs-linux) 239 %base-packages)) 240 241 (services (modify-services (append (list (service age-secret-service-type 242 (age-secret-configuration 243 (secrets (list 244 (age-secret 245 (name "wg1_saklas") 246 (file (local-file "../secrets/wg1_saklas.age"))) 247 (age-secret 248 (name "saklas_smtpd_dkim") 249 (file (local-file "../secrets/saklas_smtpd_dkim.age")) 250 (owner "smtpd") 251 (group "nogroup") 252 (mode #o400)) 253 (age-secret 254 (name "saklas_smtpd_virtuals") 255 (file (local-file "../secrets/saklas_smtpd_virtuals.age")) 256 (owner "smtpd") 257 (group "nogroup") 258 (mode #o400)) 259 (age-secret 260 (name "saklas_smtpd_passwd") 261 (file (local-file "../secrets/saklas_smtpd_passwd.age")) 262 (owner "smtpd") 263 (group "dovecot") 264 (mode #o440)))))) 265 (simple-service 'zfs-loader 266 kernel-module-loader-service-type 267 '("zfs")) 268 (simple-service 'zfs-shepherd-services 269 shepherd-root-service-type 270 zfs-shepherd-services) 271 (simple-service 'zfs-shepherd-services-user-processes 272 user-processes-service-type 273 '(zfs-automount)) 274 (service nftables-service-type 275 (nftables-configuration 276 (ruleset %nftables-ruleset))) 277 (service static-networking-service-type 278 ;; TODO hurricane electric for ipv6 /48. ovh vps only gets /128. 279 (list (static-networking 280 (addresses 281 (list (network-address 282 (device "eth0") 283 (value "141.95.52.111/24")))) 284 (routes 285 (list (network-route 286 (destination "default") 287 (gateway "141.95.52.1"))))))) 288 (simple-service 'resolv-configuration 289 etc-service-type 290 `(("resolv.conf" 291 ,(plain-file "resolv.conf" 292 (string-append 293 "nameserver 127.0.0.1\n" 294 "search epistemia\n"))))) 295 (service openssh-service-type 296 (openssh-configuration 297 (permit-root-login 'prohibit-password) 298 (password-authentication? #f) 299 (authorized-keys 300 `(("vin" ,(local-file "/data/ssh/id_ed25519.pub")) 301 ("git" ,(local-file "/data/ssh/id_ed25519.pub")) 302 ("root" ,(local-file "/data/ssh/id_ed25519.pub")))))) 303 (service unbound-service-type 304 (unbound-configuration 305 (server 306 (unbound-server 307 (interface '("127.0.0.1" 308 "::1" 309 "10.0.13.1")) 310 (hide-version #t) 311 (hide-identity #t))) 312 (extra-content "\ 313 server: 314 access-control: 127.0.0.0/8 allow 315 access-control: 10.0.13.0/24 allow 316 access-control: ::1 allow 317 318 ip-freebind: yes 319 aggressive-nsec: no 320 module-config: \"respip validator iterator\" 321 322 local-data: \"saklas.epistemia. 86400 IN A 10.0.13.1\" 323 local-data: \"saklas.epistemia. 86400 IN AAAA fd00:b0ba:cafe:babe::1\" 324 local-data: \"demiurge.epistemia. 86400 IN A 10.0.13.2\" 325 local-data: \"demiurge.epistemia. 86400 IN AAAA fd00:b0ba:cafe:babe::2\" 326 local-data: \"hastur.epistemia. 86400 IN A 10.0.13.3\" 327 local-data: \"hastur.epistemia. 86400 IN AAAA fd00:b0ba:cafe:babe::3\" 328 local-data: \"iphonebob.epistemia. 86400 IN A 10.0.13.4\" 329 local-data: \"iphonebob.epistemia. 86400 IN AAAA fd00:b0ba:cafe:babe::4\" 330 local-zone: \"saklas.epistemia.\" redirect 331 local-zone: \"demiurge.epistemia.\" redirect 332 local-zone: \"hastur.epistemia.\" redirect 333 local-zone: \"iphonebob.epistemia.\" redirect 334 335 rpz: 336 name: \"hagezi.ultimate\" 337 zonefile: \"hagezi.ultimate\" 338 url: https://raw.githubusercontent.com/hagezi/dns-blocklists/main/rpz/ultimate.txt"))) 339 (service wireguard-service-type 340 (wireguard-configuration 341 (interface "wg1") 342 (addresses '("10.0.13.1/24" "fd00:b0ba:cafe:babe::1/64 ")) 343 (port 51820) 344 (bootstrap-private-key? #f) 345 (private-key "/run/secrets/wg1_saklas") 346 (peers 347 (list 348 (wireguard-peer 349 (name "demiurge.epistemia") 350 (public-key "FMLvbSxY6vA8CRV4S1vl4+pMeCr/kR9n0G5w9buNqh4=") 351 (allowed-ips '("10.0.13.2/32" "fd00:b0ba:cafe:babe::2/128")) 352 (keep-alive 25)) 353 (wireguard-peer 354 (name "hastur.epistemia") 355 (public-key "1ketYziRhoUmpbrj/60O5DYbcPacvmEoFQqa/NntSnc=") 356 (allowed-ips '("10.0.13.3/32" "fd00:b0ba:cafe:babe::3/128")) 357 (keep-alive 25)) 358 (wireguard-peer 359 (name "iphonebob.epistemia") 360 (public-key "Xn0EmeRZdpMejBgzr98mYtb/2f5O58GAzQLNZV/SS30=") 361 (allowed-ips '("10.0.13.4/32" "fd00:b0ba:cafe:babe::4/128")) 362 (keep-alive 25)) 363 (wireguard-peer 364 (name "lab.epistemia") 365 (public-key "iMDEwvXjPAlQH8ZCmP63FM5ICYIFIX5XIyGxjnXoNVE=") 366 (allowed-ips '("10.0.13.5/32" "fd00:b0ba:cafe:babe::5/128")) 367 (keep-alive 25)))))) 368 (service certbot-service-type 369 (certbot-configuration 370 (email "postmaster@vineetk.net") 371 (certificates 372 (list 373 (certificate-configuration 374 (deploy-hook (program-file 375 "import-prosody-certs" 376 #~(begin 377 (let ((prosodyctl (string-append #$prosody "/bin/prosodyctl"))) 378 (system* prosodyctl "--root" "cert" "import" "/etc/certs"))))) 379 (domains '("vineetk.net" 380 "git.vineetk.net" 381 "mail.vineetk.net" 382 "u.vineetk.net" 383 "xmpp.vineetk.net"))) 384 (certificate-configuration 385 (domains '("13f0.net" 386 "m.13f0.net" 387 ;"snac.13f0.net" 388 ))) 389 (certificate-configuration 390 (domains '("vinbiz.ca"))))))) 391 (service nginx-service-type 392 (nginx-configuration 393 (extra-content "limit_req_zone $binary_remote_addr zone=git_rate:10m rate=30r/m;") 394 (server-blocks 395 (list (nginx-server-configuration 396 (server-name '("vineetk.net")) 397 (listen '("443 ssl")) 398 (ssl-certificate "/etc/certs/vineetk.net/fullchain.pem") 399 (ssl-certificate-key "/etc/certs/vineetk.net/privkey.pem") 400 (root "/var/www/site_vineetk") 401 (raw-content (list "include " %nginx-badboi ";"))) 402 (nginx-server-configuration 403 (server-name '("13f0.net")) 404 (listen '("443 ssl")) 405 (ssl-certificate "/etc/certs/13f0.net/fullchain.pem") 406 (ssl-certificate-key "/etc/certs/13f0.net/privkey.pem") 407 (root "/var/www/site_13f0") 408 (raw-content (list "include " %nginx-badboi ";"))) 409 (nginx-server-configuration 410 (server-name '("vinbiz.ca")) 411 (listen '("443 ssl")) 412 (ssl-certificate "/etc/certs/vinbiz.ca/fullchain.pem") 413 (ssl-certificate-key "/etc/certs/vinbiz.ca/privkey.pem") 414 (root "/var/www/site_vinbiz") 415 (raw-content (list "include " %nginx-badboi ";"))))))) 416 ;; git folder needs to be readable by nginx/cgit, gets reset to 700 on reconfigure otherwise 417 (simple-service 'git-home-permissions 418 activation-service-type 419 #~(when (file-exists? "/var/git") 420 (chmod "/var/git" #o775))) 421 (simple-service 'git-mirror-update 422 shepherd-root-service-type 423 (list (shepherd-timer 424 '(git-mirror-update) 425 "0 */8 * * *" ; vixie cron doesn't support random/tilde. I'm sorry codeberg and other mirrors :( 426 #~("/run/privileged/bin/su" "git" "-c" 427 "for i in $(dirname $(grep -l Mirrors /var/git/*.git/cgitrc)); do (cd \"$i\"; git fetch upstream --prune); done") 428 #:requirement '(networking) 429 #:documentation "Update git mirrors every 8 hours.") 430 (shepherd-timer 431 '(stagit-update) 432 "0 */8 * * *" 433 #~("/run/privileged/bin/su" "git" "-c" 434 "stagit-index /var/git/*.git >/var/www/stagit/index.html; for i in /var/git/*.git; do (r=$(basename \"$i\" .git); echo \"$r\"; mkdir -p /var/www/stagit/\"$r\"; cd /var/www/stagit/\"$r\"; stagit \"$i\"; cp ../style.css ../logo.png .); done") 435 #:requirement '(networking) 436 #:documentation "Update stagit every 8 hours without waiting for a new commit."))) 437 (service prosody-service-type 438 (prosody-configuration 439 (admins '("vin@vineetk.net")) 440 (allow-registration? #f) 441 (c2s-require-encryption? #t) 442 (s2s-require-encryption? #t) 443 (s2s-secure-auth? #t) 444 (authentication "internal_hashed") 445 (plugin-paths (list prosody-cloud-notify)) 446 (modules-enabled 447 ;; list from https://github.com/monal-im/Monal/wiki/Considerations-for-XMPP-server-admins#prosody 448 (cons* "sasl_ssdp" 449 ;; TODO update prosody to 13 450 ;; "sasl2" 451 ;; "sasl2_bind2" 452 ;; "sasl2_sm" 453 ;; "sasl2_fast" 454 "muc_notifications" 455 "smacks" 456 "mam" 457 "csi_simple" 458 "cloud_notify" 459 "bookmarks" 460 %default-modules-enabled)) 461 ;; I don't want my syslog flooded. can't control changes either in service yet 462 (log "/var/lib/prosody/prosody.log") 463 (virtualhosts 464 (list 465 (virtualhost-configuration 466 (domain "vineetk.net")))))) 467 (service opensmtpd-service-type 468 (opensmtpd-configuration 469 (config-file %opensmtpd-config))) 470 (service dovecot-service-type 471 (dovecot-configuration 472 (listen '("*" "::")) 473 (mail-location "maildir:/var/vmail/%d/%n") 474 (mail-uid "vmail") 475 (mail-gid "vmail") 476 (ssl? "required") 477 (ssl-cert "</etc/certs/vineetk.net/fullchain.pem") 478 (ssl-key "</etc/certs/vineetk.net/privkey.pem") 479 (namespaces 480 (list (namespace-configuration 481 (name "inbox") 482 (inbox? #t) 483 (location "") 484 (prefix "") 485 (mailboxes 486 (list (mailbox-configuration 487 (name "Drafts") 488 (special-use '("\\Drafts"))) 489 (mailbox-configuration 490 (name "Junk") 491 (special-use '("\\Junk"))) 492 (mailbox-configuration 493 (name "Sent") 494 (special-use '("\\Sent"))) 495 (mailbox-configuration 496 (name "Trash") 497 (special-use '("\\Trash")))))))) 498 (passdbs 499 (list (passdb-configuration 500 (driver "passwd-file") 501 (args '("scheme=CRYPT" "username_format=%u" "/run/secrets/saklas_smtpd_passwd"))))) 502 (userdbs 503 (list (userdb-configuration 504 (driver "static") 505 (args '("uid=vmail" "gid=vmail" "home=/var/vmail/%d/%n"))))) 506 (protocols 507 (list (protocol-configuration (name "imap")) 508 (protocol-configuration (name "lmtp")))) 509 (services 510 (list (service-configuration 511 (kind "lmtp") 512 (listeners 513 (list (unix-listener-configuration 514 (path "lmtp") 515 (group "vmail") 516 (user "vmail")))))))))) 517 %base-services) 518 (guix-service-type config => 519 (guix-configuration 520 (inherit config) 521 (authorized-keys 522 (append (list (local-file "../../demiurge.pub")) 523 %default-authorized-guix-keys)))))))