Commit Graph

1012 Commits (dcf1e5adfc42fea1196fe706643e5047c60ddf18)

Author SHA1 Message Date
Dustin 9286e431ab ci: Use SSH host keys from ssh-hostkeys role
I don't know why I didn't think of this before!  There's no reason to
have to have already copied the `ssh_known_hosts` file from to
`/etc/ssh` before running `ansible-playbook`.  In fact, keys just end up
getting copied from `/etc/ssh/ssh_known_hosts` into `~/.ssh/known_hosts`
anyway.  So let's just make it so that step isn't necessary: copy the
host key database directly to `~/.ssh` and avoid the trouble.
2022-11-09 21:16:21 -06:00
Dustin 8cc909baba ci: Run in Kubernetes instead of Docker
We'll use the `podTemplate` block to define an ephemeral agent running in
a Kubernetes pod as the node for this pipeline.  This takes the place of
the Docker container we used previously.
2022-11-09 20:59:07 -06:00
Dustin e09e684fd8 hosts: Update mtrcs0 FQDN
I moved the metrics Pi from the red network to the blue network.  I
started to get uncormfortable with the firewall changes that were
required to host a service on the red network.  I think it makes the
most sense to define the red network as egress only.
2022-11-09 18:56:05 -06:00
Dustin 0e97d5e39f r/gitea: Update to 1.17.0
The only major change that affects the configuration policy is the
introduction of the `webhook.ALLOWED_HOST_LIST` setting.  For some dumb
reason, the default value of this setting *denies* access to machines on
the local network.  This makes no sense; why do they expect you to host
your CI or whatever on a *public* network?  Of course, the only reason
given is "for security reasons."
2022-09-01 17:29:34 -05:00
Dustin 8965ede50a r/samba-dc: Remove winbindd restorecon workaround
This work-around is no longer necessary as the default Fedora policy now
covers the Samba DC daemon.  It never really worked correctly, anyway,
because Samba doesn't start `winbindd` fast enough for the
`/run/samba/winbindd` directory to be created before systemd spawns the
`restorecon` process, so it would usually fail to start the service the
first time after a reboot.
2022-08-22 20:32:07 -05:00
Dustin 2ca92f68f7 r/frigate: Restart service if it fails
Sometimes, Frigate crashes in situations that should be recoverable or
temporary.  For example, it will fail to start if the MQTT server is
unreachable initially, and does not attempt to connect more than once.
To avoid having to manually restart the service once the MQTT server is
ready, we can configure the systemd unit to enable automatic restarts.
2022-08-22 20:08:09 -05:00
Dustin 1834f9a108 r/bitwarden_rs: Remove dangling container at start
If the *vaultwarden* service terminates unexpectedly, e.g. due to a
power loss, `podman` may not successfully remove the container.  We
therefore need to try to delete it before starting it again, or `podman`
will exit with an error because the container already exists.
2022-08-22 20:06:02 -05:00
Dustin 4511d5447e vm-hosts: Add missing kube.network config
When I added the *systemd-networkd* configuration for the Kubernetes
network interface on the VM hosts, I only added the `.netdev`
configuration and forgot the `.network` part.  Without the latter,
*systemd-networkd* creates the interface, but does not configure or
activate it, so it is not able to handle traffic for the VMs attached to
the bridge.
2022-08-22 20:00:47 -05:00
Dustin 31c73e696f r/z*2mqtt: Restart services after unexpected stop
Both *zwavejs2mqtt* and *zigbee2mqtt* have various bugs that can cause
them to crash in the face of errors that should be recoverable.
Specifically, when there are network errors, the processes do not always
handle these well.  Especially during first startup, they tend to crash
instead of retry.  Thus, we'll move the retry logic into systemd.
2022-08-21 22:25:12 -05:00
Dustin 465aa4d78e r/z*2mqtt: Wait for clock to sync before starting
The *zwavejs2mqtt* and *zigbee2mqtt* services need to wait until the
system clock is fully synchronized before starting.  If the system clock
is wrong, they may fail to validate the MQTT server certificate.

The *time-sync.target* unit is not started until after services that
sync the clock, e.g. using NTP.  Notably, the *chrony-wait.service* unit
delays *time-sync.target* until `chrony waitsync` returns.
2022-08-21 21:58:30 -05:00
Dustin 7044cf3a46 r/hass-dhcp: Start dnsmasq after network is up
The *vlan99* interface needs to be created and activated by
`systemd-networkd` before `dnsmasq` can start and bind to it.  Ordering
the *dnsmasq.service* unit after *network.target* and
*network-online.target* should ensure that this is the case.
2022-08-21 08:03:00 -05:00
Dustin b8b8ae5798 vm-hosts: Define machines to auto start 2022-08-20 21:19:01 -05:00
Dustin 0cd58564c9 r/vmhost: Add autostart script
*libvirt*'s native autostart functionality does not work well for
machines that migrate between hosts.  Machines lose their auto-start
flag when they are migrated, and the flag is not restored if they are
migrated back.  This makes the feature pretty useless for us.

To work around this limitation, I've added a script that is run during
boot that will start the machines listed in `/etc/vm-autostart`, if they
exist.  That file can also insert a delay between starting two machines,
which may be useful to allow services to fully start on one machine
before starting another that may depend on them.
2022-08-20 21:15:31 -05:00
Dustin a433d1b01b hosts: remove dns0.p.b
I've moved handling of DNS to the border firewall instead of a dedicated
virtual machine.  Originally, the VM was necessary because the UniFi
Security Gateway sucked and could not (easily) handle the complex
configuration I wanted to use.  Since moving to the new firewall, this
is no longer a problem.

Having DNS on a VM is problematic when full-network outages occur, like
the one that happened on 16 August 2022.  When everything starts back
up, DNS is unavailable.  libvirt VM autostart does not work for machines
that have been migrated between hosts (the auto-start flag is not
migrated, and libvirt "forgets" that the VM was supposed to autostart if
it is migrated away and back).  I plan to script a solution for this at
some point, but I still think it makes more sense for the firewall to
handle it.  It will certainly make it come up quicker regardless.
2022-08-20 18:20:06 -05:00
Dustin bc60451949 metricspi: Update DNS server address
DNS is now handled by the border firewall.
2022-08-20 18:19:13 -05:00
Dustin a34debbdd5 r/named: Fix typo in firewalld condition 2022-08-20 18:18:38 -05:00
Dustin b7bbafd189 r/protonvpn: Move remote_addrs file to /var
If `/` is mounted read-only, as is usually the case, the Proton VPN
watchdog cannot update the `remote_addrs` configuration file.  It needs
to be stored in a directory that is guaranteed to be writable.
2022-08-20 18:18:21 -05:00
Dustin b6a35f9ce9 r/protonvpn: Install watchdog dependencies
The `protonvpn-watchdog.py` script requires the *httpx* Python package.
This needs to be installed for the script to work.
2022-08-20 18:14:31 -05:00
Dustin 9c364b1f06 r/netboot/basementhud: Configure NBD export
The *netboot/basementhud* Ansible role configures two network block
devices for the basement HUD machine:

* The immutable root filesystem
* An ephemeral swap device
2022-08-15 17:18:48 -05:00
Dustin 4622240c6c r/netboot/jenkins-agent: Configure NBD exports
The *netboot/jenkins-agent* Ansible role configures three NBD exports:

* A single, shared, read-only export containing the Jenkins agent root
  filesystem, as a SquashFS filesystem
* For each defined agent host, a writable data volume for Jenkins
  workspaces
* For each defined agent host, a writable data volume for Docker

Agent hosts must have some kind of unique value to identify their
persistent data volumes.  Raspberry Pi devices, for example, can use the
SoC serial number.
2022-08-15 17:14:06 -05:00
Dustin 20fd03795b hosts: add pxe0.p.b
*pxe0.pyrocufflink.blue* hosts TFTP and NBD for network-booted devices.
2022-08-15 17:13:56 -05:00
Dustin 02e4df023c r/pxe: Set up a PXE server
The *pxe* role configures the TFTP and NBD stages of PXE network
booting.  The TFTP server provides the files used for the boot stage,
which may either be a kernel and initramfs, or another bootloader like
SYSLINUX/PXELINUX or GRUB.  The NBD server provides the root filesystem,
typically mounted by code in early userspace/initramfs.

The *pxe* role also creates a user group called *pxeadmins*.  Users in
this group can publish content via TFTP; they have write-access to the
`/var/lib/tftpboot` directory.
2022-08-15 17:12:35 -05:00
Dustin 5a284faa5c r/tftp: Deploy TFTP server
The *tftp* role installs the *tftp-server* package.  There is
practically no configuration for the TFTP server.  It "just works" out
of the box, as long as its target directory exists.
2022-08-15 17:06:20 -05:00
Dustin 14bfddd0ee r/nbd-server: Deploy nbd-server
The *nbd-server* role configures a machine as a Network Block Device
(NDB) server, using the reference `nbd-server` implementation.  It
configures a systemd socket unit to listen on the port and accept
incoming connections, and a template service unit for systemd to
instantiate and pass each incoming connection.

The reference `nbd-server` is actually not very good.  It does not clean
up closed connections reliably, especially if the client disconnects
unexpectedly.  Fortunately, systemd provides the necessary tools to work
around these bugs.  Specifically, spawning one process per connection
allows processes to be killed externally.  Further, since systemd
creates the listening socket, it can control the keep-alive interval.
By setting this to a rather low value, we can clean up server processes
for disconnected clients more quickly.

Configuration of the server itself is minimal; most of the configuration
is done on a per-export basis using drop-in configuration files.  Other
Ansible roles should create these configuration files to configure
application-specific exports.  Nothing needs to be reloaded or restarted
for changes to take effect; the next incoming connection will spawn a
new process, which will use the latest configuration file automatically.
2022-08-15 16:55:36 -05:00
Dustin cfffd1d782 collectd: Only configure SELinux when used
The `selinux_permissive` module fails on hosts that do not have SELinux
activated.  We must skip running this task on those machines to avoid
fatal errors.
2022-08-14 19:39:02 -05:00
Dustin 82f2a7518e r/system-auth: Disable authselect
*authselect* is now [mandatory][0] in Fedora 36.  It cannot be
uninstalled, but it can be disabled by removing its configuration file.

[0]: https://fedoraproject.org/wiki/Changes/Make_Authselect_Mandatory
2022-08-12 16:54:00 -05:00
Dustin 0de1f84905 r/frigate: Wait for network before starting service
Frigate needs to be able to connect to the MQTT immediately upon start
up or it will crash.  Ordering the *frigate.service* unit after
*network-online.target* will help ensure Frigate starts when the system
boots.
2022-08-12 16:24:28 -05:00
Dustin dbc18022f2 metricspi: Increase scrape_timeout for speedtest
Running the Internet speed test can often take longer than a minute.
2022-08-12 14:54:49 -05:00
Dustin de93ccb0da r/systemd-resolved: Manage systemd resolver daemon
The *systemd-resolved* role/playbook ensures the *systemd-resolved*
service is enabled and running, and ensures that the `/etc/resolv.conf`
file is a symlink to the appropriate managed configuration file.
2022-08-12 14:35:14 -05:00
Dustin 921cf653b8 remount: Do not remount SquashFS volumes
SquashFS volumes, naturally, cannot be remounted read-write.
2022-08-12 13:40:06 -05:00
Dustin 37a205e8a0 ci: lib: Configure SSH key for Ansible
In order for Jenkins to apply configuration policy on machines that are
not members of the *pyrocufflink.blue* domain, it needs to use an SSH
private key for authentication.
2022-08-12 13:30:22 -05:00
Dustin 5a9b9a8d98 mtrcs0: Remove Ansible user/become settings
Jenkins still connects as *jenkins* and uses `sudo`, so we can't
hard-code the user to *root*.
2022-08-12 13:22:47 -05:00
Dustin b4f752acbd hosts: remove stats0
*stats0.pyrocufflink.blue* is being decommissioned.  It has been
completely replaced by *mtrcs0.pyrocufflink.red* at this point.
2022-08-12 13:18:04 -05:00
Dustin d2ee99daa6 mtrcs0: Update SSH host key
I committed the wrong SSH host key.  It was probably from before I
rebuilt the machine using a new SSD.
2022-08-12 13:15:01 -05:00
Dustin 7d323311f5 metricspi: Apply victoria-metrics-nginx role 2022-08-12 13:14:41 -05:00
Dustin 1f04813879 r/v-m-nginx: Prevent requesting reload
Remote systems should not be able to trigger a reload of the services
behind the reverse proxy.
2022-08-12 13:14:05 -05:00
Dustin ce3e88932d vmalert: Allow configuring http.pathPrefix
*vmalert* requires explicit configuration when it is behind a reverse
proxy.
2022-08-12 13:10:36 -05:00
Dustin fe87edea21 r/vmalert: Allow configuring external source URLs
The `-external.url` and `-external.alert.source` command line arguments
and their corresponding environment variables can be used to configure
the "Source" links associated with alerts created by `vmalert`.
2022-08-12 12:58:53 -05:00
Dustin c57500a9f4 metricspi: Update speedtest scrape target
The firewall hardware is too slow to run the *prometheus_speedtest*
program.  It always showed *way* lower speeds than were actually
available.  I've moved the service to the Kubernetes cluster and it
works a lot better there.
2022-08-12 12:55:52 -05:00
Dustin 887d462127 r/v-m-nginx: Proxy for other services too
The *metricspi* hosts several Victoria Metrics-adjacent applications.
These each expose their own HTTP interface that can be used for
debugging or introspecting state.  To make these accessible on the
network, the *victoria-metrics-nginx* role now configures `proxy_pass`
directives for them in its nginx configuration.
2022-08-12 11:59:25 -05:00
Dustin 7ac5493b63 smtp1.p.b: Allow SMTP relay from pyrocufflink.red
AlertManager running on *mtrcs0.pyrocufflink.red* needs to be able to
send e-mail through the SMTP relay.
2022-08-11 21:43:48 -05:00
Dustin 993e29c0fe r/scrape-collectd: collectd scrape targets config
The *scrape-collectd* role generates the
`/etc/prometheus/scrape-collectd.yml` file.  This file can be read by
Prometheus/Victoria Metrics/vmagent to identify the hosts running
*collectd* with the *write_prometheus* plugin, using the
`files_sd_configs` scrape configuration option.

All hosts in the *collectd-prometheus* group are listed as scrape
targets.
2022-08-11 21:40:19 -05:00
Dustin 4ddbc9f256 hosts: Add mtrcs0.p.r
*mtrcs0.pyrocufflink.red* is a Raspberry Pi CM4 on a Waveshare
CM4-IO-BASE-B carrier board with a NVMe SSD.  It runs a custom OS built
using Buildroot, and is not a member of the *pyrocufflink.blue* AD
domain.

*mtrcs0.p.r* hosts Victoria Metrics/`vmagent`, `vmalert`, AlertManager,
and Grafana.  I've created a unique group and playbook for it,
*metricspi*, to manage all these applications together.
2022-08-11 21:40:19 -05:00
Dustin 7c654031f0 r/grafana: Allow configuring LDAP CA cert
The `grafana_ldap_root_ca_cert` can be used to set the path to the root
CA certificate (bundle) Grafana uses to validate the certificate
presented by the configured LDAP server.  By default, Grafana uses the
system root CA trust store, but this variable can be used in situations
where this is not suitable.
2022-08-11 21:40:19 -05:00
Dustin b3403268a8 r/vmalert: Deploy vmalert
`vmalert` is a component of Victoria Metrics. It handles alerting and
recording rules, periodically executing queries and dispatching alerts
or writing aggregated data back to the TSDB.
2022-08-11 21:40:19 -05:00
Dustin 0dab3afc85 r/alertmanager: Deploy AlertManager
*AlertManager* is the component of the Prometheus ecosystem responsible
for sending alert notifications.
2022-08-10 22:18:53 -05:00
Dustin 1e14dd7905 r/blackbox-exporter: Deploy blackbox_exporter
The Prometheus *blackbox_exporter* is a tool that can perform arbitrary,
generic ICMP, TCP, or HTTP "probes" against external services.  This is
useful for applications that do not export their own metrics, and for
evaluating the health of protocol-level operations (e.g. TLS
certificate expiration).

The *blackbox-exporter* Ansible role installs and configures the
Blackbox Exporter on the target system.  It fetches the specified binary
release from Github and copies it to the remote machine.  It also
creates a systemd unit and configures the Blackbox exporter's "modules"
from the `blackbox_modules` Ansible variable.
2022-08-10 22:18:53 -05:00
Dustin 60505657f3 r/vmagent: Deploy vmagent
The *vmagent* role installs and configures the scraping and routing
agent used in the Victoria Metrics ecosystem.
2022-08-10 22:18:43 -05:00
Dustin 956a40f054 r/victoria-metrics-nginx: Add reverse proxy for V-M
The *victoria-metrics-nginx* role configures *nginx* as a reverse proxy
for Victoria Metrics.
2022-08-10 22:16:48 -05:00
Dustin 31fe128d48 r/collectd: Max unixsock plugin optional
Some hosts may not need this plugin, or may not have it installed.
Notably, it is not needed or used on my systems based on Buildroot,
since the only current use case for it is to keep track of the Fedora
version.
2022-08-10 21:55:54 -05:00