Commit Graph

587 Commits (29cdafac2a4b90a8735a167a4a01783d9713b4c8)

Author SHA1 Message Date
Dustin db5d1fb91a unifi: Switch from nginx to Caddy
Mostly for built-in ACME support.
2025-03-16 17:17:00 -05:00
Dustin fbbe86c651 r/unifi: Do not deploy exporter
The _unifi_exporter_ has been broken since several versions of UniFi
Network ago.
2025-03-16 16:40:57 -05:00
Dustin db54b03aa8 r/unifi: Switching to custom container image
The _linuxserver.io_ image for UniFi Network is deprecated.  It sucked
anyway.  I've created a simple image based on Debian that installs the
_unifi_ package from the upstream apt repository.  This image doesn't
require running anything as _root_, so it doesn't need a user namespace.
2025-03-16 16:40:57 -05:00
Dustin c300dc1b6c chrony: Add role/PB for chrony
I continually struggle with machines' (physical and virtual, even the
Roku devices!) clocks getting out of sync.  I have been putting off
fixing this because I wanted to set up a Windows-compatible NTP server
(i.e. on the domain controllers, with Kerberos signing), but there's
really no reason to wait for that to fix the clocks on all the
non-Windows machines, especially since there are exactly 0 Windows
machines on the network right now.

The *chrony* role and corresponding `chrony.yml` playbook are generic,
configured via the `chrony_pools`, `chrony_servers`, and `chrony_allow`
variables.  The values for these variables will configure the firewall
to act as an NTP server, synchronizing with the NTP pool on the
Internet, while all other machines will synchronize with it.  This
allows machines on networks without Internet access to keep their clocks
in sync.
2025-03-16 16:37:19 -05:00
Dustin 164d86d646 r/postgresql-data: Manage users and databases
This role can ensure PostgreSQL users and databases are created for
applications that are not themselves managed by Ansible.  Notably, we
need to do this for anything deployed in Kubernetes that uses the
central database server.
2025-02-01 17:36:58 -06:00
Dustin 878a099752 r/kubelet: Ensure iscsi service is running
The _iscsi.socket_ unit gets enabled by default with the
_iscsi-initiator-utils_ package is installed, but it won't start
automatically until the next boot.  Without this service running,
Longhorn volumes will not be able to attach to the node, so we need to
explicitly ensure it is running before any workloads are assigned to the
node.
2025-01-31 19:01:27 -06:00
Dustin a9a6a30e59 r/{cri-o,kubelet}: Support versioned packages
Fedora 41 introduced versioned package names for Kubernetes components,
including CRI-O.  The intent is to allow multiple versions of Kubernetes
to be available (but not necessarily installed) within a given Fedora
release.  In order to use these packages, we need to set the desired
Kubernetes version, via the new `kubernetes_version` Ansible variable.
2025-01-31 18:57:21 -06:00
Dustin cbc4d29bd6 r/base: Install python3-libdnf5
Fedora 41 uses _dnf5_ by default.  Being written in C, its Python API is
an optional feature that needs to be installed separately.
2025-01-31 18:55:58 -06:00
Dustin a58dbb74c5 r/vmhost: Clean up qemu packages
At some point, the _qemu-kvm_ package became a meta-package that
installs _everything_ QEMU-related.  All drivers, backends, frontends,
etc. get pulled in, which results in a huge amount of wasted space.
Recently, the VM hosts started getting alerts about their `/` filesystem
getting too full, which is how I discovered this.

We can dramatically reduce the disk space footprint by installing only
the "core" package and the drivers we need for our servers.

After making and applying this change, which marks the listed packages
as "leaf" installs, I then manually uninstalled the _qemu-kvm_ package.
This uninstalled everything else that is not specifically listed.
2025-01-28 17:36:35 -06:00
Dustin 3e8ac36f88 r/vmagent: Rework as container deployment
Like the _blackbox-exporter_ role, the _vmagent_ role now deploys
`vmagent` as a container.  This simplifies the process considerably,
eliminating the download/transfer step.

While refactoring this role, I also changed how the trusted CA
certificates are handled.  Rather than copy files, the role now expects
a `vmagent_ca_certs` variable.  This variable is a mapping of
certificate name (file name without extension) to PEM contents.  This
allows certificates to be defined using normal host/group variables.
2025-01-26 13:08:59 -06:00
Dustin dcf1e5adfc r/blackbox-exporter: Rework to run as container
Instead of downloading the `blackbox_exporter` binary from GitHub and
copying it to the managed node, the _blackbox-exporter_ role now
installs _podman_ and configures a systemd container unit (Quadlet) to
run it in a container.  This simplifies the deployment considerably, and
will make updating easier (just run the playbook with `-e
blackbox_exporter_pull_image=true`).
2025-01-26 13:06:54 -06:00
Dustin e51e933661 r/gitea: Serve kickstarts over HTTP
I want to use Gita as the canonical source for Anaconda kickstart
scripts.  There are certain situations, however, where they cannot be
accessed via HTTPS, such as on a Raspberry Pi without an RTC, since it
cannot validate the certificate without the correct time.  Thus, the
web server must not force an HTTPS redirect for these, but serve them
directly.
2024-12-27 10:51:00 -06:00
Dustin a00ffd10df r/jellyfin: Fix system.xml template whitespace
Jellyfin is one of those stupid programs that thinks it needs to mutate
its own config.  At startup, it apparently reads `system.xml` and then
writes it back out.  When it does this, it trims the final newline from
the file.  Then, the next time Ansible runs, the template rewrites the
file with the trailing newline, and thus determines that the file has
changed and restarts the service.  This cycle has been going on for a
while and is rather annoying.
2024-12-12 06:36:23 -06:00
Dustin 15cb675297 r/kubelet: Pass --config arg to service
The systemd unit configuration installed by Fedora's _kubeadm_ package
does not pass the `--config` argument to the kubelet service.  Without
this argument, the kubelet will not read the configuration file
generated by `kubeadm` from the `kubelet-config` ConfigMap.  Thus,
various features will not work correctly, including server TLS
bootstrap.
2024-12-07 09:35:57 -06:00
Dustin 7a5f01f8a3 r/doas: Configure sudo alternative
In the spirit of replacing bloated tools with unnecessary functionality
with smaller, more focused alternatives, we can use `doas` instead of
`sudo`.  Originally, it was a BSD tool, but the Linux port supports PAM,
so we can still use `pam_auth_ssh_agent` for ppasswordless
authentication.
2024-11-24 10:33:21 -06:00
Dustin 0f600b9e6e kubernetes: Manage worker nodes
So far, I have been managing Kubernetes worker nodes with Fedora CoreOS
Ignition, but I have decided to move everything back to Fedora and
Ansible.  I like the idea of an immutable operating system, but the FCOS
implementation is not really what I want.  I like the automated updates,
but that can be accomplished with _dnf-automatic_.  I do _not_ like
giving up control of when to upgrade to the next Fedora release.
Mostly, I never did come up with a good way to manage application-level
configuration on FCOS machines.  None of my experiments (Cue+tmpl,
KCL+etcd+Luci) were successful, which mostly resulted in my manually
managing configuration on nodes individually.  Managing OS-level
configuration is also rather cumbersome, since it requires redeploying
the machine entirely.  Altogether, I just don't think FCOS fits with my
model of managing systems.

This commit introduces a new playbook, `kubernetes.yml`, and a handful of
new roles to manage Kubernetes worker nodes running Fedora Linux.  It
also adds two new deploy scripts, `k8s-worker.sh` and `k8s-longhorn.sh`,
which fully automate the process of bringing up worker nodes.
2024-11-24 10:33:21 -06:00
Dustin 164f3b5e0f r/wal-g-pg: Handle versioned storage locations
The target location for WAL archives and backups saved by WAL-G should
be separated based on the major version of PostgreSQL with which they
are compatible.  This will make it easier to restore those backups,
since they can only be restored into a cluster of the same version.

Unfortunately, WAL-G does not natively handle this.  In fact, it doesn't
really have any way of knowing the version of the PostgreSQL server it
is backing up, at least when it is uploading WAL archives.  Thus, we
have to include the version number in the target path (S3 prefix)
manually.  We can't rely on Ansible to do this, because there is no way
to ensure Ansible runs at the appropriate point during the upgrade
process.  As such, we need to be able to modify the target location as
part of the upgrade, without causing a conflict with Ansible the next
time it runs.

To that end, I've changed how the _wal-g-pg_ role creates the
configuration file for WAL-G.  Instead of rendering directly to
`wal-g.yml`, the role renders a template, `wal-g.yml.in`.  This template
can include a `@PGVERSION@` specifier.  The `wal-g-config` script will
then use `sed` to replace that specifier with the version of PostgreSQL
installed on the server, rendering the final `wal-g.yml`.  This script
is called both by Ansible in a handler after generating the template
configuration, and also as a post-upgrade action by the
`postgresql-upgrade` script.

I originally wanted the `wal-g-config` script to use the version of
PostgreSQL specified in the `PG_VERSION` file within the data directory.
This would ensure that WAL-G always uploads/downloads files for the
matching version.  Unfortunately, this introduced a dependency conflict:
the WAL-G configuration needs to be present before a backup can be
restored, but the data directory is empty until after the backup has
been restored.  Thus, we have to use the installed server version,
rather than the data directory version.  This leaves a small window
where WAL-G may be configured to point to the wrong target if the
`postgresql-upgrade` script fails and thus does not trigger regenerating
the configuration file.  This could result in new WAL archives/backups
being uploaded to the old target location.  These files would be
incompatible with the other files in that location, and could
potentially overwrite existing files.  This is rather unlikely, since
the PostgreSQL server will not start if the _postgresql-upgrade.service_
failed.  The only time it should be possible is if the upgrade fails in
such a way that it leaves an empty but valid data directory, and then
the machine is rebooted.
2024-11-17 10:27:31 -06:00
Dustin e861883627 r/pgsql-server-base: Add post-upgrade capability
The `postgresql-upgrade` script will now run any executables located in
the `/etc/postgresql/post-upgrade.d` directory.  This will allow making
arbitrary changes to the system after a PostgreSQL major version
upgrade.  Notably, we will use this capability to change the WAL-G
configuration to upload WAL archives and backups to the correct
version-specific location.
2024-11-17 10:27:31 -06:00
Dustin 965742d2b0 r/postgresql-server-base: Factor out prep steps
There's a bit of a dependency loop between the _postgresql-server_ role
and other roles that supplement it, like _wal-g-pg_ and
_postgresql-cert_.  The latter roles need PostgreSQL installed, but when
those roles are used, the server cannot be started until they have been
applied.  To resolve this situation, I've broken out the initial
installation steps from the _postgresql-server_ role into
_postgresql-server-base_.  Roles that need PostgreSQL installed, but
need to be applied before the server can start, can depend on this role.
2024-11-17 10:27:31 -06:00
Dustin 53b39338dd r/postgresql-server: Add script to upgrade database
The `postgresql-upgrade.sh` script arranges to run `pg_upgrade` after a
major PostgreSQL version update.  It's scheduled by a systemd unit,
_postgresql-upgrade.service_, which runs only after an OS update.
2024-11-17 10:27:31 -06:00
Dustin 0048a87630 r/postgresql-server: Set become on postgres tasks
Tasks that must run as the _postgres_ user need to explicity enable
`become`, in case it is not already enabled at the playbook level.  This
can happen, for example, when the playbook is running directly as root.
2024-11-16 11:50:28 -06:00
Dustin 6115762847 r/serterm: Deploy serial terminal multiplexer
Using `tmux`, we can spawn a bunch of `picocom` processes for the serial
ports connected to other server's console ports.  The
_serial-terminal-server_ service manages the `tmux` server process,
while the individual _serial-terminal-server-window@.service_ units
create a window in the `tmux` session.

The serial terminal server runs as a dedicated user.  The SSH server is
configured to force this user to connect to the `tmux` session.  This
should help ensure the serial consoles are accessible, even if the
Active Directory server is unavailable.
2024-11-10 13:15:08 -06:00
Dustin 8b9cf1985a r/wal-g-pg: Schedule weekly delete jobs
WAL-G slows down significantly when too many backups are kept.  We need
to periodically clean up old backups to maintain a reasonable level of
performance, and also keep from wasting space with useless old backups.
2024-11-05 19:28:57 -06:00
Dustin eaf9cbef9a Merge remote-tracking branch 'origin/frigate-exporter' 2024-11-05 07:01:31 -06:00
Dustin c1dc52ac29 Merge branch 'loki' 2024-11-05 07:01:13 -06:00
Dustin 39d9985fbd r/loki-caddy: Caddy reverse proxy for Loki
Caddy handles TLS termination for Loki, automatically requesting and
renewing its certificate via ACME.
2024-11-05 06:54:27 -06:00
Dustin 168bfee911 r/webites: Add apps.du5t1n.xyz F-Droid repo
I want to publish the _20125_ Status application to an F-Droid
repository to make it easy for Tabitha to install and update.  F-Droid
repositories are similar to other package repositories: a collection of
packages and some metadata files.  Although there is a fully-fledged
server-side software package that can manage F-Droid repositories, it's
not required: the metadata files can be pre-generated and then hosted by
a static web server just fine.

This commit adds configuration for the web server and reverse proxy to
host the F-Droid repository at _apps.du5t1n.xyz_.
2024-11-05 06:47:02 -06:00
Dustin 7e8aee072e r/bitwarden_rs: Redirect to canonical host name
Bitwarden has not worked correctly for clients using the non-canonical
domain name (i.e. _bitwarden.pyrocufflink.blue_) for quite some time.
This still trips me up occasionally, though, so hopefully adding a
server-side redirect will help.  Eventually, I'll probably remove the
non-canonical name entirely.
2024-11-05 06:37:03 -06:00
Dustin 0807afde57 r/dch-proxy: Use separate sockets for HTTP v4/v6
Although listening on only an IPv6 socket works fine for the HTTP
front-end, it results in HAProxy logging client requests as IPv4-mapped
IPv6 addresses.  For visual processing, this is ok, but it breaks Loki's
`ip` filter.
2024-11-05 06:34:55 -06:00
Dustin 90351ce59e r/dch-proxy: Include host name in log messages
When troubleshooting configuration or connection issues, it will be
helpful to have the value of the HTTP Host header present in log
messages emitted by HAProxy.  This will help reason about HAProxy's
routing decisions.

For TLS connections, of course, we don't have access to the Host header,
but we can use the value of the TLS SNI field.  Note that the requisite
`content set-var` directive MUST come before the `content accept`;
HAProxy stops processing all `tcp-request content ...` directives once
it has encountered a decision.
2024-11-05 06:32:49 -06:00
Dustin 3ca94d2bf4 r/haproxy: Enable Prometheus metrics
HAProxy can export stats in Prometheus format, but this requires
special configuration of a dedicated front-end.  To support this, the
_haproxy_ Ansible role now has a pair of variables,
`haproxy_enable_stats` and `haproxy_stats_port`, which control whether
or not the stats front-end is enabled, and if so, what port it listens
on.  Note that on Fedora with the default SELinux policy, the port must
be labelled either `http_port_t` or `http_cache_port_t`.
2024-11-05 06:23:49 -06:00
Dustin 9f30998fbf r/jellyfin: Enable Prometheus metrics
Jellyfin can expose metrics in Prometheus format, but this functionality
is disabled by default.  To enable it, we must set `EnableMetrics` in
the configuration file.  This commit adds a template configuration file
that uses the `jellyfin_enable_metrics` Ansible variable to control this
value.
2024-11-05 06:21:38 -06:00
Dustin ccf33f90e0 r/frigate-exporter: Deploy Prometheus exporter
Frigate exports useful statistics natively, but in a custom JSON format.
There is a [feature request][0] to add support for Prometheus format,
but it's mostly being ignored.  A community member has created a
standalone process that converts the JSON format into Prometheus format,
though, which we can use.

[0]: https://github.com/blakeblackshear/frigate/issues/2266
2024-10-21 20:27:31 -05:00
Dustin 4cd983d5f4 loki: Add role+playbook for Grafana Loki
The current Grafana Loki server, *loki0.pyrocufflink.blue*, runs Fedora
CoreOS and is managed by Ignition and *cfg*.  Since I have declared
*cfg* a failed experiment, I'm going to re-deploy Loki on a new VM
running Fedora Linux and managed by Ansible.

The *loki* role installs Podman and defines a systemd-managed container
to run Grafana Loki.
2024-10-20 12:10:55 -05:00
Dustin 388fd91096 r/nginx: Configure error/access syslog separately
There may be cases where we want either error logs or access logs to be
sent to syslog, but not both.  To support these, there are now two
variables: `nginx_access_log_syslog` and `nginx_error_log_syslog`.
Both use the value of the `nginx_log_syslog` variable by default, so
existing users of the _nginx_ role will continue to work as before.
2024-10-20 12:10:17 -05:00
Dustin 845911dcbd r/nginx: Make logging to files optional
If _nginx_ is configured to send error/access log messages to syslog, it
may not make sense to _also_ send messages to log files as well.  The
`nginx_error_log_file` and `nginx_access_log_file` variables are now
available to control whether/where to send log messages.  Setting either
of these to a falsy value will disable logging to a file.  A non-empty
string value is interpreted as the path to a log file.  By default, the
existing behavior of logging to `/var/log/nginx/error.log` and
`/var/log/nginx/access.log` is preserved.
2024-10-14 12:00:19 -05:00
Dustin 87b9014721 r/statsd-exporter: Deploy statsd exporter
The *statsd exporter* is a Prometheus exporter that converts statistics
from StatsD format into Prometheus metrics.  It is generally useful as a
bridge between processes that emit event-based statistics, turning them
into Prometheus counters and gauges.
2024-10-13 19:59:52 -05:00
Dustin a22c8aa0d2 r/nextcloud: Configure trashbin retention
Setting the `trashbin_retention_obligation` setting to `auto, 30` should
supposedly delete files in users' trash bins after 30 days.
2024-10-13 18:38:12 -05:00
Dustin 265aa074aa r/nextcloud: Configure Memories app
The [Memories] app for Nextcloud provides a better user interface and
more features than the built-in Photos app.  The latter seems to be
somewhat broken recently (timeline stops in June 2024, even though there
are more recent photos available), so we're trying out Memories (and
Recognize for facial recognition).

[Memories]: https://memories.gallery
2024-10-13 18:36:25 -05:00
Dustin 5ab0bcd5bf r/nextcloud: Update rewrite config for .mjs files
Nextcloud 28+ uses JavaScript modules (`.mjs` files).  These need to be
served from the filesystem like other static files, so the *mod_rewrite*
configuration needs to be updated as such.
2024-10-13 18:35:01 -05:00
Dustin 1e6ab546bc r/vmhost: Create directory for console logs
Need a directory where _libvirt_ can write logs from VM serial console
output.
2024-10-13 18:30:04 -05:00
Dustin 219fe75424 r/nginx: logrotate: do not delay compressing
_nginx_ access logs are typically either very small or very large.  For
small log files, it's fast enough to decompress them on the fly if
necessary.  For large files, they may take up so much space in
uncompressed form that the log volume fills too quickly.  In either
case, compressing the files as soon as they are rotated is a good
option, especially since their contents should already be sent to Loki.
2024-09-30 12:43:25 -05:00
Dustin 829c04332d r/nginx: Configure logrotate
The default `logrotate` configuration for _nginx_ may not be appropriate
for high-volume servers.  The `nginx_keep_num_logs` variable is now
available to control how many days of logs are kept.
2024-09-29 11:20:29 -05:00
Dustin 9e610eaf11 r/minio-backups-cert: Enable/start cerbot timer
Forgot to ensure the _certbot-renew.timer_ unit was enabled and started,
so the MinIO certificate did not get renewed the first time.
2024-09-08 09:15:36 -05:00
Dustin 7d93ba836e r/restic: Enhance restic-backup security sandbox
Since `restic` needs to run as root in order to back up files regardless
of their permissions, we need to restrict it to doing only that.  Using
systemd sandbox features, especially the capability bounding set, we can
remove all of _root_'s powers except the ability to read all files.
2024-09-04 17:43:24 -05:00
Dustin 0f4dea9007 restic: Add role+playbook for Restic backups
The `restic.yml` playbook applies the _restic_ role to hosts in the
_restic_ group.  The _restic_ role installs `restic` and creates a
systemd timer and service unit to run `restic backup` every day.

Restic doesn't really have a configuration file; all its settings are
controlled either by environment variables or command-line options. Some
options, such as the list of files to include in or exclude from
backups, take paths to files containing the values.  We can make use of
these to provide some configurability via Ansible variables.  The
`restic_env` variable is a map of environment variables and values to
set for `restic`.  The `restic_include` and `restic_exclude` variables
are lists of paths/patterns to include and exclude, respectively.
Finally, the `restic_password` variable contains the password to decrypt
the repository contents.  The password is written to a file and exposed
to the _restic-backup.service_ unit using [systemd credentials][0].

When using S3 or a compatible service for respository storage, Restic of
course needs authentication credentials.  These can be set using the
`restic_aws_credentials` variable.  If this variable is defined, it
should be a map containing the`aws_access_key_id` and
`aws_secret_access_key` keys, which will be written to an AWS shared
credentials file.  This file is then exposed to the
_restic-backup.service_ unit using [systemd credentials][0].

[0]: https://systemd.io/CREDENTIALS/
2024-09-04 09:40:29 -05:00
Dustin 6f9cd7e4af r/postgres-exporter: Do not connect to tempate1 DB
It turns out, having the exporter connect to the _template1_ database is
not a great idea.  PostgreSQL does not allow creating a new database if
the template database is currently being accessed by any clients.  Since
_template1_ is the default choice, the `createdb` command will probably
fail.

It doesn't specifically matter which database the exporter connects to,
since it reads most (all?) of its data from the PostgreSQL catalog,
which isn't database-specific.
2024-09-02 21:15:23 -05:00
Dustin 22dbc3ebc1 r/nextcloud-db-cert: Fetch client cert from k8s
Currently, the certificate authority that issues certificates for
PostgreSQL clients is hosted in Kubernetes and managed by
_cert-manager_.  Certificates it issues are stored in Kubernetes Secret
resources, making them easy to consume by applications running in the
cluster, but not for anything outside.  Since Nextcloud runs on its own
VM, we need a way to get the certificate out of the Secret and into a
file on that machine.  To that end, I've written the
`nextcloud-fetch-cert.py` script.  This script uses a Kubernetes Service
Account token to authenticate to the Kubernetes API and download the
contents of the Secret.  It runs periodically, triggered by a systemd
timer unit, to ensure the certificate is always up-to-date.

The obvious drawback to this approach is the requirement for a static
token.  Since there's not really a way to "renew" Service Account
tokens, it needs to be issued with a fairly long duration, to mitigate
the risk of being unable to fetch a new certificate once it has expired
because the token has also expired.  This somewhat negates the advantage
of using certificates for authentication, since now the machine needs a
static, pre-defined secret.

At some point, I may deploy another instance of _step-ca_ to manage the
PostgreSQL client CA.  Clients can then use e.g. `certbot` or `step ca
certificate` to obtain their certificates.  I chose not to implement
this yet, though for a couple of reasons.  First, I need to move the
Nextcloud database very soon, so we switch to using `restic` for backups
without having to deal with the database.  Second, I am still
considering moving Nextcloud into Kubernetes eventually, where it will
be able to get the Secret directly; since Nextcloud is the only client
outside the cluster, it may not be worth setting up _step-ca_ in that
case.
2024-09-02 20:35:32 -05:00
Dustin 924107abbe nextcloud: Support remote database server
The _nextcloud_ role originally handled setting up the PostgreSQL
database and assumed that it was running on the same server as Nextcloud
itself.  I have factored out those tasks into their own role,
_nextcloud-db_, which can be applied to a separate host.

I have also introduced some new variables (`nextcloud_db_host`,
`nextcloud_db_name`, `nextcloud_db_user`, and `nextcloud_db_password`),
which can be used to specify how to connect to the database, if it is
hosted remotely.  Since these variables are used by both the _nextcloud_
and _nextcloud-db_ roles, they are actually defined in a separate role,
_nextcloud-base_, upon which both depend.
2024-09-02 20:29:51 -05:00
Dustin 226232414f r/jellyfin: Fix HAProxy vhost
Without including the settings from `ssl.include`, the virtual host
bound to port 8443 expects to handle plain HTTP traffic, rather than
HTTPS.
2024-09-01 17:33:22 -05:00
Dustin e4766e54ac r/dch-proxy: Use separate sockets for IPv4/IPv6
When HAProxy binds to the IPv6 socket, it can handle both IPv6 and IPv4
clients.  IPv4 clients are handled as IPv4-mapped IPv6 addresses, which
some backends (i.e. Apache) cannot support.  To avoid this, we configure
HAProxy to bind to the IPv4 and IPv6 sockets separately, so that IPv4
addresses are handled as IPv4 addresses.
2024-09-01 12:43:22 -05:00
Dustin 921a12cf1f r/jellyfin: Add virtual host for HAProxy
Expose a virtual host on a separate TCP port that uses the PROXY
protocol.  This way, HAProxy can pass the original client IP address to
Jellyfin without terminating the TLS connection.
2024-09-01 12:40:20 -05:00
Dustin 2864a4185c r/jellyfin: Mount LDAP CA certificate in container
In order to enable authentication using LDAP over TLS in Jellyfin, we
need to expose the CA certificate that issues the LDAP server
certificates to the container.
2024-09-01 12:39:14 -05:00
Dustin db74e9ac3f btop: Install btop and run it on the console
`btop` is so much better than `top`.  It makes a really nice status
indicator for machine health, so I like running it on tty1.
2024-09-01 09:24:53 -05:00
Dustin 77ce7aa5e7 r/minio-backups-cert: Certbot for MinIO+nginx
The MinIO server for backups has special requirements for HTTPS.  I want
to use subdomains for bucket names, so the certificate must have a
wildcard name, which requires using the DNS-01 challenge.  Fortunately,
it is actually pretty easy to use `nsupdate` with GSS-TSIG
authentication to automate DNS record creation, and by default, all
domain-member machines can create any records.  Thus, using the `manual`
auth plugin for `certbot` and a script to run `nsupdate`, obtaining the
wildcard certificate is fairly straightforward.

The biggest issue I encountered while developing this feature was
caching of NXDOMAIN responses.  There doesn't seem to be a way to change
the TTL of the SOA record of the Active Directory DNS domain, which
defaults to 3600, meaning NXDOMAIN responses are always cached for an
hour.  When adding a record using `nsupdate -g`, the tool always
performs a SOA lookup of new name to find the target zone for it.  Since
the name does not exist yet, the domain controller responds with
NXDOMAIN, which gets cached by the main DNS server.  Thus, even after
adding the record, the ACME server will not be able to resolve the
name for up to an hour.  We can a void this by explicitly setting the
target zone.  That would not work in a multi-domain forest, but
fortunately, we do not have to worry about that.

This role borrows some logic from the *postgresql-cert* role.
Eventually, I probably want to combine some of the steps from both of
these roles, possibly replacing the old *certbot* role.
2024-09-01 08:59:28 -05:00
Dustin 7854a729b7 r/minio: Add option to disable firewall rules
If MinIO is behind a reverse proxy, we do not want to expose it directly
to the network.
2024-09-01 08:59:28 -05:00
Dustin 3c907d0a16 r/minio-nginx: Reverse proxy for MinIO
The *minio-nginx* role configures nginx to proxy for MinIO.  It uses the
"subdomain" pattern, as described in [Configure NGINX Proxy for MinIO
Server][0]; the S3 API and the console UI are accessible through
different domain names.

[0]: https://min.io/docs/minio/linux/integrations/setup-nginx-proxy-with-minio.html
2024-09-01 08:59:28 -05:00
Dustin 7ec7cad26a r/minio: Update container unit for Podman 5
Modern versions of Podman use Netavark, which needs to write various
files on the host file system (even when the container uses the
host's network namespace).
2024-09-01 08:59:28 -05:00
Dustin 623f652e0d r/minio: Add additional configuration options
If the `minio_address` variable is specified, it will be passed with the
`--address` argument to `minio server`.  This allows controlling the
socket the server binds to and listens on.

The `minio_browser_redirect_url` can be specified to populate the
similarly-named environment variable, which configures how MinIO serves
the web UI.

The `minio_domain` variable sets the `MINIO_DOMAIN` environment
variable, which enables DNS names (subdomains) for buckets, i.e.
`{bucket_name}.{MINIO_DOMAIN}`.
2024-09-01 08:59:28 -05:00
Dustin 2e37fce4f6 r/wal-g-pg: Run wal-g backup as postgres
`wal-g` needs to connect to the PostgreSQL database system, so it should
run as the _postgres_ user, who has permission to connect, rather than
_root_, who does not.
2024-08-30 09:44:43 -05:00
Dustin ab5da58175 r/frigate: Add Frigate RTSP port to firewall
Home Assistant streams camera videos via RTSP now.
2024-08-28 09:50:36 -05:00
Dustin 3511176c31 r/gitea: Configure SMTP mailer
Gitea needs SMTP configuration in order to send e-mail notifications
about e.g. pull requests.  The `gitea_smtp` variable can be defined to
enable this feature.
2024-08-25 08:46:37 -05:00
Dustin 1ab0dd3457 r/gitea: Set WORK_DIR in config
Gitea complains if the `WORK_DIR` setting is not set.  It tries to set
it itself, but fails because the configuration is read-only.  The value
it uses is incorrect anyway (`/usr/local/bin`, since that's where the
`gitea` executable is).
2024-08-25 08:45:29 -05:00
Dustin 710a8686fe r/gitea: Update LFS config syntax 2024-08-25 08:45:23 -05:00
Dustin 85da487cb8 r/dch-proxy: Define sites declaratively
I've already made a couple of mistakes keeping the HTTP and HTTPS rules
in sync.  Let's define the sites declaratively and derive the HAProxy
rules from the data, rather then manually type the rules.
2024-08-24 11:48:45 -05:00
Dustin 2fa28dfa5f r/dch-proxy: Update and clean up
The *dch-proxy* role has not been used for quite some time.  The web
server has been handling the reerse proxy functionality, in addition to
hosting websites.  The drawback to using Apache as the reverse proxy,
though, is that it operates in TLS-terminating mode, so it needs to have
the correct certificate for every site and application it proxies for.
This is becoming cumbersome, especially now that there are several sites
that do not use the _pyrocufflink.net_ wildcard certificate.  Notably,
Tabitha's _hatchlearningcenter.org_ is problematic because although the
main site are hosted by the web server, the Invoice Ninja client portal
is hosted in Kubernetes.

Switching back to HAProxy to provide the reverse proxy functionality
will eliminate the need to have the server certificate both on the
backend and on the reverse proxy, as it can operate in TLS-passthrough
mode.  The main reason I stopped using HAProxy in the first place was
because when using TLS-passthrough mode, the original source IP address
is lost.  Fortunately, HAProxy and Apache can both be configured to use
the PROXY protocol, which provides a mechanism for communicating the
original IP address while still passing through the TLS connection
unmodified.  This is particularly important for Nextcloud because of its
built-in intrusion prevention; without knowing the actual source IP
address, it blocks _everyone_, since all connections appear to come from
the reverse proxy's IP address.

Combining TLS-passthrough mode with the PROXY protocol resolves both the
certificate management issue and the source IP address issue.

I've cleaned up the _dch-proxy_ role quite a bit in this commit.
Notably, I consolidated all the backend and frontend definitions into a
single file; it didn't really make sense to have them all separate,
since they were managed by the same role and referred to each other.  Of
course, I had to update the backends to match the currently-deployed
applications as well.
2024-08-24 11:46:28 -05:00
Dustin 5376253c9a r/vmhost: Ensure vm-autostart waits for NFS mount
If _vm-autostart.service_ starts before `/var/lib/libvirt/images` has
been mounted, starting (some) virtual machines may fail.
2024-08-23 09:33:29 -05:00
Dustin 0e46599fbc r/postfix: Support rewriting recipient addresses
The *postfix* role will now generate configuration and a lookup table
for [canonical address mapping][0] of email recipients.  To configure
the mapping, the `postfix_recipient_canonical_map` must be a dictionary
of source-target addresses, e.g.:

```yaml
postfix_recipient_canonical_map:
  my.bad.email@fake.test: my.real.email@example.com
```

[0]: https://www.postfix.org/ADDRESS_REWRITING_README.html#canonical
2024-08-22 16:17:00 -05:00
Dustin d7a271de20 Merge branch 'feature/redeploy-frigate' 2024-08-14 20:30:48 -05:00
Dustin 0ec9401c6e r/squid: Support configuring auth_param
The `auth_param` directive is used to configure proxy authentication
helpers.
2024-08-14 20:26:11 -05:00
Dustin 27b172f083 r/system-auth: skip session winbind for local users
If winbind is unable to communicate with any domain controller, the
`pam_winbind.so` module will time out.  In _auth_ and _account_ context,
this was not an issue, at least for local users, because other modules
terminated the stack before `pam_winbind.so` was called.  In _session_
context, though, nothing terminated the stack at all, so
`pam_winbind.so` was called unconditionally.  This prevented even _root_
from logging in on the console.  This made troubleshooting difficult,
especially for the VM hosts, when the domain controllers were down.
2024-08-13 21:04:42 -05:00
Dustin 34fcaa52ef r/frigate: Increase service startup timeout
Starting the Frigate container can take quite some time, since `podman`
needs to check permissions/SELinux labels for the entire media volume.
2024-08-12 22:22:50 -05:00
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