Commit Graph

465 Commits (217b13faff361579d4d14a3dfe8debeec07bc647)

Author SHA1 Message Date
Dustin 6c71d96f81 r/frigate-caddy: Deploy Caddy in front of Frigate
Deploying Caddy as a reverse proxy for Frigate enables HTTPS with a
certificate issued by the internal CA (via ACME) and authentication via
Authelia.

Separating the installation and base configuratieon of Caddy into its
own role will allow us to reuse that part for other sapplications that
use Caddy for similar reasons.
2024-08-12 18:47:04 -05:00
Dustin 59be10a51c r/gasket-dkms: Build/sign Coral TPU driver
The *gasket-dkms* package provides the `gasket` and `apex` kernel
modules, which are needed fro the Google Coral Edge TPU.  Since these
are out-of-tree modules, they are not allowed in Fedora proper, so they
are provided in a COPR, and have to be rebuilt for every kernel version.
The DKMS framework handles automatically building the modules whenever
the kernel updates.

For systems usign UEFI with SecureBoot enabled, kernel modules must be
signed by a key trusted by the platform.  For locally-built modules, we
can use the Machine Owner Key (MOK).  Unfortunately, enrolling a new MOK
requires rebooting and manual intervention during the boot process.
Therefore, the *gasket-dkms* role has a `pause` step to ensure someone
is paying attention and able handle the key enrollment interactively.

Eventually, I'd like to have an RPM package with these modules
pre-built, so production servers do not need the kernel development
tools (`perl`, `gcc`, headers, etc.).  It will be tricky, though, to
make sure the modules get rebuilt for every kernel version as Fedora
releases them.
2024-08-12 18:47:04 -05:00
Dustin 8dfb2e3e4f r/frigate: Clean up Frigate role
* Switch to Quadlet-style `.container` for systemd unit
* Update to new image tag naming scheme (not arch-specific)
* Use environment variables for secrets
* Allow the entire `frigate_config` variable to be overridden
2024-08-12 18:47:04 -05:00
Dustin 7b61a7da7e r/useproxy: Configure system-wide proxy
The *useproxy* role configures the `http_proxy` et al. environmet
variables for systemd services and interactive shells.  Additionally, it
configures Yum repositories to use a single mirror via the `baseurl`
setting, rather than a list of mirrors via `metalink`, since the proxy
a) the proxy only allows access to _dl.fedoraproject.org_ and b) the
proxy caches RPM files, but this is only effective if all clients use
the same mirror all the time.

The `useproxy.yml` playbook applies this role to servers in the
*needproxy* group.
2024-08-12 18:47:04 -05:00
Dustin f51e0fe2a9 r/samba-dc: Enable auto-restart for samba.service
Setting `RestartSec` is not enough to enable auto-restart; the `Restart`
option is also required, as it defaults to `no`.
2024-08-09 08:11:39 -05:00
Dustin ed22f6311c r/samba-dc: Auto restart samba
Although it's rare, sometimes Samba crashes or fails to start.  When
this happens, restarting it is almost always enough to get it working
again.  Since all sorts of authentication problems can occur if one of
the domain controllers is down, it's probably best to just have systemd
automatically restart _samba.service_ if it ever stops for any reason.
2024-07-03 10:30:20 -05:00
Dustin 4f202c55e4 r/postgres-exporter: Deploy postgres-exporter
The [postgres-exporter][0] exposes PostgreSQL server statistics to
Prometheus.  It connects to a specified PostgreSQL server (in this
case, a server on the local machine via UNIX socket) and collects data
from the `pg_stat_activity`, et al. views.  It needs the `pg_monitor`
role in order to be allowed to read the relevant metrics.

Since we're setting up the exporter to connect via UNIX socket, it needs
a dedicated OS user to match the PostgreSQL user in order to
authenticate via the _peer_ method.

[0]: https://github.com/prometheus-community/postgres_exporter/
2024-07-02 20:44:29 -05:00
Dustin 090ebb0c1b r/wal-g-pg: Schedule daily backups
WAL archives are not much good without a base backup onto which they
can be applied.  Thus, we need to schedule WAL-G to create and upload a
backup periodically.
2024-07-02 20:44:29 -05:00
Dustin edffaf258b r/wal-g-pg: Deploy WAL-G for PostgreSQL
This role installs `wal-g` from the DCH Yum repository, and creates a
configuration file for it in `/etc/postgresql`.  Additionally, it
installs a custom SELinux policy module that allows `wal-g` to run in
the `postgresql_t` domain (i.e. when spawned by the PostgreSQL server).
2024-07-02 20:44:29 -05:00
Dustin 99c309240c r/postgresql-cert: ACME certificates using certbot
This role can be used to get a server certificate for PostgreSQL from an
ACME CA using `certbot`.  It fetches the initial certificate and copies
it to the PostgreSQL configuration directory.  It also sets up a
post-renewal hook script that copies updated certificates and reload
the server.
2024-07-02 20:44:29 -05:00
Dustin 9e742dc217 roles/postgresql-server: Rewrite role
This rewrite brings a lot of improvements and new functionality to the
*postgresql-server* role.  The most noticeable change is the
introduction of the `postgresql_config_dir` variable, which can be used
to specify a different location for the PostgreSQL server configuration
files, separate from the data storage directory.  By default, the
variable is set to `/etc/postgresql`.  For some situations, it may be
necessary to disable this functionality, which can be accomplished by
setting the value of `postgresql_config_dir` to the same path as
`pgdata_dir`.  Note also that the `postgresql-setup` tool, and the
corresponding `postgresql-check-db-dir` script, which are included in
the Fedora/Red Hat distribution of PostgreSQL, do not support having
separate configuration and data directories, so their use has to be
disabled.

Another significant improvement is to how the `postgresql.conf` file
is generated.  Any setting can be set now, using the `postgresql_config`
variable; any key in this dictionary will be written to the
configuration file.  Note that configuration file syntax requires
single quotes around string values, so these have to be included in the
YAML value.

To support deploying standby servers, the role now supports running a
command to restore from a backup instead of running `initdb`.
Additionally, the `postgresql_standby` variable can be set to `true`
to create the `recovery.signal` file, configuring the server as a
standby.
2024-07-02 20:44:29 -05:00
Dustin b5eac25f14 r/minio: Fix ExecReload command
Sending SIGHUP to the main PID (i.e. conmon) ends up stopping the
service.  What we really want is to send the signal to main PID _inside_
the container.  We can achieve this by using `podman kill` instead of
`kill`.
2024-06-23 10:43:15 -05:00
Dustin 0464041cf8 r/dnf-automatic: Allow excluding packages
Some hosts may have packages that we do not want to have updated
automatically.  For those, we can set `dnf_automatic_exclude`.
2024-06-23 10:43:15 -05:00
Dustin 7579429a0d r/samba-cert: Save firewall configuration
Without making the firewall changes permanent, when a server tries to
renew its certificate after rebooting, it will fail as the ACME server
cannot connect to the HTTP port.
2024-06-20 19:42:13 -05:00
Dustin 7b24babfab r/collectd-version: Auto-restart service
Sometimes, the `collectd-version` script crashes or fails to start at
boot.  Configuring systemd to automatically restart it will ensure that
it's always running, so machines' versions are consistently inventoried.
2024-06-12 19:03:11 -05:00
Dustin 74e4a4d898 r/squid: Let squid initialize cache dirs
The `squid.service` systemd unit now correctly initializes the
configured cache directories, so we do not need to do it explicitly
before starting the server.
2024-06-12 18:43:23 -05:00
Dustin f54858ee5e r/dch-selinux: Install from dch-yum repository
The *dch-selinux* package is now published to the same Yum repository as
other packages (e.g. *sshca-cli*, etc.), rather than its own repository.
2024-06-12 18:42:22 -05:00
Dustin ffe972d79b r/samba-cert: Obtain LDAP/TLS cert via ACME
The *samba-cert* role configures `lego` and HAProxy to obtain an X.509
certificate via the ACME HTTP-01 challenge.  HAProxy is necessary
because LDAP server certificates need to have the apex domain in their
SAN field, and the ACME server may contact *any* domain controller
server with an A record for that name.  HAProxy will forward the
challenge request on to the first available host on port 5000, where
`lego` is listening to provide validation.

Issuing certificates this way has a couple of advantages:

1. No need for the wildcard certificate for the *pyrocufflink.blue*
   domain any more
2. Renewals are automatic and handled by the server itself rather than
   Ansible via scheduled Jenkins job

Item (2) is particularly interesting because it avoids the bi-monthly
issue where replacing the LDAP server certificate and restarting Samba
causes the Jenkins job to fail.

Naturally, for this to work correctly, all LDAP client applications
need to trust the certificates issued by the ACME server, in this case
*DCH Root CA R2*.
2024-06-12 18:33:24 -05:00
Dustin 7b6e0bd100 r/haproxy: Support configuring resolvers
HAProxy uses a special configuration block, `resolvers`, to specify
how it should look up names in DNS.  This configuration is used for
e.g. dynamically discovering backend servers via DNS A or SRV records.
Since resolvers are global, they need to be specified in the global
configuration file, rather than a per-application drop-in.

We will use this functionality for the ACME HTTP-01 challenge solver
for Samba AD domain controllers.
2024-06-12 18:29:56 -05:00
Dustin 29ef364fab r/haproxy: Clean up for modern haproxy versions
The current version of *haproxy* packaged in Fedora already enables
configuration via fragments in a drop-in directory, though it uses
a different path by default.  I still like separating the global
configuration from the defaults, though, and keeping the main
`haproxy.cfg` file empty.
2024-06-12 18:28:16 -05:00
Dustin 58972cf188 auto-updates: Install and configure dnf-automatic
*dnf-automatic* is an add-on for `dnf` that performs scheduled,
automatic updates.  It works pretty much how I would want it to:
triggered by a systemd timer, sends email reports upon completion, and
only reboots for kernel et al. updates.

In its default configuration, `dnf-automatic.timer` fires every day.  I
want machines to update weekly, but I want them to update on different
days (so as to avoid issues if all the machines reboot at once).  Thus,
the _dnf-automatic_ role uses a systemd unit extension to change the
schedule.  The day-of-the-week is chosen pseudo-randomly based on the
host name of the managed system.
2024-06-12 06:25:17 -05:00
Dustin af295cec1b r/bitwarden_rs: Fix EROFS when starting container
Even with `Network=host`, Podman tries to write to
`/etc/containers/network` for some reason.  Fortunately, it doesn't
actually need to, so we can trick it into working by mounting an empty
*tmpfs* filesystem there.
2024-05-28 08:25:08 -05:00
Dustin 4c0d5bb473 r/jellyfin: Fix EROFS when starting container
Even with `Network=host`, Podman tries to write to
`/etc/containers/network` for some reason.  Fortunately, it doesn't
actually need to, so we can trick it into working by mounting an empty
*tmpfs* filesystem there.
2024-05-26 12:03:14 -05:00
Dustin 541dd625b5 r/web/hlc: Proxy for Enrollment 2024 form
The summer 2024 enrollment form is more complicated than the other
forms on the HLC site, as it integrates directly with Invoice Ninja.  As
such, it's handled by a different backend, which runs in Kubernetes.
2024-04-02 09:25:47 -05:00
Dustin d9f46d6d62 r/promtail: Optionally run with DAC_READ_SEARCH
The *promtail* service runs as an unprivileged user by default, which is
fine in most cases (i.e. when scraping only the Journal), but may not
always be sufficient to read logs from other files.  Rather than run
Promtail as root in these cases, we can assign it the
CAP_DAC_READ_SEARCH capability, which will allow it to read any file,
but does not grant it any of root's other privileges.

To enable this functionality, the `promtail_dac_read_search` Ansible
variable can be set to `true` for a host or group.  This will create a
systemd unit configuration extension that configures the service to have
the CAP_DAC_READ_SEARCH capability in its ambient set.
2024-02-28 19:00:26 -06:00
Dustin 6645ec36c1 r/dch-yum: Explicitly disable proxy for repo
*unifi1.pyrocufflink.blue* requires a proxy to access Yum repositories
on the Internet, so it has the `proxy` setting configured globally.  The
proxy does NOT allow access to internal resources, however.  The
internal repository is directly accessible by that machine, so it needs
to be configured thus.
2024-02-27 17:42:10 -06:00
Dustin 8c88e58655 r/squid: Send cache log to syslog
The Squid "cache log" is where it writes general debug and error
messages.  It is distinct from the "access log," which is where it
writes the status of every proxy request.  We already had the latter
configured to go to syslog by default (so it would be captured in the
journal), but missed the former.
2024-02-26 08:37:49 -06:00
Dustin 19009bde1a promtail: Role/Playbook to deploy Promtail
Promtail is the log sending client for Grafana Loki.  For traditional
Linux systems, an RPM package is available from upstream, making
installation fairly simple.  Configuration is stored in a YAML file, so
again, it's straightforward to configure via Ansible variables.  Really,
the only interesting step is adding the _promtail_ user, which is
created by the RPM package, to the _systemd-journal_ group, so that
Promtail can read the systemd journal files.
2024-02-22 19:23:31 -06:00
Dustin 19d833cc76 websites/d&t.com: drop obsolete formsubmit config
The *dustinandtabitha.com* website no longer uses *formsubmit* (the time
for RSVP has **long** passed).  Removing the configuration so the
file encrypted with Ansible Vault can go away.
2024-02-22 10:23:19 -06:00
Dustin 4dd2db92a3 r/squid: Add missing private-tmp.conf file 2024-02-22 10:19:25 -06:00
Dustin 18aba01422 r/ssh-user-ca: Add missing handlers file 2024-02-22 10:16:48 -06:00
Dustin 7451026d75 r/collectd: Ignore efivarfs mounts
There's not much point in alerting based on the utilization of this
virtual filesystem.
2024-02-16 20:24:46 -06:00
Dustin 323ffa3426 r/ssh-user-ca: Remove old AuthorizedKeysCommand
A few hosts have `AuthorizedKeysCommand` set in their *sshd(8)*
configuration.  This was my first attempt at centrally managing SSH
keys, using a script which fetched a list of keys for each user from an
HTTP server.  This worked most of the time, but I didn't take good care
of the HTTP server, so the script would fail frequently.  Now that all
hosts trust the SSH user CA, there is no longer any need for this
"feature."
2024-02-01 19:27:52 -06:00
Dustin f83cea50e9 r/ssu-user-ca: Configure sshd TrustedUserCAKeys
The `TrustedUserCAKeys` setting for *sshd(8)* tells the server to accept
any certificates signed by keys listed in the specified file.
The authenticating username has to match one of the principals listed in
the certificate, of course.

This role is applied to all machines, via the `base.yml` playbook.
Certificates issued by the user CA managed by SSHCA will therefore be
trusted everywhere.  This brings us one step closer to eliminating the
dependency on Active Directory/Samba.
2024-02-01 18:46:40 -06:00
Dustin 0d30e54fd5 r/fileserver: Restrict non-administrators to SFTP
Normal users do not need shell access to the file server, and certainly
should not be allowed to e.g. forward ports through it.  Using a `Match`
block, we can apply restrictions to users who do not need administrative
functionality.  In this case, we restrict everyone who is not a member
of the *Server Admins* group in the PYROCUFFLINK AD domain.
2024-02-01 10:29:32 -06:00
Dustin 091d9e1f78 r/sudo: Optionally enable pam_ssh_agent_auth
The [pam_ssh_agent_auth][0] PAM module authenticates users using keys in
their SSH agent.  Using SSH agent forwarding, it can even authenticate
users with keys on a remote system.  By adding it to the PAM stack for
`sudo`, we can configure the latter to authenticate users without
requiring a password.  For servers especially, this is significantly
more secure than configuring `sudo` not to require a password, while
still being almost as convenient.

For this to work, users need to enable SSH agent forwarding on their
clients, and their public keys have to be listed in the
`/etc/security/sudo.authorized_keys` file.  Additionally, although the
documentation suggests otherwise, the `SSH_AUTH_SOCK` environment
variable has to be added to the `env_keep` list in *sudoers(5)*.

[0]: https://github.com/jbeverly/pam_ssh_agent_auth
2024-01-28 12:16:35 -06:00
Dustin 7569c9da0d r/squid: Fix SELinux AVC denial after cache init
Running `squid -z` as *root* leaves behind temporary files in
`/dev/shm`.  When *squid.service* starts squid, in the proper SELinux
domain, it is unable to access these files and crashes.  To avoid this,
we mount a private *tmpfs* so no existing files are accessible in the
service's namespace.
2024-01-27 20:28:06 -06:00
Dustin 541a6385e2 r/squid: Update default config for latest version
At some point, the default `squid.conf` file changed a bit.  Updating
the template to match.
2024-01-27 20:08:16 -06:00
Dustin 1d94dc9528 r/squid: Support custom cache rules
Instead of hard-coding a single cache directory and a set of refresh
patterns, the *squid* role can now have custom cache rules defined with
the `squid_cache_dir` variable (which now takes a list of `cache_dir`
settings) and the `squid_refresh_pattern` variable (which takes a list
of refresh patterns).  If neither of these are defined, the default
configuration is used.

This is a breaking change, since `squid_cache_dir` used to refer to a
directory, and the previous default was to configure one cache path.
There are no extant users of this role, though, so it doesn't really
matter.
2024-01-27 20:05:35 -06:00
Dustin af18a575d1 r/squid: Support custom ACLs and rules
The default set of access control lists and access rules for Squid are
fine for allowing hosts on the local network access to the web in
general.  For other uses, such as web filtering, etc. more complex rules
may be needed.  To that end, the *squid* role now supports some
additional variables.  Notably, `squid_acl` contains a map of ACL names
to list entries and `squid_http_access` contains a list of access rules.
If these are set, their corresponding defaults are not included in the
rendered configuration file.
2024-01-27 19:56:02 -06:00
Dustin 236e6dced6 r/web/hlc: Add formsubmit config for summer signup
And of course, Tabitha lost her SSH key so she had to get another one.
2024-01-23 22:04:29 -06:00
Dustin 5287ff601b r/jellyfin: Enable service auto restart 2024-01-22 20:37:21 -06:00
Dustin 54727e148f r/nut{,-monitor}: Enable nut.target
Recent versions of NUT have a *nut.target* unit that collects all of the
NUT-related services.  Enabling any of the services individually does
effectively nothing, as it only adds the service as a `Wants` dependency
for *nut.target*, and that unit already has dependencies for all of
them. Thus, in order for the service to start at boot, *nut.target* has
to be enabled instead.

In situations where only *nut-monitor* should be enabled, enabling
*nut.target* is inappropriate, since that enables *nut-driver* and
*nut-server* as well. It's not clear why upstream made this change (it
was part of a [HUGE pull request][0]), but restoring the desired
behavior is easy enough by clearing the dependencies from *nut.target*.
Services that we want to start automatically can still be enabled
individually, and will start as long as *nut.target* is enabled.

[0]: https://github.com/networkupstools/nut/pull/330
2024-01-22 09:03:15 -06:00
Dustin 681384872c r/synapse: Increase service startup timeout
The Synapse server can sometimes take a very long time to start.
Increasing the start timeout should keep it from failing to come up when
the machine is under load.
2024-01-21 19:05:00 -06:00
Dustin 55e26a7c81 r/unifi: Increase startup timeout
The UniFi controller service can sometimes take a really long time to
start up.  This most frequently happens after a full outage, when the VM
hosts are very busy bringing everything up.
2024-01-21 16:12:29 -06:00
Dustin bba55b5182 r/unifi: Enable service auto restart
Automatically restart the UniFi service in case it crashes (which it
tends to do quite frequently).
2024-01-21 16:12:29 -06:00
Dustin b4fcbb8095 unifi: Deploy unifi_exporter
`unifi_exporter` provides Prometheus metrics for UniFi controller.
2024-01-21 16:12:29 -06:00
Dustin d5de7131a0 r/vmhost: Remove system call filters from unit
The `vm-autostart` script fails with `bad system call` errors when
trying to start libvirt domains.  Removing the system call filters works
around this.  Ideally, we should figure out exactly which system call is
being rejected and allow it, but that's rather difficult to do and
probably not really worth the effort in this case.
2024-01-21 15:53:44 -06:00
Dustin 823d899e9e r/minio: Start more reliably on boot
The MinIO service often fails to start from a cold boot.  Delaying
starting the service until the network is online, plus increasing the
startup timeout, should help with this.  If not, enabling auto restart
will let systemd try to start the service again if it still fails to
come up on time.
2024-01-21 15:53:33 -06:00
Dustin 525f2b2a04 nut-monitor: Configure upsmon
`upsmon` is the component of [NUT] that monitors (local or remote) UPS
devices and reacts to changes in their state.  Notably, it is
responsible for powering down the system when there is insufficient
power to the system.
2024-01-19 20:50:03 -06:00