alexkarle.com

Source for alexkarle.com
git clone git://git.alexkarle.com/alexkarle.com.git
Log | Files | Refs | README | LICENSE

state-of-the-homelab-2022-09.txt (10558B) [raw]


      1 # State of the Homelab
      2 
      3 _Published: September 12, 2022_
      4 
      5 I've been sinking some time recently into organizing my
      6 homelab, spurred by the recent addition of a NAS, and thought
      7 it might be a good time to write about it.
      8 
      9 ## Birds Eye View
     10 
     11 Here's the network topology:
     12 
     13 	          ┌──────────────┐     ┌───────┐
     14 	          │ Wifi Clients │     │ Wired │
     15 	          └──────────────┘     │Clients│
     16 	                 :             └───┬───┘
     17 	                 :                 │
     18 	         ┌───────▼───────┐    ┌────▼─────┐
     19 	Internet │   Verizon     ├────► OpenBSD  │
     20 	─────────►    Router     │    │  Router  │
     21 	         │ (FiosGateway) ◄────┤ (apu2e4) │
     22 	         └──────┬──▲─────┘    └──┬───▲───┘
     23 	                │  │             │   │
     24 	            ┌───▼──┴──┐      ┌───▼───┴────┐
     25 	            │ pi.hole │      │  NAS/Git   │
     26 	            │ (Rpi4b) │      │(Odroid HC4)│
     27 	            └─────────┘      └────────────┘
     28 
     29 
     30 Excluding the Fios router, that's 3 servers hosting
     31 the following services:
     32 
     33 - A git server for private repos (public repos hosted on
     34   [git.alexkarle.com](https://git.alexkarle.com), and
     35   [sourcehut](https://git.sr.ht)).
     36 - A NAS (network attached storage) for backups, photos, music, etc
     37 - A network wide ad-blocker ([pi-hole](https://pi-hole.net/))
     38 - An OpenBSD router/firewall (dhcp / pf) to provide extra security
     39   to my wired devices.
     40 
     41 
     42 ## Why Bother with a Homelab, Anyways?
     43 
     44 Before I dive into each component, I want to take a step back and
     45 ask _why_.
     46 
     47 In a world where you can pay `$HIP_COMPANY` $5/mo to
     48 run or host anything, it may seem like a homelab
     49 is a waste of time and effort. Looking at what I'm running,
     50 a lot of it could even be hosted for free!
     51 
     52 Despite the time cost of tending to this digital garden,
     53 I've found that
     54 running my homelab has been an incredible source of learning from
     55 hands-on experimentation. At this stage in my career, this type
     56 of experience is invaluable, especially because a lot of it
     57 (hardware tinkering, sysadmin tasks, linux distros, etc) doesn't
     58 come across my desk often.
     59 
     60 As an added bonus, I really enjoy the feeling of digital ownership
     61 I get from hosting my private data. It certainly comes with the
     62 weight of responsibility that I need to keep (and test!) backups,
     63 but the learning and ownership feel worthwhile for now.
     64 
     65 ## The Nitty Gritty
     66 
     67 ### Fios Gateway
     68 
     69 I have no special attachment to Verizon--I wouldn't go so far as
     70 to endorse them, but my coworkers don't complain about lag during
     71 video calls, so I haven't mustered the courage to switch providers.
     72 
     73 It's on my long todo list to switch to a more local ISP, but with
     74 both me and my fiance working from home it's the last place
     75 I want an outage.
     76 
     77 ### Pi Hole
     78 
     79 Pi-hole is a network wide adblocker. It works by acting as the DNS
     80 server for your network and responding with localhost (0.0.0.0) for
     81 known spammy domains.
     82 
     83 As a concrete example, with pi-hole running right now, I can't access
     84 doubleclick.net (Google ads):
     85 
     86 	# Response from my router
     87 	$ host doubleclick.net 192.168.1.1
     88 	Using domain server:
     89 	Name: 192.168.1.1
     90 	Address: 192.168.1.1#53
     91 	Aliases: 
     92 	
     93 	doubleclick.net has address 0.0.0.0
     94 	doubleclick.net has IPv6 address ::
     95 	
     96 	
     97 	# Response from Google's DNS resolver
     98 	$ host doubleclick.net 192.168.1.1
     99 	Using domain server:
    100 	Name: 8.8.8.8
    101 	Address: 8.8.8.8#53
    102 	Aliases: 
    103 	
    104 	doubleclick.net has address 142.251.41.14
    105 	[...]
    106 
    107 The default configuration for the Gateway router is to tell clients
    108 to use it (192.168.1.1) as a DNS server. By updating Gateway to use
    109 pi-hole as _it's_ server (instead of the Verizon supplied ones), all
    110 clients on the network receive pi-hole's filtering.
    111 
    112 What's brilliant about this is that no clients need updating. As far
    113 as they're aware, they _really are_ trying to reach out to doubleclick.net.
    114 It's just a network failure that 0.0.0.0 isn't listening on 443!
    115 
    116 The results are most noticeable on mobile since I use uBlock Origin on
    117 all my browsers. It's amazing how much faster and less cluttered
    118 certain mobile apps are without ads (cough nytimes cough please stop
    119 it with the full screen banners).
    120 
    121 Finally, as the name might imply, the pi-hole was designed to run on the
    122 Raspberry Pi. I'm running mine on a
    123 [Raspberry Pi 4b](https://www.raspberrypi.com/products/raspberry-pi-4-model-b/),
    124 which is definitely overkill for the resources it needs.
    125 
    126 
    127 ### Git Server
    128 
    129 Running a private git server is incredibly easy. In fact, there isn't
    130 really any separate git daemon that needs running. So long as you have
    131 ssh access to the host, you can clone/push/pull from:
    132 
    133 	$ git clone user-on-host@host:/path/to/server
    134 
    135 I like to get a bit fancy and `adduser` a `git` user on the server so
    136 that the repos can be stored in its home directory and ssh access can
    137 be managed separately from the user account I would normally use.
    138 
    139 Assuming the `git` user has the home directory `/home/git`, the following
    140 will clone `/home/git/repo.git`:
    141 
    142 	$ git clone git@host:repo.git
    143 
    144 Much cleaner!
    145 
    146 A lot more detail, including securing the git user by assigning it the
    147 `git-shell` for the login shell, can be found in the amazing
    148 [Pro Git](https://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server)
    149 book.
    150 
    151 As far as _what_ I keep on my personal server (that I wouldn't trust
    152 to sourcehut, or even really my own git.alexkarle.com), I host the following
    153 repos:
    154 
    155 - My password repository (for [`pass(1)`](https://www.passwordstore.org/))
    156 - Personal notes (public notes go on [gopher://alexkarle.com/1/notes]!)
    157 
    158 In the past (mostly for fun), I've hosted [cgit](https://git.zx2c4.com/cgit/about/),
    159 [gitea](https://gitea.io/) and even GitLab (reverse chronologically
    160 and also least to most heavy). I've found that for the few private
    161 repos I host, I rarely want a web UI (let alone forking/user accounts/etc).
    162 
    163 ### NAS
    164 
    165 The most recent upgrade to my homelab was the addition of a purpose-built
    166 NAS using the [Odroid HC4](https://www.hardkernel.com/shop/odroid-hc4/)
    167 toaster-style dual hard drive board.
    168 
    169 Previously, my backups were distributed across multiple drives and
    170 frequently offline (with all my operating system tinkering I have 5
    171 SSD's of which only 2 are in use at any time...). Things that I
    172 needed frequent access to were stored on a (rather fragile) Raspberry Pi 3b
    173 on a 64GB thumbdrive! Needless to say, the HC4 is a step up.
    174 
    175 It's only really been online for ~24hrs so I don't have a solid review
    176 of the hardware yet, but initial impressions are:
    177 
    178 - I was a bit bummed that the Linux they support is an old forked kernel,
    179   which strikes me as probably missing security patches (didn't poke around
    180   hard enough to confirm though--it may be up to date and just old!)
    181 - Despite being on the OpenBSD hardware list, I couldn't get it to boot.
    182   Given the need to unscrew the plastic top to get the UART serial connection
    183   in, I stopped trying after a few hours :(. I might email the mailing list
    184   in the future to see what I overlooked.
    185 - I was pleased to find that the [Armbian](https://www.armbian.com/odroid-hc4/)
    186   project supported it (with a newer kernel!). This is what I ended up
    187   installing (with no issues so far)
    188 - I stumbled across [Chandler Swift's](https://chandlerswift.com/2021/05/07/odroid-hc4-nas)
    189   awesome writeup about his experience with the HC4 and his golang
    190   [odroidhc4-display](https://github.com/ChandlerSwift/odroidhc4-display) tool
    191   is the perfect easy-to-deploy service for the little display
    192 
    193 Overall, operating system quirks aside, I'm really happy with how it turned
    194 out. I put in two 2TB western digital drives (whatever BestBuy had on sale
    195 a few weekends ago) and encrypted both of them with `cryptsetup` using the
    196 LUKS encryption mode as described in the
    197 [Arch Wiki](https://wiki.archlinux.org/title/Dm-crypt/Device_encryption).
    198 I intentionally did not RAID-1 the drives together because I'm more worried
    199 about accidentally `rm`-ing a file than I am not having access to the data
    200 in case of drive failure. Instead, I have only one drive always online. A
    201 cron job mounts the offline drive daily, `rsync`'s over the data, and
    202 unmounts it when done. This should give me hopefully a few hours or more
    203 if I realize I deleted a file. (I'll eventually also cycle in a third drive
    204 for offsite storage somewhere trusted like my parents' house).
    205 
    206 In the future I'd love to use this NAS as an excuse to explore fancier
    207 filesystems like ZFS, but I stuck to ext4 for now.
    208 
    209 
    210 ### OpenBSD Firewall/Router
    211 
    212 *Puts tinfoil hat on.*
    213 
    214 The final piece of the topology is maybe the least functional in terms
    215 of hosting required services but the best learning tool: the OpenBSD router.
    216 
    217 There are arguably some security wins here by bisecting my network between
    218 wifi and wired clients. For one, the Verizon router itself may or may not
    219 be receiving security patches (it's proprietary, who knows?). By setting
    220 up a firewall so that the only traffic going in to wired clients is the
    221 traffic expected, the wired clients are a tad safer.
    222 
    223 While the security angle is certainly appealing, the much bigger reason
    224 to have this in my homelab has been experimenting with router technologies.
    225 In setting this up I had to grok `pf` (packet filtering for the firewall),
    226 `dhcpd` (to give clients IP addresses), and just basic networking
    227 (how _does_ a machine in one network talk to another?). There's no better
    228 way to learn networking than having my wifi laptop trying to ping my
    229 wired desktop and `tcpdump`ing the traffic.
    230 
    231 This is running on a PC Engines [apu2e4](https://www.pcengines.ch/apu2e4.htm),
    232 mostly since it seemed popular with the community and I wanted to make sure
    233 the device had good OpenBSD support. It's been running since April 2021
    234 without issues, so I'd recommend it!
    235 
    236 I would eventually love to write my own pi-hole using the DNS tools in
    237 base, but for now it's low on my todo list.
    238 
    239 ## Conclusion
    240 
    241 If you made it this far, thanks! I hope you learned something or found
    242 something of interest.
    243 
    244 I'll hopefully write a similar "state of the cloud" post to cover the
    245 services I'm running outside home, but I think this post might just be
    246 long enough for now :)
    247 
    248 *Update:* [State of the Cloud](/blog/state-of-the-cloud-2022-09.html)
    249 post has been written!