Commit Graph

841 Commits (af295cec1bf10cd4121a168919eefe1e2a686072)

Author SHA1 Message Date
Dustin 9408ee31c3 home-assistant: Back up Zigbee/ZWave/Mosquitto
Mosquitto, Zigbee2MQTT, and ZWaveJS2MQTT all have persistent state that
needs to be backed up in addition to Home Assistant's own data.
2022-12-23 06:56:52 -06:00
Dustin 6b4b18dac8 facts: Add PB to force fetching facts
Some playbooks/roles require facts from machines other than the target.
The `facts.yml` playbook can be used to gather facts from machines
without running any other tasks.
2022-12-23 06:56:52 -06:00
Dustin 10344b07c7 hosts: Add ag62kz.p.b
New domain controller (Fedora 37): *ag62kz.pyrocufflink.blue*
2022-12-23 06:56:52 -06:00
Dustin 8e1c67f591 hosts: Remove dc2
*dc2.pyrocufflink.blue* has been decommissioned.
2022-12-23 06:56:52 -06:00
Dustin f0a70c70e5 samba-dc: Install dch-selinux
The *dch-selinux* package contains a SELinux policy module for Samba AD
DC.  This policy defines a `samba_t` domain for the `samba` process.
While the domain is (currently) unconfined, it is necessary in order to
provide a domain transition rule for `winbindd`.  Without this rule,
`winbindd` would run in `unconfined_service_t`, which causes its IPC
pipe files to be incorrectly labelled, preventing other confined
services like `sshd` from accessing them.
2022-12-23 06:54:28 -06:00
Dustin 4bc587e408 r/dch-selinux: Install dch-selinux package
The *dch-selinux* package contains customized SELinux policy modules.
I haven't worked out exactly how to build an publish it through a
continuous integration pipeline yet, so for now it's just hosted in my
user `public_html` folder on the main file server.
2022-12-23 06:52:28 -06:00
Dustin 5661910a21 samba-dc: Add sysvolsync script
Samba AD DC does not implement [DFS-R for replication of the SYSVOL][0]
contents.  This does not make much of a difference to me, since
the SYSVOL is really only used for Group Policy.  Windows machines may
log an error if they cannot access the (basically empty) GPO files, but
that's pretty much the only effect if the SYSVOL is in sync between
domain controllers.

Unfortunately, there is one side-effect of the missing DFS-R
functionality that does matter.  On domain controllers, all user,
computer, and group accounts need to have Unix UID/GID numbers mapped.
This is different than regular member machines, which only need UID/GID
numbers for users that will/are allowed to log into them.  LDAP entries
only have ID numbers mapped for the latter class of users, which does
not include machine accounts.  As a result, Samba falls back to
generating local ID numbers for the rest of the accounts.  Those ID
numbers are stored in a local database file,
`/var/lib/samba/private/idmap.ldb`.  It would seem that it wouldn't
actually matter if accounts have different ID numbers on different
domain controllers, but there are evidently [situations][1] where DCs
refuse to allocate ID numbers at all, which can cause authentication to
fail.  As such, the `idmap.ldb` file needs to be kept in sync.

If we're going to go through the effort of synchronizing `idmap.ldb`, we
might as well keep the SYSVOL in sync as well.  To that end, I've
written a script to synchronize both the SYSVOL contents and the
`idmap.ldb` file.  It performs a simple one-way synchronization using
`rsync` from the DC with the PDC emulator role, as discovered using DNS
SRV records.  To ensure the `idmap.ldb` file is in a consistent state,
it only copies the most recent backup file.  If the copied file differs
from the local one, the script stops Samba and restores the local
database from the backup.  It then flushes Samba's caches and restarts
the service.  Finally, it fixes the NT ACLs on the contents of the
SYSVOL.

Since the contents of the SYSVOL are owned by root, naturally the
synchronization process has to run as root as well.  To attempt to limit
the scope of control this would give the process, we use as much of the
systemd sandbox capabilities as possible.  Further, the SSH key pairs
the DCs use to authenticate to one another are restricted to only
running rsync.  As such, the `sysvolsync` script itself cannot run
`tdbbackup` to back up `idmap.ldb`.  To handle that, I've created a
systemd service and corresponding timer unit to run `tdbbackup`
periodically.

I considered for a long time how to best implement this process, and
although I chose this naïve implementation, I am not exactly happy with
it.  Since I do not fully understand *why* keeping
the `idmap.ldb` file in sync is necessary, there are undoubtedly cases
where blindly copying it from the PDC emulator is not correct.  There
are definitely cases where the contents of the SYSVOL can be updated on
a DC besides the PDC emulator, but again, we should not run into them
because we don't really use the SYSVOL at all.  In the end, I think this
solution is good enough for our needs, without being so complicated

[0]: https://wiki.samba.org/index.php?title=SysVol_replication_(DFS-R)&oldid=18120
[1]: https://lists.samba.org/archive/samba/2021-November/238370.html
2022-12-22 18:55:07 -06:00
Dustin 77191c8b5a Fedora37: Set collectd SELinux domain permissive
*collectd* is broken by default on Fedora 36 and 36.  Several plugins
generate AVC denials.
2022-12-19 10:22:00 -06:00
Dustin 019276da88 collect: Import dyngroups.yml playbook
We need to import the `dyngroups.yml` playbook so that the dynamic host
groups are populated.  Without this, the *RedHat* group is empty, so the
*collectd-version* role is never applied.
2022-12-19 10:20:57 -06:00
Dustin 4a1e961d57 dyngroups: Also group by distribution and version
Adding dynamic groups for speciffic Linux distributions and versions
thereof so we can apply settings based on those properties.
2022-12-19 10:20:09 -06:00
Dustin 3cc501abef collect: Restart after changing SELinux permissive
*collectd* needs to be restarted after changing its SELinux domain
to/from permissive, as many operations that may fail only happen at
startup.
2022-12-19 10:19:08 -06:00
Dustin 3949a40f64 r/collectd-version: Fix handlers
Upating the `collect-version` script should restart the
*collectd-version* service, not *collectd* itself.
2022-12-19 10:17:57 -06:00
Dustin 637289036a blackbox: Update pyrocufflink DNS check
I changed the naming convention for domain controller machines.  They
are no longer "numbered," since the plan is to rotate through them
quickly.  For each release of Fedora, we'll create two new domain
controllers, replacing the existing ones.  Their names are now randomly
generated and contain letters and numbers, so the Blackbox Exporter
check for DNS records needs to account for this.
2022-12-19 09:04:37 -06:00
Dustin 066a68318c hosts: Add dc-4k6s8e.p.b
This is a new domain controller running Fedora 37.
2022-12-18 22:49:44 -06:00
Dustin 57702bb9c7 hosts: vmhost[01]: Update static DNS server address 2022-12-18 20:19:32 -06:00
Dustin caef7f342b vm-hosts: Update autostart list
* Remove DC0 (decommissioned)
* Remove Jenkins and its build VMs (Migrated to Kubernetes)
* Add pxe0 (Required for Basement HUD)
2022-12-18 19:55:48 -06:00
Dustin cdc120bb07 ci: Add metricspi pipeline 2022-12-18 19:30:00 -06:00
Dustin 77c6408187 metricspi: Remove sensors scrape job
Sensor data are retrieved via Home Assistant.
2022-12-18 19:16:10 -06:00
Dustin da2b3c4d59 hosts: Remove dc0
Finally got this guy shut down!
2022-12-18 19:12:58 -06: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 bdd0310cf6 ci: lib: Update for latest ansible container image
The latest version of the *ansible* container runs processes as the
unprivileged *jenkins* user, provides its own "sleep forever" default
command, and sets the correct LANG environment variable.  Since it runs
processes as *jenkins*, we need to override HOME and set it to the
WORKSPACE to ensure Jenkins has a writable path for arbitrary files.
2022-12-03 13:36:10 -06:00
Dustin 244482ac52 websites: Add hatchlearningcenter.org
This is the website for Tabitha's new hybrid private school! 👩‍🎓
2022-11-30 22:04:29 -06:00
Dustin 11e26c3189 hosts: Remove jenkins0, build0
The Jenkins controller is now hosted in Kubernetes.  Relatedly, jobs
all run in Kubernetes pods, and there is no longer any need for static
agents.
2022-11-27 17:21:03 -06:00
Dustin 772f669ab2 r/gitea: Handle encoded / characters in HTTP paths
Gitea package names (e.g. OCI images, etc.) can contain `/` charactres.
These are encoded as %2F in request paths.  Apache needs to forward
these sequences to the Gitea server without decoding them.
Unfortunately, the `AllowEncodedSlashes` setting, which controls this
behavior, is a per-virtualhost setting that is *not* inherited from the
main server configuration, and therefore must be explicitly set inside
the `VirtualHost` block.  This means Gitea needs its own virtual host
definition, and cannot rely on the default virtual host.
2022-11-27 17:21:03 -06:00
Dustin c625b28d6d ci: radius: Convert to using shared library 2022-11-09 21:37:01 -06:00
Dustin 42830c1d5b ci: samba-dc: Convert to using shared library 2022-11-09 21:36:23 -06:00
Dustin eff98691fe ci: smtp: Convert to using shared library 2022-11-09 21:35:18 -06:00
Dustin db28544824 ci: ntp: Convert to using shared library 2022-11-09 21:31:53 -06:00
Dustin 6af78aadda ci: Set LANG environment variable
Hopefully this will fix this warning from Ansible:

> [WARNING]: An error occurred while calling
> ansible.utils.display.initialize_locale (unsupported locale setting).
> This may result in incorrectly calculated text widths that can cause
> Display to print incorrect line lengths
2022-11-09 21:24:29 -06:00
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