Install behind Caddy instead of nginx and acme.sh
install.sh sets up a fresh Debian or Ubuntu host behind Caddy, installed from Caddy's apt repository, which obtains and renews the certificate itself. The site goes to /etc/caddy/uberbringer.caddy and the Caddyfile imports it; an edited Caddyfile only gains the import line. The result is validated as the caddy user, and both files are put back if Caddy rejects it. Caddy's body limit follows webserver.body_limit, and a larger body gets the daemon's 413 body_too_large JSON. A re-run upgrades the binary, the unit and Caddy and restarts the service. The script does not migrate hosts set up by the 0.1 script. The Docker image stays a proxy-free microservice behind the operator's own reverse proxy. The README credits the pre-refactor code, written without AI, and design.md records the persistent job store and image previews as deferred work. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4562f0cebb
commit
92dcacb3b9
7 files changed
+353
-278
No files matched your search
@@ -22,6 +22,13 @@ REST API and prints them on an EPSON ESC/POS network receipt printer.
|
||||
- **Health endpoint** with live printer status: paper low or out, cover open,
|
||||
errors.
|
||||
|
||||
> [!NOTE]
|
||||
> **Pre-refactor code: no AI was used.** The original Überbringer (v0.1.x),
|
||||
> up to commit
|
||||
> [`bb73348`](https://git.anomalous.dev/57_Wolve/uberbringer/src/commit/bb73348433de1604c839de5fb8f8b2793e0e9518)
|
||||
> from January 2025, was written without any AI. That commit shows the
|
||||
> code as it was before the 0.2 refactor.
|
||||
|
||||
## Contents
|
||||
|
||||
- [Quick start](#quick-start)
|
||||
@@ -36,45 +43,72 @@ REST API and prints them on an EPSON ESC/POS network receipt printer.
|
||||
|
||||
## Quick start
|
||||
|
||||
### Debian/Ubuntu server with nginx and TLS
|
||||
### Debian/Ubuntu server with Caddy and TLS
|
||||
|
||||
```sh
|
||||
sudo ./install.sh printer.example.com you@example.com 192.168.1.245
|
||||
```
|
||||
|
||||
The arguments are the server's domain, the email address for Let's Encrypt,
|
||||
and the printer's address. The domain may contain only letters, digits, dots
|
||||
and hyphens. The printer address may also contain colons, for IPv6.
|
||||
The script sets up a fresh Debian or Ubuntu host, and re-runs upgrade what
|
||||
it set up. It does not upgrade a host set up by the 0.1 install script, which
|
||||
used nginx and acme.sh. Ports 80 and 443 must be free for Caddy.
|
||||
|
||||
The arguments are the server's domain, the email address for the ACME
|
||||
certificate account, and the printer's address. The domain may contain only
|
||||
letters, digits, dots and hyphens. The printer address may also contain
|
||||
colons, for IPv6. The domain's DNS must point at the server, and ports 80 and
|
||||
443 must be reachable, for the certificate to be issued.
|
||||
|
||||
The script does the following:
|
||||
|
||||
- It downloads the latest release for the host's architecture and checks it
|
||||
against the release's `checksums.txt` (sha256). If the check fails, nothing
|
||||
is installed. To install a given release, name its tag:
|
||||
- It installs curl and gnupg, then downloads the latest release for the
|
||||
host's architecture and checks it against the release's `checksums.txt`
|
||||
(sha256). If the check fails, nothing else is installed. To install a given
|
||||
release, name its tag:
|
||||
`sudo UBERBRINGER_VERSION=v0.2.0 ./install.sh <domain> <acme-email> <printer-address>`.
|
||||
- It installs the binary to `/usr/local/bin/uberbringer` and the systemd unit
|
||||
to `/usr/local/lib/systemd/system/uberbringer.service`. The unit comes from
|
||||
the release archive, or from this checkout's `packaging/` directory if the
|
||||
archive lacks it. The service runs as a dedicated `uberbringer` user.
|
||||
from the release archive to
|
||||
`/usr/local/lib/systemd/system/uberbringer.service`. The service runs as a
|
||||
dedicated `uberbringer` user.
|
||||
- It writes `/etc/uberbringer/config.toml` (0640, root:uberbringer) with a
|
||||
fresh secret.
|
||||
- It sets up nginx as the HTTPS reverse proxy. The certificate comes from
|
||||
Let's Encrypt through acme.sh, whose cron job renews it.
|
||||
- It installs [Caddy](https://caddyserver.com) from Caddy's own apt repository
|
||||
as the HTTPS reverse proxy. Caddy obtains and renews the certificate itself
|
||||
and redirects HTTP to HTTPS.
|
||||
- The site is `/etc/caddy/uberbringer.caddy`; `/etc/caddy/Caddyfile`
|
||||
imports it. The package's default Caddyfile is replaced and kept as
|
||||
`Caddyfile.default`.
|
||||
- Caddy passes the client address in `X-Real-IP`, adds HSTS and other
|
||||
security headers, and logs requests to
|
||||
`/var/log/caddy/uberbringer-access.log`.
|
||||
- Caddy limits request bodies to `webserver.body_limit` from the config
|
||||
(4 MiB by default). It answers a larger body itself, with the same `413`
|
||||
`body_too_large` JSON the daemon sends.
|
||||
- The configuration is validated as the `caddy` user before it is used. If
|
||||
Caddy rejects it, the previous Caddyfile and site file are put back and
|
||||
the script stops.
|
||||
- It writes the first API token to `/etc/uberbringer/initial-token` (0600,
|
||||
readable by root only) instead of printing it. Copy the token to your
|
||||
client, then delete the file.
|
||||
|
||||
The install log, apt output included, is `/var/log/uberbringer-install.log`.
|
||||
|
||||
Running the script again upgrades the binary and the unit, and restarts the
|
||||
service only if the binary, the unit or the config changed. It also rewrites
|
||||
the nginx site files `/etc/nginx/sites-available/default.conf` and
|
||||
`reverse-proxy.conf`, so local edits to them are lost. It keeps:
|
||||
Running the script again upgrades the binary, the unit and Caddy, and
|
||||
restarts the service. It rewrites `/etc/caddy/uberbringer.caddy`, so local
|
||||
edits to that file are lost. It keeps:
|
||||
|
||||
- **The config.** The printer-address argument is ignored on a re-run, so
|
||||
edit `printer.address` in `/etc/uberbringer/config.toml` instead.
|
||||
- **The certificate.** One is requested only when `fullchain.pem` or
|
||||
`privkey.pem` in `/etc/letsencrypt/live/<domain>/` is missing or empty.
|
||||
edit `printer.address` in `/etc/uberbringer/config.toml` instead. The daemon
|
||||
reads the config only when it starts: after an edit, run
|
||||
`systemctl restart uberbringer`. After changing `webserver.body_limit`,
|
||||
re-run the script instead, which copies the new limit into Caddy's site and
|
||||
restarts the service.
|
||||
- **Your Caddyfile edits.** Put global options and your other sites in the
|
||||
Caddyfile. Once you have edited it, a re-run only adds the `import` line if
|
||||
it is missing (keeping the previous copy as `Caddyfile.bak`), and the file
|
||||
keeps its owner and mode. Überbringer's own site can't be changed there,
|
||||
because `uberbringer.caddy` defines it.
|
||||
- **The certificate.** Caddy stores it and renews it before it expires.
|
||||
- **Tokens.** A re-run creates none. Issue more with
|
||||
`uberbringer token --config /etc/uberbringer/config.toml --subject <client>`.
|
||||
|
||||
@@ -86,13 +120,6 @@ The systemd unit ships as
|
||||
- **Sandboxing.** The unit has no capabilities and a read-only file system,
|
||||
and it can reach the network over IPv4 and IPv6 only. Check it on the host
|
||||
with `systemd-analyze security uberbringer`.
|
||||
- **The 0.1 unit.** The 0.1 install script wrote
|
||||
`/etc/systemd/system/uberbringer.service`, and a re-run renames that file to
|
||||
`uberbringer.service.bak`. Any other file at that path overrides the
|
||||
packaged unit; the script leaves it in place and warns.
|
||||
|
||||
Upgrading a 0.1 install needs a few manual steps; see
|
||||
[Migrating from the old format](#migrating-from-the-old-format).
|
||||
|
||||
### Docker
|
||||
|
||||
@@ -101,7 +128,22 @@ docker build -t uberbringer .
|
||||
docker run -d -p 8080:8080 -v "$PWD/config.toml:/etc/uberbringer/config.toml:ro" uberbringer
|
||||
```
|
||||
|
||||
Inside a container, set `bind_ip = "0.0.0.0"` in the `[webserver]` section.
|
||||
The image is a microservice for running behind your own reverse proxy. It
|
||||
contains no proxy and no TLS: it serves plain HTTP on port 8080, and the proxy
|
||||
terminates HTTPS. In the mounted `config.toml`:
|
||||
|
||||
- Set `bind_ip = "0.0.0.0"` in `[webserver]`.
|
||||
- Set `trusted_proxies` to your proxy's address or its container network
|
||||
(e.g. `["172.18.0.0/16"]`), and have the proxy set `X-Real-IP` to the
|
||||
client's address. Otherwise every request appears to come from the proxy,
|
||||
and all clients share one rate limit.
|
||||
- Let the proxy pass request bodies up to `webserver.body_limit` (4 MiB by
|
||||
default).
|
||||
|
||||
Publish port 8080 only to the proxy, never directly to the internet. For
|
||||
container health checks, use `GET /` to see whether the daemon is up.
|
||||
`/healthz` answers `503` while the printer is unreachable, so it suits
|
||||
alerting better than restarting the container.
|
||||
|
||||
### From source
|
||||
|
||||
@@ -560,7 +602,7 @@ Old text items did not end the line, hence `"newline": false`. You can usually
|
||||
drop it now and let each `text` element be a line. Hex-encoded CP437 box
|
||||
drawing can become plain text: `B3 20 21 21 21` is `"│ !!!"`.
|
||||
|
||||
These changes also affect 0.1 clients and installs.
|
||||
These changes also affect 0.1 clients and configs.
|
||||
[CHANGELOG.md](CHANGELOG.md) lists every change.
|
||||
|
||||
- Tokens are read only from the `Authorization` header. A `?token=` query
|
||||
@@ -569,26 +611,11 @@ These changes also affect 0.1 clients and installs.
|
||||
or plain text.
|
||||
- `printer.model` defaults to `tm-t88` (512 dots). On a TM-T20, set
|
||||
`model = "tm-t20"` to use the full 576-dot width.
|
||||
|
||||
To upgrade a server set up by the 0.1 install script:
|
||||
|
||||
1. Add a `[printer]` section to `/etc/uberbringer/config.toml`. The 0.1
|
||||
script did not write one, `printer.address` is now required, and
|
||||
`install.sh` keeps an existing config as it is, so without this step the
|
||||
service does not start:
|
||||
|
||||
```toml
|
||||
[printer]
|
||||
address = "192.168.1.245"
|
||||
```
|
||||
|
||||
2. Run the new `install.sh` with the domain, the email address and the
|
||||
printer address; it needs all three, although the printer address in the
|
||||
kept config is the one used. It creates the `uberbringer` user, installs
|
||||
the new unit and moves the 0.1 unit aside.
|
||||
3. The 0.1 script left the config readable by every user. Once the
|
||||
`uberbringer` group exists, fix that with
|
||||
`sudo chown root:uberbringer /etc/uberbringer/config.toml && sudo chmod 0640 /etc/uberbringer/config.toml`.
|
||||
- A 0.1 config needs a `[printer]` section with `address` before 0.2
|
||||
starts, because `printer.address` is now required. The 0.1 install script
|
||||
did not write one.
|
||||
- `install.sh` sets up a fresh host. It does not upgrade a server set up by
|
||||
the 0.1 install script.
|
||||
|
||||
## Configuration
|
||||
|
||||
@@ -628,8 +655,8 @@ Settings worth knowing:
|
||||
all copies counted, fails instead of printing. It is a backstop against
|
||||
runaway text; `/api/v1/preview` answers such a job with `422`.
|
||||
- `webserver.trusted_proxies` / `proxy_header`: the real client IP for
|
||||
per-client rate limits comes from the `X-Real-IP` header set by nginx on
|
||||
`127.0.0.1`.
|
||||
per-client rate limits comes from the `X-Real-IP` header set by the reverse
|
||||
proxy (Caddy, as `install.sh` configures it) on `127.0.0.1`.
|
||||
- `sentry.dsn`: error reporting. Falls back to the `SENTRY_DSN` environment
|
||||
variable, then to a DSN built into release binaries (from the `SENTRY_DSN`
|
||||
CI secret). Request bodies and the `Authorization` header are never sent
|
||||
|
||||
Reference in new issue
Block a user