Home Assistant IP ban allow list plugin

4 Apr 2024

home-assistant  Python 

I've been a fan of Home Assistant for a while. We use it mostly for our windows/blinds and some heating bits so far (as well as the tree lights this last Xmas), but there's lots of other useful features and addons.

However, something recently has caused us to get repeatedly locked out of the system. It's got an IP banning system that was getting tripped by our own external IP for some reason. I haven't managed to track that one down yet (looked at things like the proxy headers, etc) and I was hoping to just allow list our IP and call it good enough. But, that's not something that's available, and the upstream maintainers appear to be of the "let's fix the actual bugs" opinion. Generally, I'm in agreement with this philosophy, but right now I just wanted to get stuff done. Judging from both that PR's comments and a fairly active community discussion thread, this is wanted though.

I've written a plugin for Home Assistant that solves this. This can be installed with the excellent 3rd party HACS tool, and configured to whatever IPs you want allow listed. How this works is a bit of a hack, but OTOH, it seems to work. What it does is wait for the HTTP bits to be up, and then digs into the relevant objects and wraps the banning feature with a filter. Fundamentally, all of this code is just Python, so you can just do this sort of monkey patching, it's just generally a really bad idea. To try and reduce the level of "oh gods, will this break stuff", I've got integration tests that explicitly both tests banning and the filtered banning, and grabs each of the monthly versions of Home Assistant from 2023.8.4 all the way up to the latest 2024.4.0, so it seems safe so far. Patches welcomed if you find a way to break things :)

Relatedly, I've used uv, a new Python package installer written in Rust for this project, and wow. It's insanely fast. I did a version upgrade of Python from 3.11 to 3.12 for the project, and the time to tear down the old virtualenv and make a new one was about a second or so. Having tooling this fast means you can do things like "always do a package sync before running tests" in the Makefile and not be going "ugh, waiting for the packager again" all the time, which is really useful.

Previously: serial_test - 3.0.0, multi-key support