diff --git a/CLAUDE.md b/CLAUDE.md index 6e18018..50fe604 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -31,7 +31,7 @@ go test ./web # checks a bui Do not start the server (`make run`, `docker run`, …) yourself; the user runs it in their own terminal. Check it with `curl localhost:8000/health` and ask the user to start it if it is not reachable. `make run` loads `.env` and `.env.local` (gitignored; template in `.env.example`); without projects (added on the Projects page or by `create_project`) every event is rejected: the start logs a warning, each rejected envelope only a debug line (`LOG_LEVEL=debug`). `.env.example` is a working local setup (the first admin set up with `exceptic`/`exceptic`, an API token; a project is added on the Projects page), short, every variable only in `docs/configuration.md`; real keys and passwords go into `.env.local` and never into it. `go run` does not rebuild on change: after editing Go code (or rebuilding the web app, which is embedded), the user must restart it. -The image has a writable `/tmp` (scratch has none). CI (`.github/workflows/ci.yml`) runs golangci-lint (pinned version), `make test`, `make vulncheck`, `make web-check web` with `go test ./web`, an amd64 image build with the size check and an arm64 build. `make release` (`tools/release.sh`, as hothost's build.sh: from this machine, no CI secrets; the version from the commits since the last release as semantic-release reads them (AdminForth): a breaking change the major, `feat:` the minor, `fix:`/`perf:` the patch, none of them nothing to release; asked for confirmation; or `VERSION=X.Y.Z`) checks that `main` is clean, pushed and green on CI for that commit (`gh run list`), builds the image with the size check, pushes `devforth/exceptic:X.Y.Z`, `:X.Y` and `:latest` (a pre-release `X.Y.Z-rc.1` only its own) for amd64 and arm64 with the machine's `docker login` (buildx), tags the commit `vX.Y.Z` and makes its GitHub release (`gh release create`, the commits since the previous tag; a pre-release marked so), and for a release replaces the description on Docker Hub with `docs/dockerhub.md` (short, links to GitHub by absolute URL, since Docker Hub resolves no relative link; markers of its copied blocks stripped) when `DOCKERHUB_USERNAME` and `DOCKERHUB_TOKEN` (Read, Write & Delete) are in the environment or `.env.local`. `image-scan.yml` runs Trivy weekly over the published `:latest` (fixable HIGH/CRITICAL fail the run: a patch release with a newer Go or module). `compose.yml` is the example deployment the docs refer to. +The image has a writable `/tmp` (scratch has none). CI (`.github/workflows/ci.yml`) runs golangci-lint (pinned version), `make test`, `make vulncheck`, `make web-check web` with `go test ./web`, an amd64 image build with the size check and an arm64 build. `make release` (`tools/release.sh`, as hothost's build.sh: from this machine, no CI secrets; the version from the commits since the last release as semantic-release reads them (AdminForth): a breaking change the major, `feat:` the minor, `fix:`/`perf:` the patch, none of them nothing to release; asked for confirmation; or `VERSION=X.Y.Z`) checks that `main` is clean, pushed and green on CI for that commit (`gh run list`), builds the image with the size check, pushes `devforth/exceptic:X.Y.Z`, `:X.Y` and `:latest` (a pre-release `X.Y.Z-rc.1` only its own) for amd64 and arm64 with the machine's `docker login` (buildx), tags the commit `vX.Y.Z` and makes its GitHub release (`gh release create`, the commits since the previous tag; a pre-release marked so), and for a release replaces the description on Docker Hub with `docs/dockerhub.md` (short, links to GitHub by absolute URL, since Docker Hub resolves no relative link; markers of its copied blocks stripped) when `DOCKERHUB_USERNAME` and `DOCKERHUB_TOKEN` (Read, Write & Delete) are in the environment or `.env.local`. `image-scan.yml` runs Trivy weekly over the published `:latest` (fixable HIGH/CRITICAL fail the run: a patch release with a newer Go or module). `compose.yml` is the example deployment the docs refer to; its `caddy` profile (`COMPOSE_PROFILES=caddy` in `.env`) adds Caddy with HTTPS on the host's network as `caddy reverse-proxy --from $PUBLIC_URL` (no Caddyfile; that command has no admin API; Exceptic limits request bodies itself). ## Architecture diff --git a/compose.yml b/compose.yml index 7c4ad2d..e75171a 100644 --- a/compose.yml +++ b/compose.yml @@ -1,5 +1,13 @@ # Example deployment behind an HTTPS reverse proxy on this machine: `docker compose up -d` (docs/deployment.md). # Put the settings in .env next to this file (docs/configuration.md; a minimal one in docs/deployment.md). + +# Docker keeps container logs forever by default: at most 3 files of 10 MB. +x-logging: &logging + driver: json-file + options: + max-size: 10m + max-file: "3" + services: exceptic: image: devforth/exceptic:latest # in production pin X.Y (docs/deployment.md) @@ -12,14 +20,26 @@ services: # Only on this machine, for its reverse proxy. A try over plain http from elsewhere: "8000:8000" with an http PUBLIC_URL. - "127.0.0.1:8000:8000" env_file: .env - # Docker keeps container logs forever by default: at most 3 files of 10 MB. - logging: - driver: json-file - options: - max-size: 10m - max-file: "3" + logging: *logging volumes: - data:/data + # HTTPS for PUBLIC_URL's domain, with COMPOSE_PROFILES=caddy in .env; skip it when the machine has a proxy already. + caddy: + image: caddy:2 + profiles: [caddy] + restart: unless-stopped + # On the host's ports 80 and 443, reaching Exceptic as a proxy installed on this machine would. + network_mode: host + cap_drop: [ALL] + cap_add: [NET_BIND_SERVICE] + security_opt: [no-new-privileges:true] + logging: *logging + # Caddy's own reverse proxy: HTTPS for PUBLIC_URL's domain, its certificate kept in caddy-data, no admin API. + command: caddy reverse-proxy --from ${PUBLIC_URL:-https://set-public-url-in-env.invalid} --to 127.0.0.1:8000 + volumes: + - caddy-data:/data + volumes: data: + caddy-data: diff --git a/docs/deployment.md b/docs/deployment.md index f9cfeca..412cab5 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -21,7 +21,7 @@ Image tags: `latest` (newest release), `X.Y` (newest patch of a minor version), With an `https://` `PUBLIC_URL` the login works only over HTTPS: set up the proxy first ([HTTPS and a reverse proxy](#https-and-a-reverse-proxy)). To try it on plain http, use `PUBLIC_URL=http://:8000` and publish `"8000:8000"`. -3. Run `docker compose up -d`, open `https://errors.example.com` and log in as `exceptic`. The password is `ADMIN_PASSWORD`. A form opens where you create the first admin with your email and your own password. +3. On a machine without a proxy, with an `https://` `PUBLIC_URL` (not for the try over plain http), add `COMPOSE_PROFILES=caddy` to `.env` ([Caddy from compose.yml](#caddy-from-composeyml)). Run `docker compose up -d`, open `https://errors.example.com` and log in as `exceptic`. The password is `ADMIN_PASSWORD`. A form opens where you create the first admin with your email and your own password. 4. On the **Projects** page add a project and give its DSN to your app: [Connecting apps](sdk.md). The container runs as an unprivileged user (uid 65534). A bind-mounted data folder must be writable by it: `sudo chown 65534:65534 ./data`. A named volume, as in the example, needs nothing. @@ -33,16 +33,22 @@ The container runs as an unprivileged user (uid 65534). A bind-mounted data fold Use HTTPS whenever the server is reachable from other machines. HTTPS is set up in a reverse proxy on the same machine (Caddy, nginx), not in Exceptic, and its certificate needs a domain. - `compose.yml` publishes the port only on `127.0.0.1`, so only the proxy reaches it. Keep it so: never publish `"8000:8000"` behind a proxy. -- Set `PUBLIC_URL=https://errors.example.com`. Nothing else is needed: the server then takes each person's address from the last `X-Forwarded-For` entry, the one the proxy added, and only from the proxy on this machine (in Docker: the address the published port comes from), so the login limit counts everyone apart and nobody can write an address of their own. If something reaches the server past the proxy, or another address sends the header, it says so in its log. +- Set `PUBLIC_URL=https://errors.example.com`. Nothing else is needed: the server then takes each person's address from the last `X-Forwarded-For` entry, the one the proxy added, and only from the proxy on this machine (in Docker: the address the published port comes from), so the login limit counts everyone apart and nobody can write an address of their own (programs on this machine reach the port as the proxy does). If something reaches the server past the proxy, or another address sends the header, it says so in its log. - The proxy passes the domain (`Host`), appends the address to `X-Forwarded-For` and sets `X-Forwarded-Proto`, and allows request bodies up to 20 MB. Caddy does all of it by itself. -Caddy (gets the certificate itself): +### Caddy from compose.yml + +When the machine has no proxy yet, add `COMPOSE_PROFILES=caddy` to `.env`: every `docker compose` command (`up`, `pull`, `down`) then includes Caddy beside Exceptic, run as `caddy reverse-proxy` (Caddy's own reverse proxy, without a Caddyfile). It gets the certificate for `PUBLIC_URL`'s domain itself, renews it and keeps it in the `caddy-data` volume. Without the profile it never starts, so a machine with nginx keeps using its own. + +- `PUBLIC_URL` is `https://` and the domain only, as in the example: no `/` or path at the end, or Caddy does not start (`paths are not allowed` in `docker compose logs caddy`). +- The domain points to this server, and ports 80 and 443 are free and open: Caddy uses the host's network (`network_mode: host`, Linux), so it reaches Exceptic as a proxy installed on the machine would, and nothing else is needed. + +### A proxy on the machine + +Caddy: ``` errors.example.com { - request_body { - max_size 20MB - } reverse_proxy 127.0.0.1:8000 } ``` @@ -68,8 +74,8 @@ server { ### Other setups -- **The proxy is on another machine, in a container of its own, or Exceptic runs with `network_mode: host` or in Kubernetes:** set `TRUSTED_PROXIES` to the proxy's address, e.g. `TRUSTED_PROXIES=10.0.0.5`. It replaces the default. List only proxies, never a whole range such as `172.16.0.0/12`. A proxy in a container needs a fixed address (`ipv4_address` in Compose). -- **Cloudflare in front:** keep the default and have your proxy send the visitor's address. In Caddy, put Cloudflare's ranges in `trusted_proxies` and add `header_up X-Forwarded-For {client_ip}`. In nginx, use `set_real_ip_from` with Cloudflare's ranges and `real_ip_header CF-Connecting-IP`. +- **The proxy is on another machine, in a container of its own on a Docker network (not compose.yml's Caddy, on the host's), or Exceptic runs with `network_mode: host` or in Kubernetes:** set `TRUSTED_PROXIES` to the proxy's address, e.g. `TRUSTED_PROXIES=10.0.0.5`. It replaces the default. List only proxies, never a whole range such as `172.16.0.0/12`. A proxy in a container needs a fixed address (`ipv4_address` in Compose). +- **Cloudflare in front:** keep the default and have your proxy send the visitor's address. compose.yml's Caddy cannot (it takes no settings), so run your own Caddy or nginx. In Caddy, put Cloudflare's ranges in `trusted_proxies` and add `header_up X-Forwarded-For {client_ip}`. In nginx, use `set_real_ip_from` with Cloudflare's ranges and `real_ip_header CF-Connecting-IP`. - **The proxy does not set `X-Forwarded-For`** (a plain TLS tunnel): set `TRUSTED_PROXIES=none`. ## Securing it diff --git a/docs/values_test.go b/docs/values_test.go index c1548b3..73e7581 100644 --- a/docs/values_test.go +++ b/docs/values_test.go @@ -124,7 +124,6 @@ func TestDocsValues(t *testing.T) { value{Phrase: "--log-opt max-file={}`", Value: logFiles}, value{Phrase: "open `https://errors.example.com` and log in as `{}`.", Value: config.DefaultAdminEmail}, value{Phrase: "request bodies up to {} MB", Value: ingest.MaxBodyBytes >> 20}, - value{Phrase: "max_size {}MB", Value: ingest.MaxBodyBytes >> 20}, value{Phrase: "client_max_body_size {}m;", Value: ingest.MaxBodyBytes >> 20}, value{Phrase: "**admin** ({})", Value: store.RoleSummaries[store.RoleAdmin]}, value{Phrase: "**user** ({}). A user sees only", Value: store.RoleSummaries[store.RoleUser]}, diff --git a/skills/exceptic/SKILL.md b/skills/exceptic/SKILL.md index 8097705..9109f67 100644 --- a/skills/exceptic/SKILL.md +++ b/skills/exceptic/SKILL.md @@ -29,7 +29,7 @@ Read the page for the task before acting, rather than relying on memory: it matc ## Deploy the server 1. Read deployment.md and configuration.md. Ask where it runs (this machine for a try, or a server with a domain) and whether a reverse proxy with HTTPS already exists. -2. Use the `compose.yml` from deployment.md and an `.env` next to it with at least `ADMIN_PASSWORD` and, on a server, `SECRET_KEY` (otherwise generated into the data directory), `PUBLIC_URL=https://` with the port published on `127.0.0.1` (as `compose.yml` does) and a reverse proxy with HTTPS on the same machine; `TRUSTED_PROXIES` only in the cases of deployment.md, Other setups. Let the user choose the admin password or tell them where it is stored; do not print it. +2. Use the `compose.yml` from deployment.md and an `.env` next to it with at least `ADMIN_PASSWORD` and, on a server, `SECRET_KEY` (otherwise generated into the data directory), `PUBLIC_URL=https://` with the port published on `127.0.0.1` (as `compose.yml` does) and a reverse proxy with HTTPS on the same machine (none yet: `COMPOSE_PROFILES=caddy` in `.env`, deployment.md, Caddy from compose.yml); `TRUSTED_PROXIES` only in the cases of deployment.md, Other setups. Let the user choose the admin password or tell them where it is stored; do not print it. 3. Start it with `docker compose up -d` (or let the user start it if they prefer), then check `curl -fsS /health`. 4. Tell the user to log in as `exceptic` with `ADMIN_PASSWORD`, set up the first admin with their own email and a new password in the form that opens, and add a project per service on the **Projects** page.