gnucode.me-current-config.scm 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  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* nss-certs ;for HTTPS access
  188. openssh-sans-x
  189. %base-packages))
  190. (services (cons*
  191. (service dhcp-client-service-type)
  192. ;; guix daemon requires avahi
  193. (service avahi-service-type)
  194. (service certbot-service-type
  195. (certbot-configuration
  196. (email "jbranso@dismail.de")
  197. (webroot "/srv/www")
  198. (certificates
  199. (list
  200. (certificate-configuration
  201. (name "gnucode.me")
  202. (domains '("gnucode.me" "www.gnucode.me"
  203. "imap.gnucode.me"
  204. "smtp.gnucode.me"))
  205. (deploy-hook %nginx-deploy-hook))
  206. (certificate-configuration
  207. (name "gnu-hurd.com")
  208. (domains '("gnu-hurd.com" "www.gnu-hurd.com"))
  209. (deploy-hook %nginx-deploy-hook))
  210. (certificate-configuration
  211. (name "propernaming.org")
  212. (domains '("propernaming.org" "www.propernaming.org"))
  213. (deploy-hook %nginx-deploy-hook))
  214. ))))
  215. (service dovecot-service-type
  216. (dovecot-configuration
  217. (mail-location "maildir:/home/%n/Maildir")
  218. (protocols
  219. (list
  220. (protocol-configuration
  221. (name "imap")
  222. ;; 3 was too few. Sometimes I will have several email clients
  223. ;; open. So 5 is a better number.
  224. (mail-max-userip-connections 5)
  225. )
  226. ;;(protocol-configuration name "lmtp")
  227. ))
  228. ;; I am hoping to set up LMTP, that way I can set up Sieve filtering.
  229. ;; https://doc.dovecot.org/configuration_manual/sieve/configuration/
  230. ;; https://doc.dovecot.org/configuration_manual/protocols/lmtp_server/#lmtp-server
  231. ;; (services
  232. ;; (list
  233. ;; (service-configuration
  234. ;; (kind "imap"))))
  235. ;; someone tries to login via joshua@gnucode.me
  236. ;; this strips away that login username to "joshua"
  237. ;; when I set up virtual users, I'll need to delete this!
  238. ;; https://wiki.dovecot.org/DomainLost
  239. ;; "%n-AT-%d" -> joshua@gnucode.me -> joshua-AT-gnucode.me
  240. (auth-username-format "%n")
  241. (ssl-cert "</etc/letsencrypt/live/gnucode.me/fullchain.pem")
  242. (ssl-key "</etc/letsencrypt/live/gnucode.me/privkey.pem")
  243. ))
  244. ;;(service gnucode -form-service-type)
  245. (service fail2ban-service-type
  246. (fail2ban-configuration
  247. (extra-jails
  248. (list
  249. (fail2ban-jail-configuration
  250. (name "sshd")
  251. (enabled? #t))))))
  252. (service nginx-service-type
  253. (let ([default-listen (list "80"
  254. "443 ssl http2"
  255. "[::]:80"
  256. "[::]:443 ssl http2"
  257. )]
  258. ;; tell browsers my site supports HTTPS, and tell them that it will
  259. ;; at least work for 12 hours. Gradually, I will increase this number.
  260. [default-raw-content (list "add_header Strict-Transport-Security max-age=18000;")]
  261. [srv-root-dir "/srv/www/html/"]
  262. [letsencrypt-dir "/etc/letsencrypt/live/"]
  263. [letsencrypt-acme-challenge (nginx-location-configuration ;; for certbot
  264. (uri "/.well-known")
  265. (body (list "root /srv/www;")))])
  266. (nginx-configuration
  267. (server-blocks
  268. (list
  269. (nginx-server-configuration
  270. (server-name '("gnucode.me"))
  271. (listen default-listen)
  272. (root "/srv/www/html/gnucode.me/site/")
  273. (ssl-certificate (string-append letsencrypt-dir "gnucode.me/fullchain.pem"))
  274. (ssl-certificate-key (string-append letsencrypt-dir "gnucode.me/privkey.pem"))
  275. (raw-content default-raw-content)
  276. (locations
  277. (list
  278. letsencrypt-acme-challenge ;; for certbot
  279. (nginx-location-configuration
  280. (uri "/form/")
  281. (body '("proxy_pass http://127.0.0.1:8081;")))
  282. (nginx-location-configuration
  283. (uri "/craggy-hurd/")
  284. (body
  285. (list ("root /srv/www/html/gnucode.me/site/craggy-hurd/rendered/;"))))
  286. ;; (nginx-location-configuration
  287. ;; (uri "/agenda/")
  288. ;; (body
  289. ;; (list
  290. ;; (string-append "root " srv-root-dir "gnucode.me/agenda/;\n")
  291. ;; ;(string-append "auth_basic \"Yearly Agenda\";\n")
  292. ;; ;(string-append "auth_basic_user_file " srv-root-dir "gnucode.me/agenda/htpasswd;")
  293. ;; )))
  294. )))
  295. (nginx-server-configuration
  296. (server-name '("gnu-hurd.com"))
  297. (listen default-listen)
  298. (root "/srv/www/html/gnu-hurd.com/")
  299. (ssl-certificate (string-append letsencrypt-dir "gnu-hurd.com/fullchain.pem"))
  300. (ssl-certificate-key (string-append letsencrypt-dir "gnu-hurd.com/privkey.pem"))
  301. (raw-content default-raw-content)
  302. (locations
  303. (list
  304. letsencrypt-acme-challenge ;; for certbot
  305. )))
  306. (nginx-server-configuration
  307. (server-name '("propernaming.org"))
  308. (listen default-listen)
  309. (root "/srv/www/html/propernaming.org/site/")
  310. (ssl-certificate (string-append letsencrypt-dir "propernaming.org/fullchain.pem"))
  311. (ssl-certificate-key (string-append letsencrypt-dir "propernaming.org/privkey.pem"))
  312. (raw-content default-raw-content)
  313. (locations
  314. (list
  315. letsencrypt-acme-challenge ;; for certbot
  316. )))
  317. )))))
  318. (service openssh-service-type
  319. (openssh-configuration
  320. (openssh openssh-sans-x)
  321. (password-authentication? #f)
  322. (port-number 22)
  323. (authorized-keys
  324. `(
  325. ("joshua" ,(plain-file "id_rsa.pub" %joshua-ssh-key))
  326. ("root" ,(plain-file "id_rsa.pub" %joshua-ssh-key))
  327. ))))
  328. ;; I've created the prosody admin user, and I imported the cert...
  329. ;; but pidgin tells me that I the XMPP server at gnucode.me does not support encryption.
  330. (service prosody-service-type
  331. (prosody-configuration
  332. ;;(certificates "/etc/")
  333. (admins '("jbranso@gnucode.me"))
  334. (virtualhosts
  335. (list
  336. (virtualhost-configuration
  337. (domain "gnucode.me"))))))
  338. ;; I can test send an email from my ssh machine via:
  339. ;; cat test-email.txt | msmtp -- jbranso@dismail.de
  340. ;; (service opensmtpd-service-type
  341. ;; (opensmtpd-configuration
  342. ;; (config-file %smtpd.conf)))
  343. ;; TODO my nftables for a server ARE NOT working.
  344. ;; (service nftables-service-type
  345. ;; (nftables-configuration
  346. ;; (ruleset
  347. ;; (plain-file "nftables.conf" %gnucode-nftables-ruleset))))
  348. (service opensmtpd-service-type
  349. (let ([action-receive
  350. (opensmtpd-local-delivery
  351. (name "receive")
  352. (method (opensmtpd-lmtp
  353. (destination "/var/run/dovecot/lmtp"))))
  354. ;; (opensmtpd-local-delivery
  355. ;; (name "receive")
  356. ;; (method (opensmtpd-maildir
  357. ;; (pathname "/home/%{rcpt.user}/Maildir")
  358. ;; (junk #t)))
  359. ;; (virtual (opensmtpd-table
  360. ;; (name "vusers")
  361. ;; (data '(("joshua@gnucode.me" . "joshua")
  362. ;; )))))
  363. ]
  364. [pki-gnucode (opensmtpd-pki
  365. (domain "smtp.gnucode.me")
  366. (cert "/etc/letsencrypt/live/gnucode.me/fullchain.pem")
  367. (key "/etc/letsencrypt/live/gnucode.me/privkey.pem"))]
  368. [filter-dkimsign (opensmtpd-filter
  369. (name "dkimsign")
  370. (exec #t)
  371. (proc (list (file-append opensmtpd-filter-dkimsign "/libexec/opensmtpd/filter-dkimsign")
  372. " -d gnucode.me -s 2023-02-28 -c relaxed/relaxed -k "
  373. "/etc/opensmtpd/dkimsign/02-28-2023-rsa1024-gnucode.me-private.key "
  374. "user nobody group nogroup")))]
  375. ;; [table-creds (opensmtpd-table
  376. ;; (name "creds")
  377. ;; (data
  378. ;; (list
  379. ;; (cons "joshua"
  380. ;; "$6$Ec4m8FgKjT2F/03Y$k66ABdse9TzCX6qaALB3WBL9GC1rmAWJmaoSjFMpbhzat7DOpFqpnOwpbZ34wwsQYIK8RQlqwM1I/v6vsRq86."))))]
  381. )
  382. (opensmtpd-configuration
  383. (interfaces
  384. (list
  385. ;; this forum help suggests that I listen on 0.0.0.0 and NOT eth0
  386. ;; https://serverfault.com/questions/726795/opensmtpd-wont-work-at-reboot
  387. ;; this listens for email from the outside world
  388. (opensmtpd-interface ; accept email from gmail and other domains
  389. (interface "0.0.0.0")
  390. (port 25)
  391. (secure-connection "tls")
  392. (pki pki-gnucode))
  393. (opensmtpd-interface ;; let joshua@gnucode.me send emails
  394. (interface "0.0.0.0")
  395. (port 465)
  396. (secure-connection "smtps")
  397. (pki pki-gnucode)
  398. (auth #t)
  399. (filters (list filter-dkimsign)))
  400. (opensmtpd-interface ;; let joshua@gnucode.me send emails
  401. (interface "0.0.0.0")
  402. (port 587)
  403. (secure-connection "tls-require")
  404. (pki pki-gnucode)
  405. (auth #t)
  406. (filters (list filter-dkimsign)))))
  407. (matches (list
  408. (opensmtpd-match
  409. (action (opensmtpd-relay
  410. (name "relay")))
  411. (options
  412. (list
  413. (opensmtpd-option
  414. (option "for any"))
  415. (opensmtpd-option
  416. (option "from any"))
  417. (opensmtpd-option
  418. (option "auth")))))
  419. (opensmtpd-match
  420. (action action-receive)
  421. (options
  422. (list
  423. (opensmtpd-option
  424. (option "from any"))
  425. (opensmtpd-option
  426. (option "for domain")
  427. (data (opensmtpd-table
  428. (name "vdoms")
  429. (data (list "gnucode.me"
  430. "gnu-hurd.com"))))))))
  431. (opensmtpd-match
  432. (action action-receive)
  433. (options
  434. (list
  435. (opensmtpd-option
  436. (option "for local"))))))))))
  437. (service unattended-upgrade-service-type)
  438. %my-base-services)))
  439. ;; (list (machine
  440. ;; (operating-system %system)
  441. ;; (environment managed-host-environment-type)
  442. ;; (configuration (machine-ssh-configuration
  443. ;; (host-name "45.56.66.20")
  444. ;; (system "x86_64-linux")
  445. ;; (user "joshua")
  446. ;; (identity "~/.ssh/id_rsa")
  447. ;; (host-key "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJgL0hBTWmCVGGvNJYa+YS+fEXs89v0GbdkQ+M+LdZlf root@(none)")
  448. ;; (port 22)))))