Files
loki/.github/workflows/mailgate.yml
CatoandClaude 48b0dc04cc feat(mailgate): every app host receives mail at hello@, delivered signed to the app (#1412)
loki-mailgate is the receiving half of the fleet email standard: one
public address per app on its own host (hello@<app host>), no mail server
or mailbox per app.

- Receive-only SMTP on :25 (smtp-server). Routes by apps.conf (Loki's live
  copy, refreshed by every deploy, plus the one installed beside it), so a
  new site gets mail after the next deploy with no step here. Accepts only
  hello@, postmaster@ and abuse@; refuses everything else at SMTP time, so
  it never bounces and cannot relay.
- SPF / DKIM / DMARC checked (mailauth); failures are marked, not dropped.
- Spooled to disk before "250", then POSTed to
  http://127.0.0.1:<port>/api/mail/inbound signed with the fleet key
  MAIL_INBOUND_SECRET (mail-kit 0.2 inbound contract), retried with backoff
  until the app says 2xx. Delivered mail is pruned after 14 days: the app's
  own retention governs its copy.
- Bundled to one file; a systemd unit with CAP_NET_BIND_SERVICE as ubuntu,
  ProtectSystem=strict; install-mailgate.sh creates the secret and its own
  STARTTLS key and opens 25/tcp; the manual Mailgate workflow tests,
  bundles and installs. test:mailgate joins verify.

Checked end to end against the bundle: hello@skif accepted and delivered
with a valid signature; another mailbox and an unknown host refused 550.


Claude-Session: https://claude.ai/code/session_01TTH5cy8bKmEqzdTyAsbbT8

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-22 18:46:06 +02:00

52 lines
1.8 KiB
YAML

name: Mailgate
# Build and install loki-mailgate on the box: mail to hello@<any app host> is
# received, checked (SPF/DKIM/DMARC) and delivered signed to the app
# (mailgate/README.md). Also refreshes its copy of the app register, so run it
# after a site is added. Manual on purpose: it opens a port and runs a service.
on:
workflow_dispatch: {}
permissions:
contents: read
concurrency:
group: deploy-prod
cancel-in-progress: false
jobs:
install:
runs-on: ubuntu-latest
timeout-minutes: 15
env:
HETZNER_IP: ${{ vars.HETZNER_IP }}
steps:
- uses: actions/checkout@v7
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
- name: Build the bundle
run: |
pnpm install --frozen-lockfile --filter loki-mailgate...
pnpm -C mailgate test
pnpm -C mailgate bundle
- name: SSH setup
run: |
mkdir -p ~/.ssh
printf '%s\n' "${{ secrets.HETZNER_SSH_KEY }}" > ~/.ssh/id_deploy
chmod 600 ~/.ssh/id_deploy
ssh-keyscan -H "$HETZNER_IP" >> ~/.ssh/known_hosts 2>/dev/null
- name: Install on the box
run: |
set -euo pipefail
BOX="ubuntu@$HETZNER_IP"
SSH="ssh -o BatchMode=yes -i $HOME/.ssh/id_deploy"
$SSH "$BOX" 'sudo mkdir -p /opt/mailgate/install && sudo chown ubuntu:ubuntu /opt/mailgate /opt/mailgate/install'
scp -q -o BatchMode=yes -i ~/.ssh/id_deploy \
mailgate/dist/mailgate.mjs mailgate/loki-mailgate.service scripts/hetzner/apps.conf \
scripts/hetzner/install-mailgate.sh scripts/hetzner/fleet-env.sh scripts/hetzner/fleet-keys.conf \
"$BOX:/opt/mailgate/install/"
$SSH "$BOX" 'bash /opt/mailgate/install/install-mailgate.sh'