Staging deployment¶
A staging deployment is a third clone of this repository, built from the repository alone onto the smallest server Hetzner sells, seeded with synthetic data, and destroyed again when the round is over. It exists for one reason: nothing is switched on a live deployment without a full rehearsal on staging. A new role, a replaced service, a migration of the directory or of the mail stack – each is deployed on staging first, run through the checklist at the end of this chapter, and only then on a live host. Rollback is rehearsed there too, because a rollback that has never been run is a plan, not a procedure.
The rules that follow from that purpose:
The smallest server (
cax11, 2 vCPU, 4 GB, arm64), no storage box, no Hetzner snapshots. Staging holds nothing worth paying to keep.Synthetic data only. No member directory, no mail archive and no backup of a live host is ever restored onto it;
seed-test-data.ymlcreates what the checklist needs.Destroyed between rounds. A staging host that lives on becomes a second production host nobody looks after. What survives a round is the clone on the control machine with its tfvars and
host_vars.Nothing of it is committed. Everything that makes the clone a staging deployment is in files the repository already ignores.
A project and a zone of its own¶
A second deployment cannot share the Hetzner project of the first.
tf/main.tf names the server compact-1, the firewalls icmp,
ssh, mail and http+https, and the SSH keys after the files in
tf/ssh-keys/; tf/dns.tf owns the zone. All of these names are unique
per project, so a second apply inside the same project collides with the
first on every one of them – or, worse, with a shared state file, adopts and
rebuilds the live server. Staging therefore gets its own Hetzner project
(ae-staging, say), its own API token, its own state file and its own zone.
The zone is a child of the live deployment’s zone, staging.example.com
below example.com, and the parent has to delegate it: an NS record set at
the label staging in the parent zone tells every resolver to ask the
child zone’s name servers for everything below it. That is what the
delegated_subzones variable in tf/variables.tf of the parent
deployment is for (see the section „Delegated sub-zones“ of the
Terraform chapter). The values are the name servers
Hetzner assigned to the child zone, and those exist only once the child zone
does, so the order is: apply staging first, read its name servers, then apply
the parent.
Before the first apply, look in the parent zone for a record that was made by
hand at the label staging – an old test site, for instance. Terraform
does not know about it, the plan looks clean, and an NS set next to an A
record at the same name is nothing to find out about on the live zone. Delete
or move it first.
The staging clone¶
Next to the clones of the live deployments:
cd ~/projects/ae
git clone ../windsbraut staging # origin = the reference clone, ff only
cd staging/tf
mkdir ssh-keys && cp ../../windsbraut/tf/ssh-keys/*.pub ssh-keys/
Replace windsbraut with whatever your reference clone is called. The
staging clone never gets commits of its own; it is fast-forwarded to the
branch under test and otherwise left alone.
tf/secrets.auto.tfvars holds the token of the new project, created in the
Console under „Security“, „API tokens“, with read and write permissions:
hcloud_token = "..."
tf/config.auto.tfvars describes the machine and the zone:
domain_name = "staging.example.com"
server_type = "cax11"
server_location = "fsn1"
server_backups = false
server_image = "debian-13"
dmarc_policy = "v=DMARC1; p=none;"
service_hosts = { mattermost = null }
server_backups turns the daily snapshots off (20% of the server price,
for a host with nothing on it). server_image is debian-13 because a
fresh deployment has no reason to build from bookworm and dist-upgrade; the
live hosts have to keep debian-12 because the attribute is immutable, as
the variable explains. dmarc_policy stays at p=none so that a test
message which fails alignment is reported, not dropped, while the setup is
being debugged. service_hosts drops the names of roles staging does not
run, mattermost = null as on the live deployments. A name that stays
published for a role in ae_disabled_roles – office.cloud for
collabora, say – only resolves to a server that has no vhost for it, which
is harmless; add collabora = null if the zone should say what runs. Both
*.auto.tfvars files are gitignored.
Then, in tf/:
tofu init
tofu apply
The apply creates the zone, the server, the firewalls, the records, the
reverse DNS entries and ansible/hosts.ini. Now read the name servers of
the new zone. They are in the state:
tofu state show hcloud_zone.zone
prints an authoritative_nameservers block whose assigned list is the
set to delegate to; the Console shows the same three names on the zone’s
overview page. Put them, fully qualified with the trailing dot, into
delegated_subzones in the parent clone’s tf/config.auto.tfvars:
delegated_subzones = {
staging = [
"hydrogen.ns.hetzner.com.",
"oxygen.ns.hetzner.com.",
"helium.ns.hetzner.de.",
]
}
and tofu apply there – the plan contains exactly one new NS record set
and nothing else. Check both sides afterwards:
dig NS staging.example.com
dig A mail.staging.example.com
The first has to return the three names, the second the server’s address. Do not run the playbook before both do: Caddy requests a Let’s Encrypt certificate for every vhost the moment it starts, and a name that does not resolve yet fails the challenge and is retried against a rate limit (see The order of the first run).
Port 25 on first boot¶
Hetzner blocks outbound port 25 on new accounts until the block is lifted on request; a new project inside an established account is not supposed to be affected, but that is a thing to know before the mail stack is deployed, not after the first test message sits in the queue. Log in once the server is up and try a real MX:
ssh root@mail.staging.example.com nc -zv -w5 gmail-smtp-in.l.google.com 25
succeeded or open means outbound mail will work. A timeout means the
block is in place; ask Hetzner support to lift it for the project before
going on, since half of the mail checklist depends on it. Should the image
ship without nc, bash alone does the same:
timeout 5 bash -c 'cat </dev/null >/dev/tcp/gmail-smtp-in.l.google.com/25' && echo open
host_vars¶
ansible/host_vars/compact-1.yml of the staging clone (the host is called
compact-1 in every deployment, which is why nothing host-specific may ever
be copied between clones):
ae_caddy_serve_apex: false
ae_disabled_roles:
- backup
- mounts
- mattermost
- website
- collabora # re-enable only for a round that tests the office
- blackbox-exporter
ae_swap_size: "4G"
ae_lldap_mail_operators:
- "test1" # a seed person; see below for when it takes effect
ae_caddy_serve_apex: false because nothing points at the bare
staging.example.com and a placeholder site there would only cost a
certificate. backup and mounts need a storage box staging does not
have; mattermost and website are not part of every deployment and
have nothing to do with the switches being rehearsed; collabora is
memory this server does not have; blackbox-exporter probes names from the
outside that a throwaway host has no business alerting about.
ae_swap_size is what makes the full stack fit into 4 GB: the swap
role does nothing unless a host sets it, and with it creates and enables
/swapfile before the first container starts.
ae_lldap_mail_operators has to name somebody because the lldap role
refuses an empty list: a mail domain without a postmaster is not one. On a
fresh host, though, no person exists when the role first runs – setup.yml
comes before seed-test-data.yml and creates only service accounts – and
the role adds the uid to the operator groups without checking LLDAP’s answer,
so a uid that does not exist yet is silently not added and postmaster@,
abuse@ and the other operator aliases end up without a member. Name a
seed person (test1 is the one the seed makes an application administrator
anyway) and, once the seed has run, run the lldap role once more so that the
membership is actually made:
ansible-playbook -i hosts.ini setup.yml --tags lldap </dev/null
The alternative is to create the operator account by hand at
auth.staging.example.com before the first full run; the second lldap run
is the one that needs no clicking.
The seam role takes its branding from files under
ansible/files/compact-1/, named by ae_seam_logo and
ae_seam_favicon in the parent deployment’s host_vars. Copy the two
image files – seam-logo.png and seam-favicon.png in the reference
deployment – into the same directory of the staging clone and carry the two
variables over; they are branding, not secrets, and without them seam simply
shows its own logo. Nothing else from the parent’s host_vars or
files/ belongs on staging: the Borg repository settings and the CIFS
mounts are exactly what it must not have.
The run¶
In ansible/ of the staging clone:
make collections
ansible-playbook -i hosts.ini setup.yml --check </dev/null
ansible-playbook -i hosts.ini setup.yml </dev/null
ansible-playbook -i hosts.ini seed-test-data.yml \
-e confirm_domain=staging.example.com </dev/null
ansible-playbook -i hosts.ini setup.yml --tags lldap </dev/null
The dry run is known to stop at the lldap and unbound roles – the
directory tasks query a service that does not exist yet and check mode cannot
answer for it – and that is as far as it is expected to get on a fresh host.
What it does cover is the foundation: the swap file, the podman installation
on trixie, Caddy and PostgreSQL. </dev/null keeps Ansible from treating
the terminal as stdin.
The full run ends with the rspamd role writing tf/dkim.tf; a second
tofu apply in the staging clone then publishes the DKIM records, as in
every first deployment.
seed-test-data.yml fills the empty host with what the checklist asks
about: five test persons in LLDAP, two aliases and a shared mailbox, a
mailing list test@ with two members and an owner, a personal Sieve rule,
three files in every person’s Nextcloud and twenty messages through the
submission port, one of them carrying the GTUBE string. Two guards keep it
off a live host: -e confirm_domain has to equal the host’s ae_domain,
and that domain has to contain staging. The playbook refuses --check
altogether; each section carries a tag (persons, aliases,
mailman, sieve, nextcloud, mail) and can be repeated alone
with --tags. Everything but the mail is idempotent; the messages are sent
again on every run. The persons‘ passwords come from the password lookup and
land in ansible/compact-1/ next to the other generated secrets, so a
rebuilt host gets the same ones. The last line is the second lldap run from
above, which puts test1 into the operator groups now that the person
exists.
If the host runs out of memory¶
A cax11 with 4 GB of swap carries the mail stack, Nextcloud and the three
Django applications, but not with room to spare. If journalctl -k shows
OOM kills, step up to cax21 by changing server_type in the staging
tfvars and applying: the attribute is not ForceNew, Hetzner resizes the
server in place (it is powered off for the resize, which on staging costs
nothing). Prefer that to disabling more roles – a staging host that runs
less than the live hosts rehearses less – and leave
ae_nextcloud_php_memory_limit at its default, because the point is to see
the live configuration under load, not a trimmed one.
Teardown¶
When the round is over:
cd ~/projects/ae/staging/tf
tofu destroy
tofu state list # expect: nothing, or only the zone
rm -f dkim.tf
cd ../ansible
make clean
Two guards in the configuration stand in the way of tofu destroy, both on
purpose, both aimed at the live deployments:
hcloud_server.compact-1carriesprevent_destroy = trueintf/main.tf, and a lifecycle argument cannot be driven by a variable. In the staging clone, remove that line before the destroy and restore it afterwards (git checkout -- tf/main.tf). The edit is local to the staging clone and is never committed.hcloud_zone.zonehasdelete_protection = true. The zone is worth keeping between rounds: it costs nothing, and as long as it exists its name servers, and with them the parent’sdelegated_subzonesentry, stay valid, so the next round needs no second apply on the live deployment. Left as it is, the destroy is expected to fail on the zone and the zone alone, with everything else gone and the nexttofu applybuilding the server and the records back into it. That has not been watched through yet: OpenTofu stops scheduling new operations after the first error and the firewalls and SSH keys are only deleted after the server, so a first destroy may leave some of them behind – hence thetofu state list, and a secondtofu destroyif anything but the zone is listed. The cleaner form istofu destroy -exclude=hcloud_zone.zone, which never attempts the zone; it also skips the record sets, which depend on the zone, and leaves them in the state pointing at the old address until the next apply rewrites them. Which of the two to document as the default is a question for the first teardown. To remove the project’s last resource instead, lift the protection in the Console, or set the attribute tofalselocally, apply, then destroy – and remember that the parent’s delegation then points at name servers that no longer answer for the label.
make clean deletes ansible/compact-1/ and ansible/hosts.ini: the
generated secrets, the seed persons‘ passwords and the inventory all describe
a server that no longer exists, and the next apply and run create fresh ones.
tf/dkim.tf is in the same position – the rspamd role wrote it from the
destroyed host’s keys, and the rebuilt host generates new ones – but
make clean does not know about it; left in place, the first apply of the
next round publishes the old keys under the same selectors until the role has
rewritten the file and the second apply corrects the records. Keep the clone,
tf/secrets.auto.tfvars, tf/config.auto.tfvars, tf/ssh-keys/ and
ansible/host_vars/compact-1.yml; they are the whole of what makes the
next round a one-command rebuild. The server’s SSH host key changes with
every rebuild, so expect to clear the old one from ~/.ssh/known_hosts.
Test checklist¶
Run on staging before every live switch, and on each live host after it. The list covers what the repository deploys today; a migration that replaces one of these services brings its own lines with it when it lands.
Logins¶
Nextcloud web login as a test person and as
test1; the seeded files are visible, the user id is the same as before the switch (no orphaned home directory).Grafana login as
test1, admin role from the group mapping.Mailman Postorius login, the list owner sees the list; the Hyperkitty archive shows the seeded posts.
Seam, knutt and bokstaever logins (website only where it runs).
fail2ban bans after five wrong logins on the authentication path.
Mail¶
IMAPS on 993 with Thunderbird and one mobile client (K-9 or iOS Mail); IMAP on 143 is refused from the outside.
Submission on 587 to an external address (a test mailbox at a large provider): DKIM, SPF and DMARC all pass in the received headers.
Inbound from outside to a person, to an alias and to the shared mailbox.
Shared mailbox login as
user/shared.Mailman: a member’s post goes through, a non-member’s is rejected or held, the digest is sent, From munging and ARC sealing as configured.
The seeded Sieve rule still files the list’s mail after the switch.
Spam: a message with the GTUBE string is rejected or filed into Junk.
Roundcube login, send, address book lookup.
Autoconfig, autodiscover and the MTA-STS policy are still served.
Platform¶
All
ae-*units active, no failed units,podman psmatches whatsetup.ymldeploys on this host.Backups (live hosts only): the first hourly borg run after the switch succeeds.
The Grafana mail volume, queue and DMARC panels are still populated after 24 hours.
No OOM kills in
journalctl -kwithin 24 hours.