Files
jcoffey-dev c9245077fa Phase 2: the console and the webmail on the host
--console host and --webmail host install them without containers, from
their releases' tarballs (inbuxa-admin #106, inbuxa-webmail #68), each
checked against a checksum pinned in internal/release.

- The console is files: unpacked into <dir>/console, root-owned and
  readable, and pointed at the server the way its image's entrypoint does
  (the api-base-url meta tag). The managed Caddy serves the directory,
  mounted read-only, or the operator's web server does from the
  configuration --proxy snippets writes; both with the image's rules (app
  routes fall back to index.html, hashed assets cached for good, index.html
  never). With --local or --proxy none nothing would serve it, and the
  plan says so.
- The webmail is the /app its image runs, in <dir>/webmail, owned by root,
  under inbuxa-webmail.service as its own user on the installer's own Node
  (now 26, as its image) in /opt/inbuxa/node, on 127.0.0.1:8080, with the
  container's environment in <dir>/webmail.env. It can't write its own
  files, which is what its IMMUTABLE setting checks. The unit is
  ProtectSystem=strict. A server in a container is reached at its loopback
  port and sees it at the project network's gateway, which is what gets
  exempted from the auto-ban.
- Both unpack beside the old copy and swap only when complete; a re-run
  skips an unchanged release and restarts the webmail only when what it
  reads at start changed. A webmail moved back into a container gives its
  port back first. status and export report them as host.

With all three on the host and --proxy snippets, no container runtime is
installed. The release pins are empty until those releases exist, and the
host shapes say so; INBUXA_CONSOLE_TARBALL and INBUXA_WEBMAIL_TARBALL (and
CONSOLE_TARBALL=, WEBMAIL_TARBALL= in e2e/vm/run.sh) install a local
tarball meanwhile.

Also: the "using docker" line no longer prints when nothing runs in a
container; Verify takes the plan's options and checks a host console by
its files.

Tests: plan (console host needs a web server; host front ends wait for
their releases; the webmail wants the installer's own Node), compose
(console files, the webmail unit, Caddy on the host's network, the
gateway exemption, nginx serving the directory), apply (api-base-url
replaced or inserted, the webmail's environment, unpack's swap and
marker). e2e: webmail-host.sh 18/18 (signing in included), all-host.sh
17/17 (no runtime, behind nginx), both with tarballs taken out of the
current images as the release jobs will; install-local, install-host,
install-public, proxy-snippets, interface, status-export and topology
pass unchanged.
2026-10-12 11:26:03 -07:00

90 lines
2.5 KiB
Cheetah

# Written by the inbuxa installer {{.Version}} for {{.Domain}}.
#
# Caddy holds 80 and 443 for two programs that both want certificates for some
# of the same names: Caddy itself, to serve HTTPS, and the mail server, whose
# IMAP and SMTP listeners need a certificate of their own. They are kept apart
# by challenge type rather than by name:
#
# Caddy TLS-ALPN-01 on 443 -- for the server's names it never uses 80.
# the server HTTP-01 on 80, which Caddy forwards to it untouched.
#
# So neither answers the other's challenge, and neither needs the other's key.
{
email {{.Email}}
{{- if .ACMEDirectory}}
acme_ca {{.ACMEDirectory}}
{{- end}}
{{- if .ACMECARoot}}
acme_ca_root /etc/caddy/acme-ca-root.pem
{{- end}}
}
{{- if .ServesWebmail}}
# The webmail. Push arrives as Server-Sent Events, so responses are flushed as
# they are written rather than buffered.
{{.WebmailHost}} {
encode zstd gzip
reverse_proxy {{.WebmailUpstream}} {
flush_interval -1
}
}
{{- end}}
{{- if .Console}}
# The console. Static files: it talks to the mail server from the browser, so
# nothing here proxies the API.
{{.ConsoleHost}} {
encode zstd gzip
reverse_proxy {{.ConsoleUpstream}}
}
{{- end}}
{{- if .ConsoleFiles}}
# The console, installed on this machine as files and served from them: a
# single-page app, so any path that is not a file is the app's own route.
# Hashed assets are cached for a year; index.html, which names them, never.
{{.ConsoleHost}} {
encode zstd gzip
root * /srv/console
try_files {path} /index.html
header /assets/* Cache-Control "public, max-age=31536000, immutable"
@page not path /assets/*
header @page Cache-Control "no-cache"
file_server
}
{{- end}}
{{- if .ServesServer}}
# The mail server's web side: JMAP for the front ends and any other client,
# CalDAV, CardDAV, autoconfig and MTA-STS. The server is told to believe the
# X-Forwarded-For Caddy sets here, so a scanner is banned by its own address
# rather than by Caddy's.
{{join .ServerNames ", "}} {
tls {
issuer acme {
{{- if .ACMEDirectory}}
dir {{.ACMEDirectory}}
{{- end}}
{{- if .ACMECARoot}}
trusted_roots /etc/caddy/acme-ca-root.pem
{{- end}}
email {{.Email}}
disable_http_challenge
}
}
reverse_proxy {{.ServerUpstream}}
}
# Port 80 for the server's names is its challenge path and a redirect.
{{range $i, $n := .ServerNames}}{{if $i}}, {{end}}http://{{$n}}{{end}} {
handle /.well-known/acme-challenge/* {
reverse_proxy {{.ServerUpstream}}
}
handle {
redir https://{host}{uri} 308
}
}
{{- end}}