Commit Graph

10 Commits (nut-monitor)

Author SHA1 Message Date
Dustin 679ea47bf7 r/homeassistant: Protect ~/.ssh
When the Home Assistant container restarts, Podman relabels the entire
`/var/lib/homeassistant` directory as `container_file_t`.  Since the
*homeassistant* user's home directory is `/var/lib/homeassistant`, its
`~/.ssh` directory is thus also relabeled, preventing the SSH daemon
from accessing it.  Since Home Assistant itself does not need access to
this path, we can tell systemd to mount an empty tmpfs filesystem there
in the service unit's mount namespace.  This way, when Podman relabels
the directory, it will change the label of the tmpfs mount point instead
of the actual directory.
2023-06-08 10:05:36 -05:00
Dustin a670e34e90 r/homeassistant: Proxy for Zigbee2MQTT frontend
Zigbee2MQTT now has a web GUI, which makes it *way* easier to manage the
Zigbee network.  Now that I've got all the Philips Hue bulbs controlled
by Zigbee2MQTT instead of the Hue Hub, having access to the GUI is
awesome.
2022-12-12 17:47:05 -06:00
Dustin e55fc8f5af r/homeassistant et al.: Increase start timeout
The first time launching a container after pulling a new image, it can
take several minutes for the container to actually start.  Podman has to
set up the overlay filesystems, which is very slow on a Raspberry Pi.

With the default start timeout, systemd may end up killing the process
before the container is completely set up.  Thus, we need to increase
the timeout to ensure there is plenty of time for Podman to work.
2021-12-20 09:59:14 -06:00
Dustin 6f9ff86788 r/homeassistant: Wait for network to start
Although Home Assistant itself will start fine if the network is not yet
available, some integrations will not.  Notably, the Matrix integration
will fail to load if it cannot contact the homeserver when it is first
initialized.  To avoid this problem, we can just delay starting Home
Assistant until the network is available.
2021-12-18 16:45:53 -06:00
Dustin 7d2b3887c2 Add ability to update HA-related containers
Home Assistant, Zigbee2MQTT, and ZWaveJS2MQTT can now be updated by
setting the corresponding Ansible variable.
2021-08-12 19:02:34 -05:00
Dustin ceeb61cdb0 roles/homeassistant: Proxy ZwaveJS2Mqtt Web UI
ZwaveJS2Mqtt includes a very powerful web-based UI for configuring and
controlling the Z-Wave network.  This functionality is no longer
available within Home Assistant itself, so being able to access the
ZwaveJS2Mqtt UI is crucial to operating the network.

I wanted to make the UI available at */zwave/*, which requires using
*mod_rewrite* to conditionally proxy requests based on the `Connection`
HTTP header, since the UI passes both HTTP and WebSocket requests to the
same paths.  *mod_rewrite* configuration is not inherited from the main
server configuration to virtual hosts, so the
`RewriteRule`/`RewriteCond` directives have to be specified within the
`<VirtualHost>` block.  This means that the Home Assistant proxy
configuration has to be within its own virtual host, and the
Zwavejs2Mqtt configuration has to be there as well.
2021-07-19 15:58:58 -05:00
Dustin 288b050a33 roles/homeassistant: Deploy container with Podman
Installing Home Assistant in a Python virtualenv is rather tedious,
especially on non-x86 machines.  The main issue is Python packages that
include native extensions, as many of these do not have binary wheels
available for aarch64, etc. on PyPI.  Thus, to install these, they have
to be built from source, which then requires the appropriate development
packages to be installed.  Additionally, compiling native code on a
Raspberry Pi is excruciatingly slow.  I have considered various ways of
mitigating this, but all would require a substantial time investment,
both up front and ongoing, making them rather pointless.  Eventually, I
settled on just deploying the official Home Assistant container image
with Podman.

Although Podman includes a tool for generating systemd service unit
files for running containers, I ended up creating my own for several
reasons.  First and foremost, the generated unit files configure the
containers to run as *root*, but I wanted to run Home Assistant as an
unprivileged user.  Unfortunately, I could not seem to get the container
to work when dropping privileges using the `User` directive of the unit.
Fortunately, `podman` has `--uidmap` and `--gidmap` arguments, which I
was able to use to map UID/GID 0 in the container to the *homeassistant*
user on the host.  Another drawback of the generated unit files is that
they specify a "forking" type service, which is not really necessary.
Podman/conmon supports the systemd notify protocol, but the generator
has not been updated to make use of that yet.

Recent versions of Home Assistant are more strict with respect to how
reverse proxies are handled.  In order to use one, it must be explicitly
listed in the configuration file.  Therefore, the *homeassistant*
Ansible role will now create a stub `configuration.yaml`, based on the
one generated by Home Assistant itslf when it starts for the first time
on a new machine, that includes the appropriate configuration for a
reverse proxy running on the same machine.  The stub configuration will
not overwrite an existing configuration file, so it is only useful when
deploying Home Assistant for the first time on a new machine.

Overall, although I think a 300+ MB container image is ridiculous,
deploying Home Assistant this way should make it a lot easier to manage,
especially when updating.
2021-07-19 13:38:08 -05:00
Dustin b4db8eb74d roles/homeassistant: Add HTTPS redirect
Enforce HTTPS access to Home Assistant web UI using a redirect and HSTS.
2020-07-04 14:25:16 -05:00
Dustin b99c7aa27d roles/homeassistant: Install in a virtualenv
Because the Home Assistant user's home directory is on `/var`, Python
packages installed in the "user site" do not get the correct SELinux
labels and thus run in the wrong domain.  This causes a lot of AVC
denials and other issues that prevent Home Assistant from working
correctly.

To resolve this issue, Home Assistant is now installed in a virtual
environment at `/usr/local/homeassistant`.  This directory is still
owned by the Home Assistant user, allowing Home Assistant to manage
packages installed there.  Since it is rooted under `/usr`, files are
labelled correctly and processes launched from executables there will
run in the correct domain.
2020-07-04 14:25:16 -05:00
Dustin 960528c001 roles/homeassistant: Deploy Home Assistant
This commit introduces a *homeassistant* role that installs and sets up
Home Assistant using `pip`.
2019-03-05 18:30:29 -06:00