gnucode.me-current-config.scm 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. ;; this is the current configuration for my gnucode.me,
  2. ;; propernaming.org, and gnu-hurd.com
  3. (add-to-load-path (dirname (current-filename)))
  4. (add-to-load-path "/home/joshua/prog/gnu/guix/guixrus")
  5. (use-modules (gnu)
  6. (guix modules)
  7. ;;(secret nginx)
  8. (public-keys)
  9. ;;(gnucode-form)
  10. (nftables)
  11. (endlessh-service)
  12. ;;(opensmtpd-records)
  13. ;;(gnu services mail)
  14. (guixrus services opensmtpd)
  15. (gnu packages mail)
  16. ((gnu services mail)
  17. #:hide (opensmtpd-configuration
  18. opensmtpd-configuration?
  19. opensmtpd-service-type
  20. %default-opensmtpd-config-file))
  21. )
  22. (use-service-modules admin ; unattended-upgrades
  23. avahi
  24. certbot
  25. ;; mail
  26. mcron
  27. messaging
  28. networking
  29. security
  30. sysctl
  31. ssh
  32. vpn ;;wireguard
  33. web)
  34. (use-package-modules admin
  35. certs
  36. package-management
  37. ssh
  38. tls)
  39. (define %nginx-deploy-hook
  40. (program-file
  41. "nginx-deploy-hook"
  42. #~(let ((pid (call-with-input-file "/var/run/nginx/pid" read)))
  43. (kill pid SIGHUP))))
  44. (define %my-base-services
  45. (modify-services %base-services
  46. (guix-service-type config =>
  47. (guix-configuration (inherit config)
  48. (discover? #t)
  49. (substitute-urls
  50. (append (list
  51. "https://guix.tobias.gr")
  52. %default-substitute-urls))
  53. (authorized-keys
  54. (append (list
  55. ;; setting up guix deploy from dobby.
  56. (local-file "./dobby-guix-signing-key.pub")
  57. (plain-file
  58. "guix.tobias.gr"
  59. "(public-key
  60. (ecc
  61. (curve Ed25519)
  62. (q #E21911E159DB6D031A763509A255B054360A4A96F5668CBBAC48052E67D274D3#)
  63. )
  64. )
  65. ")
  66. )))
  67. (extra-options '("--max-jobs=1"))))
  68. ;; security stuff.
  69. (sysctl-service-type config =>
  70. (sysctl-configuration
  71. (settings
  72. (append
  73. '(
  74. ;;disable ipv6
  75. ("net.ipv6.conf.all.disable_ipv6" . "1")
  76. ("net.ipv6.conf.all.disable_policy" . "1")
  77. ("net.ipv6.conf.default.disable_ipv6" . "1")
  78. ("net.ipv6.conf.default.disable_policy" . "1")
  79. ("net.ipv6.conf.enp0s10.disable_ipv6" . "1")
  80. ("net.ipv6.conf.enp0s10.disable_policy" . "1")
  81. ("net.ipv6.conf.lo.disable_ipv6" . "1")
  82. ("net.ipv6.conf.lo.disable_policy" . "1")
  83. ;; disable ebpf in kernel virtual machine for unprivledged users
  84. ("sysctl kernel.unprivileged_bpf_disabled" . "1")
  85. ("spec_store_bypass_disable" . "on")
  86. ("spectre_v2" . "on")
  87. ("lld_flush" . "on")
  88. ;; need to enable apparmor for this...
  89. ;;("lockdown" . "confidentiality")
  90. ("init_on_alloc" . "1")
  91. ("init_on_free" . "1")
  92. ("page_alloc.shuffle" . "1")
  93. ;;("slab_nomerge")
  94. ("vsyscall" . "1")
  95. ;; ("slub_debug" . "F")
  96. ("randomize_kstack_offset" . "1")
  97. ;; disable re-leading a running kernel
  98. ("kernel.kexec_load_disabled" . "1")
  99. ;; restrict kernel pointers
  100. ("kernel.kptr_restrict" . "2")
  101. ;; unprivledegd users cannot get perf events
  102. ("kernel.perf_event_paranoid" . "3")
  103. ;; only privledged users can use bpf
  104. ("net.core.bpf_jit_harden" . "2")
  105. ("kernel.unprivleged_bpf" . "1")
  106. ;; prevest some proofing attacks
  107. ("net.ipv4.conf.all.rp_filter" . "1")
  108. ("net.ipv4.conf.default.rp_filter" . "1")
  109. ;; disable icmp redirects and
  110. ;; RFC1620 shared media redirects
  111. ("net.ipv4.conf.all.accept_redirects" . "0")
  112. ("net.ipv4.conf.all.secure_redirects" . "0")
  113. ("net.ipv4.conf.all.send_redirects" . "0")
  114. ("net.ipv4.conf.all.shared_media" . "0")
  115. ("net.ipv4.conf.default.accept_redirects" . "0")
  116. ("net.ipv4.conf.default.secure_redirects" . "0")
  117. ("net.ipv4.conf.default.send_redirects" . "0")
  118. ("net.ipv4.conf.default.shared_media" . "0")
  119. ("net.ipv6.conf.all.accept_redirects" . "0")
  120. ("net.ipv6.conf.default.accept_redirects" . "0")
  121. ;; disallow source-routed packets
  122. ("net.ipv4.conf.all.accept_source_route" . "0")
  123. ("net.ipv4.conf.default.accept_source_route" . "0")
  124. ("net.ipv6.conf.all.accept_source_route" . "0")
  125. ("net.ipv6.conf.default.accept_source_route" . "0")
  126. ;; disable pings sent to a broadcast address
  127. ("net.ipv4.icmp_echo_ignore_broadcasts" . "1")
  128. ;; disable bogus icmp error responses
  129. ("net.ipv4.icmp_ignore_bogus_error_responses" . "1")
  130. ;; protect against time-wait assassination hazards in tcp
  131. ("net.ipv4.tcp_rfc1337" . "1")
  132. ("net.ipv4.tcp_sack" . "0")
  133. ("net.ipv4.tcp_dsack" . "0")
  134. ("net.ipv4.tcp_timestamps" . "0")
  135. ("vm.mmap_rnd_bits" . "32")
  136. ("vm.mmap_rnd_compat_bits" . "16")
  137. ("net.ipv4.icmp_echo_ignore_all" . "1")
  138. )
  139. %default-sysctl-settings))))))
  140. ;;(define %system)
  141. (operating-system
  142. (host-name "copertino")
  143. (timezone "America/Chicago")
  144. (locale "en_US.UTF-8")
  145. ;; This goofy code will generate the grub.cfg
  146. ;; without installing the grub bootloader on disk.
  147. (bootloader (bootloader-configuration
  148. (bootloader
  149. (bootloader
  150. (inherit grub-bootloader)
  151. (installer #~(const #t))))))
  152. (file-systems (cons (file-system
  153. (device "/dev/sda")
  154. (mount-point "/")
  155. (type "ext4"))
  156. %base-file-systems))
  157. (swap-devices (list
  158. (swap-space (target "/dev/sdb"))))
  159. (initrd-modules (cons "virtio_scsi" ; Needed to find the disk
  160. %base-initrd-modules))
  161. (users (cons* (user-account
  162. (name "joshua")
  163. (group "users")
  164. ;; Adding the account to the "wheel" group
  165. ;; makes it a sudoer.
  166. (supplementary-groups '("wheel"))
  167. (home-directory "/home/joshua"))
  168. ;; (user-account
  169. ;; (name "vmail")
  170. ;; (group "vmail")
  171. ;; (home-directory "vmail")
  172. ;; (system? #t)
  173. ;; (comment "User that dovecot users to deliver emails
  174. ;; to /home/vmail/gnucode.me/joshua"))
  175. %base-user-accounts))
  176. ;; (groups (cons* (user-group
  177. ;; (name "vmail")
  178. ;; (system? #t))
  179. ;; %base-groups))
  180. ;; I can read 'man 5 suoders' for tips about the syntax of suoders file.
  181. ;; the very end of the file has some examples.
  182. (sudoers-file
  183. (plain-file "sudoers"
  184. (string-append (plain-file-content %sudoers-specification)
  185. (format #f "~a ALL = NOPASSWD: ALL~%"
  186. "joshua"))))
  187. (packages (cons* openssh-sans-x
  188. %base-packages))
  189. (services (cons*
  190. (service dhcp-client-service-type)
  191. ;; guix daemon requires avahi
  192. (service avahi-service-type)
  193. (service certbot-service-type
  194. (certbot-configuration
  195. (email "jbranso@dismail.de")
  196. (webroot "/srv/www")
  197. (certificates
  198. (list
  199. (certificate-configuration
  200. (name "gnucode.me")
  201. (domains '("gnucode.me" "www.gnucode.me"
  202. "imap.gnucode.me"
  203. "smtp.gnucode.me"))
  204. (deploy-hook %nginx-deploy-hook))
  205. (certificate-configuration
  206. (name "gnu-hurd.com")
  207. (domains '("gnu-hurd.com" "www.gnu-hurd.com"))
  208. (deploy-hook %nginx-deploy-hook))
  209. (certificate-configuration
  210. (name "propernaming.org")
  211. (domains '("propernaming.org" "www.propernaming.org"))
  212. (deploy-hook %nginx-deploy-hook))
  213. ))))
  214. (service dovecot-service-type
  215. (dovecot-configuration
  216. (mail-location "maildir:/home/%n/Maildir")
  217. (protocols
  218. (list
  219. (protocol-configuration
  220. (name "imap")
  221. ;; 3 was too few. Sometimes I will have several email clients
  222. ;; open. So 5 is a better number.
  223. (mail-max-userip-connections 5)
  224. )
  225. ;;(protocol-configuration name "lmtp")
  226. ))
  227. ;; I am hoping to set up LMTP, that way I can set up Sieve filtering.
  228. ;; https://doc.dovecot.org/configuration_manual/sieve/configuration/
  229. ;; https://doc.dovecot.org/configuration_manual/protocols/lmtp_server/#lmtp-server
  230. ;; (services
  231. ;; (list
  232. ;; (service-configuration
  233. ;; (kind "imap"))))
  234. ;; someone tries to login via joshua@gnucode.me
  235. ;; this strips away that login username to "joshua"
  236. ;; when I set up virtual users, I'll need to delete this!
  237. ;; https://wiki.dovecot.org/DomainLost
  238. ;; "%n-AT-%d" -> joshua@gnucode.me -> joshua-AT-gnucode.me
  239. (auth-username-format "%n")
  240. (ssl-cert "</etc/letsencrypt/live/gnucode.me/fullchain.pem")
  241. (ssl-key "</etc/letsencrypt/live/gnucode.me/privkey.pem")
  242. ))
  243. ;;(service gnucode -form-service-type)
  244. (service fail2ban-service-type
  245. (fail2ban-configuration
  246. (extra-jails
  247. (list
  248. (fail2ban-jail-configuration
  249. (name "sshd")
  250. (enabled? #t))))))
  251. (service nginx-service-type
  252. (let ([default-listen (list "80"
  253. "443 ssl http2"
  254. "[::]:80"
  255. "[::]:443 ssl http2"
  256. )]
  257. ;; tell browsers my site supports HTTPS, and tell them that it will
  258. ;; at least work for 12 hours. Gradually, I will increase this number.
  259. [default-raw-content (list "add_header Strict-Transport-Security max-age=18000;")]
  260. [srv-root-dir "/srv/www/html/"]
  261. [letsencrypt-dir "/etc/letsencrypt/live/"]
  262. [letsencrypt-acme-challenge (nginx-location-configuration ;; for certbot
  263. (uri "/.well-known")
  264. (body (list "root /srv/www;")))])
  265. (nginx-configuration
  266. (server-blocks
  267. (list
  268. (nginx-server-configuration
  269. (server-name '("gnucode.me"))
  270. (listen default-listen)
  271. (root "/srv/www/html/gnucode.me/site/")
  272. (ssl-certificate (string-append letsencrypt-dir "gnucode.me/fullchain.pem"))
  273. (ssl-certificate-key (string-append letsencrypt-dir "gnucode.me/privkey.pem"))
  274. (raw-content default-raw-content)
  275. (locations
  276. (list
  277. letsencrypt-acme-challenge ;; for certbot
  278. (nginx-location-configuration
  279. (uri "/form/")
  280. (body '("proxy_pass http://127.0.0.1:8081;")))
  281. (nginx-location-configuration
  282. (uri "/craggy-hurd/")
  283. (body
  284. (list "root /srv/www/html/gnucode.me/site/craggy-hurd/rendered/;")))
  285. ;; (nginx-location-configuration
  286. ;; (uri "/agenda/")
  287. ;; (body
  288. ;; (list
  289. ;; (string-append "root " srv-root-dir "gnucode.me/agenda/;\n")
  290. ;; ;(string-append "auth_basic \"Yearly Agenda\";\n")
  291. ;; ;(string-append "auth_basic_user_file " srv-root-dir "gnucode.me/agenda/htpasswd;")
  292. ;; )))
  293. )))
  294. (nginx-server-configuration
  295. (server-name '("gnu-hurd.com"))
  296. (listen default-listen)
  297. (root "/srv/www/html/gnu-hurd.com/")
  298. (ssl-certificate (string-append letsencrypt-dir "gnu-hurd.com/fullchain.pem"))
  299. (ssl-certificate-key (string-append letsencrypt-dir "gnu-hurd.com/privkey.pem"))
  300. (raw-content default-raw-content)
  301. (locations
  302. (list
  303. letsencrypt-acme-challenge ;; for certbot
  304. )))
  305. (nginx-server-configuration
  306. (server-name '("propernaming.org"))
  307. (listen default-listen)
  308. (root "/srv/www/html/propernaming.org/site/")
  309. (ssl-certificate (string-append letsencrypt-dir "propernaming.org/fullchain.pem"))
  310. (ssl-certificate-key (string-append letsencrypt-dir "propernaming.org/privkey.pem"))
  311. (raw-content default-raw-content)
  312. (locations
  313. (list
  314. letsencrypt-acme-challenge ;; for certbot
  315. )))
  316. )))))
  317. (service openssh-service-type
  318. (openssh-configuration
  319. (openssh openssh-sans-x)
  320. (password-authentication? #f)
  321. (port-number 22)
  322. (authorized-keys
  323. `(
  324. ("joshua" ,(plain-file "id_rsa.pub" %joshua-ssh-key))
  325. ("root" ,(plain-file "id_rsa.pub" %joshua-ssh-key))
  326. ))))
  327. ;; I've created the prosody admin user, and I imported the cert...
  328. ;; but pidgin tells me that I the XMPP server at gnucode.me does not support encryption.
  329. (service prosody-service-type
  330. (prosody-configuration
  331. ;;(certificates "/etc/")
  332. (admins '("jbranso@gnucode.me"))
  333. (virtualhosts
  334. (list
  335. (virtualhost-configuration
  336. (domain "gnucode.me"))))))
  337. ;; I can test send an email from my ssh machine via:
  338. ;; cat test-email.txt | msmtp -- jbranso@dismail.de
  339. ;; (service opensmtpd-service-type
  340. ;; (opensmtpd-configuration
  341. ;; (config-file %smtpd.conf)))
  342. ;; TODO my nftables for a server ARE NOT working.
  343. ;; (service nftables-service-type
  344. ;; (nftables-configuration
  345. ;; (ruleset
  346. ;; (plain-file "nftables.conf" %gnucode-nftables-ruleset))))
  347. (service opensmtpd-service-type
  348. (let ([action-receive
  349. (opensmtpd-local-delivery
  350. (name "receive")
  351. (method (opensmtpd-lmtp
  352. (destination "/var/run/dovecot/lmtp"))))
  353. ;; (opensmtpd-local-delivery
  354. ;; (name "receive")
  355. ;; (method (opensmtpd-maildir
  356. ;; (pathname "/home/%{rcpt.user}/Maildir")
  357. ;; (junk #t)))
  358. ;; (virtual (opensmtpd-table
  359. ;; (name "vusers")
  360. ;; (data '(("joshua@gnucode.me" . "joshua")
  361. ;; )))))
  362. ]
  363. [pki-gnucode (opensmtpd-pki
  364. (domain "smtp.gnucode.me")
  365. (cert "/etc/letsencrypt/live/gnucode.me/fullchain.pem")
  366. (key "/etc/letsencrypt/live/gnucode.me/privkey.pem"))]
  367. [filter-dkimsign (opensmtpd-filter
  368. (name "dkimsign")
  369. (exec #t)
  370. (proc (list (file-append opensmtpd-filter-dkimsign "/libexec/opensmtpd/filter-dkimsign")
  371. " -d gnucode.me -s 2023-02-28 -c relaxed/relaxed -k "
  372. "/etc/opensmtpd/dkimsign/02-28-2023-rsa1024-gnucode.me-private.key "
  373. "user nobody group nogroup")))]
  374. ;; [table-creds (opensmtpd-table
  375. ;; (name "creds")
  376. ;; (data
  377. ;; (list
  378. ;; (cons "joshua"
  379. ;; "$6$Ec4m8FgKjT2F/03Y$k66ABdse9TzCX6qaALB3WBL9GC1rmAWJmaoSjFMpbhzat7DOpFqpnOwpbZ34wwsQYIK8RQlqwM1I/v6vsRq86."))))]
  380. )
  381. (opensmtpd-configuration
  382. (interfaces
  383. (list
  384. ;; this forum help suggests that I listen on 0.0.0.0 and NOT eth0
  385. ;; https://serverfault.com/questions/726795/opensmtpd-wont-work-at-reboot
  386. ;; this listens for email from the outside world
  387. (opensmtpd-interface ; accept email from gmail and other domains
  388. (interface "0.0.0.0")
  389. (port 25)
  390. (secure-connection "tls")
  391. (pki pki-gnucode))
  392. (opensmtpd-interface ;; let joshua@gnucode.me send emails
  393. (interface "0.0.0.0")
  394. (port 465)
  395. (secure-connection "smtps")
  396. (pki pki-gnucode)
  397. (auth #t)
  398. (filters (list filter-dkimsign)))
  399. (opensmtpd-interface ;; let joshua@gnucode.me send emails
  400. (interface "0.0.0.0")
  401. (port 587)
  402. (secure-connection "tls-require")
  403. (pki pki-gnucode)
  404. (auth #t)
  405. (filters (list filter-dkimsign)))))
  406. (matches (list
  407. (opensmtpd-match
  408. (action (opensmtpd-relay
  409. (name "relay")))
  410. (options
  411. (list
  412. (opensmtpd-option
  413. (option "for any"))
  414. (opensmtpd-option
  415. (option "from any"))
  416. (opensmtpd-option
  417. (option "auth")))))
  418. (opensmtpd-match
  419. (action action-receive)
  420. (options
  421. (list
  422. (opensmtpd-option
  423. (option "from any"))
  424. (opensmtpd-option
  425. (option "for domain")
  426. (data (opensmtpd-table
  427. (name "vdoms")
  428. (data (list "gnucode.me"
  429. "gnu-hurd.com"))))))))
  430. (opensmtpd-match
  431. (action action-receive)
  432. (options
  433. (list
  434. (opensmtpd-option
  435. (option "for local"))))))))))
  436. (service unattended-upgrade-service-type)
  437. %my-base-services)))
  438. ;; (list (machine
  439. ;; (operating-system %system)
  440. ;; (environment managed-host-environment-type)
  441. ;; (configuration (machine-ssh-configuration
  442. ;; (host-name "45.56.66.20")
  443. ;; (system "x86_64-linux")
  444. ;; (user "joshua")
  445. ;; (identity "~/.ssh/id_rsa")
  446. ;; (host-key "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJgL0hBTWmCVGGvNJYa+YS+fEXs89v0GbdkQ+M+LdZlf root@(none)")
  447. ;; (port 22)))))