Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .changeset/selfhost-smtp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@cloudhal/cli": minor
---

The self-host image mails invites and password resets (#291). Set `CLOUDHAL_SMTP_URL` (or `CLOUDHAL_SMTP_URL_FILE`) and `CLOUDHAL_MAIL_FROM`, and the generated workerd config gets an `smtp` Worker behind the admin Worker's `EMAIL` binding, the binding used on Cloudflare.
- It connects with STARTTLS (`smtp://`) or implicit TLS (`smtps://`) only.
- Retries are bounded.
- Its logs carry no message bodies and no credentials.
- `CLOUDHAL_SMTP_CA_FILE` adds certificates to trust.

The compose file gains a `mail` profile (Mailpit), and the Helm chart gains `mail.*` values.
15 changes: 14 additions & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ name: Docker image
# (compose.yml's SeaweedFS, the image's own `secrets`, the first site and owner, a publish live
# on the next request, a restart, the Node-volume guard, a second instance taking over while the
# first stops), scripts/failover-smoke.ts (three instances, one killed with SIGKILL while a release
# is due, then graceful handoffs under load; #290) and Trivy, which fails the job on a CRITICAL
# is due, then graceful handoffs under load; #290), scripts/mail-smoke.ts (an invite and a reset
# through Mailpit with STARTTLS and AUTH; #291) and Trivy, which fails the job on a CRITICAL
# vulnerability with a fix;
# - `smoke-arm64` runs the same smoke test on the arm64 image, on GitHub's native arm64 runner;
# - `tag` adds the release tags to the very digest that passed, with `imagetools create`, writes
Expand Down Expand Up @@ -52,6 +53,7 @@ on:
- ".github/workflows/docker.yml"
- "scripts/docker-smoke.ts"
- "scripts/failover-smoke.ts"
- "scripts/mail-smoke.ts"
- "scripts/pack-packages.ts"
- "scripts/selfhost-edge-bundle.ts"
- "packages/cli/src/selfhost/**"
Expand Down Expand Up @@ -111,11 +113,17 @@ jobs:
} > "$RUNNER_TEMP/compose.env"
docker compose -f deploy/docker/compose.yml --env-file "$RUNNER_TEMP/compose.env" config --quiet
docker compose -f deploy/docker/compose.yml --env-file "$RUNNER_TEMP/compose.env" --profile caddy config --quiet
docker compose -f deploy/docker/compose.yml --env-file "$RUNNER_TEMP/compose.env" --profile mail config --quiet
- name: Lint the Helm chart
run: |
helm lint deploy/helm/cloudhal
helm lint deploy/helm/cloudhal --set replicaCount=3 --set baseUrl=https://studio.example.com --set ingress.enabled=true
helm template t deploy/helm/cloudhal --set httpRoute.enabled=true --set baseUrl=https://studio.example.com --set 'httpRoute.parentRefs[0].name=gw' > /dev/null
helm template t deploy/helm/cloudhal --set mail.smtpUrlSecret.name=smtp --set mail.from=cloudhal@example.com --set mail.caConfigMap.name=ca \
| grep -q 'CLOUDHAL_SMTP_CA_FILE' || { echo "::error::the chart's mail values render no CLOUDHAL_SMTP_CA_FILE"; exit 1; }
if helm template t deploy/helm/cloudhal --set mail.smtpUrlSecret.name=smtp > /dev/null 2>&1; then
echo "::error::mail.smtpUrlSecret without mail.from must fail"; exit 1
fi
- name: The kustomize base matches the chart
run: scripts/kustomize-base.sh --check
# The stores the recipes offer, against what workerd's cluster and R2 binding need
Expand Down Expand Up @@ -251,6 +259,11 @@ jobs:
- name: Cluster failover test
timeout-minutes: 20
run: node scripts/failover-smoke.ts --image cloudhal:ci
# Mail (#291): Mailpit requiring STARTTLS and AUTH; an invite and a password reset arrive, and
# the log names each send without the password or a token. CI only, like the failover test.
- name: Mail smoke test (Mailpit)
timeout-minutes: 10
run: node scripts/mail-smoke.ts --image cloudhal:ci
- name: Trivy scan
timeout-minutes: 15
uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ node scripts/release-bundle.ts build|verify … # RFC-0046 release bundle: det
- `packages/core-ts` — `SiteGraphStore` (CAS on `rev`, snapshots, diff, publish, rollback). Behavioural suite in `src/testing.ts` runs on sqlite and Miniflare D1. `./local` opens the offline store; `seedStarterSite` seeds a demo. `./surfaces` is RFC-0020's generative UI: the catalog (primitives + block types), eval-free surface checks, bindings, repairs, JSON Patch (`patchPage`), `catalogPrompt`; `./interop` converts A2UI v0.9 and json-render to and from surfaces; `./design` is RFC-0021's DESIGN.md lint and guidance. `./fields` is RFC-0041's typed custom fields (definition and value checks, `resolveFields`, `formatFieldValue`, the agents' JSON Schema, the conversion table); `src/fields-operations/` runs rename/retype/localize/remove. `search.ts` is RFC-0019's FTS5 site search (index written with the publish batch; articles, pages, terms and authors, RFC-0029); `search-provider.ts` is RFC-0029's `SearchProvider` (`fts5`, `memory`, `withFallback`), set with `SiteGraphStoreOptions.search`; `search-ai.ts` is the experimental Cloudflare AI Search provider (`hybridProvider`, `searchProviderFromEnv`, `cloudhal.json` `search`, docs/guides/search.md).
- `packages/schedules` — RFC-0008: time model (only `temporal-polyfill/implementation`, `now` injected, never `Temporal.Now`), RRULE subset, release model (`rl1:`), automation/run state, taint and budgets, `runDue`; `./sql` is `SqlScheduleStore`, `./engine` the Temporal-free part core-ts and the site Worker use. Worker-safe; conformance suites in `src/testing.ts` on sqlite and Miniflare D1.
- `packages/astro-renderer` — `GraphSource` (live/snapshot), `cloudhal()` integration (virtual config + dev route-cache watcher), `.astro` section components (`Surface.astro` for RFC-0020 surfaces; `./surfaces` renders them, `./kit` has the table of contents and reading time; `./fields` and `EntryFields.astro` render typed field values, RFC-0041). `./status-page` is RFC-0043's status pages (`statusPage(state, input) → Response`, served by the Site Worker entry before Astro and by `cloudhal dev` at `/__cloudhal/status/<state>`; the optional `statusPage` theme hook; the catalog in `src/status-strings/` where only `en.ts` is hand-edited and the other languages come from `pnpm i18n:import`). Routes live in starters, not here.
- `packages/cli` — the `cloudhal` CLI (`init`, `dev`, `studio`, `mcp`, `deploy`, `push`, `pull`, `export`, `import`, …; every command is in `src/cli/help.ts`, which `cloudhal --help` prints and the docs site's CLI reference is generated from); TS bin run by Node 24 type stripping. `src/cli.ts` parses flags and dispatches through `COMMANDS`, built from `src/cli/commands-{local,remote,content,ops,site}.ts` (a new command is one handler plus one line in `src/cli/help.ts`). `src/archive/` is RFC-0039's `.cloudhal` container (tar, gzip, manifest, limits), read and written by `src/commands/export.ts` and `import*.ts` (`archive-bundle.ts`, `archive-reassemble.ts`); the starter demo archive `test/fixtures/site-archives/starter-blog.cloudhal` is written by `pnpm demo:archive`, and `pnpm check` fails when it is stale. E2E test spawns the bin (Astro disables dev middleware under `VITEST`). Cloudflare tests run both Workers on workerd via wrangler's `createTestHarness`; test files run serially (shared starter caches). `src/commands/deploy/release/` is RFC-0046 §11b's `deploy --release`: the signed key and yank lists (`trust.ts`, the yank memory in `~/.cloudhal/release-trust.json`), the release lookup and download, the theme check against the CLI's starter (`theme-check.ts`; recheck its build-input list on every Astro or Vite major), the build keys of `src/config-build-keys.ts`, extraction and the `no_bundle` wrangler configs; tests use `@cloudhal/release-verify`'s synthetic bundle (`test/fixtures/release-deploy.ts`), never the network. `src/selfhost/` is RFC-0047's self-host image on workerd (`cloudhal selfhost fetch|check|config|secrets|start`): the settings (`_FILE` secrets), the generated Cap'n Proto config (Durable Object `uniqueKey`s are constants, never change them), the bundle check, the Node-volume guard and the first site; `deploy/docker/workerd/` pins workerd (an npm lockfile Dependabot bumps weekly, ADR-0047; never the Miniflare pin), `scripts/docker-smoke.ts` runs it on SeaweedFS.
- `packages/cli` — the `cloudhal` CLI (`init`, `dev`, `studio`, `mcp`, `deploy`, `push`, `pull`, `export`, `import`, …; every command is in `src/cli/help.ts`, which `cloudhal --help` prints and the docs site's CLI reference is generated from); TS bin run by Node 24 type stripping. `src/cli.ts` parses flags and dispatches through `COMMANDS`, built from `src/cli/commands-{local,remote,content,ops,site}.ts` (a new command is one handler plus one line in `src/cli/help.ts`). `src/archive/` is RFC-0039's `.cloudhal` container (tar, gzip, manifest, limits), read and written by `src/commands/export.ts` and `import*.ts` (`archive-bundle.ts`, `archive-reassemble.ts`); the starter demo archive `test/fixtures/site-archives/starter-blog.cloudhal` is written by `pnpm demo:archive`, and `pnpm check` fails when it is stale. E2E test spawns the bin (Astro disables dev middleware under `VITEST`). Cloudflare tests run both Workers on workerd via wrangler's `createTestHarness`; test files run serially (shared starter caches). `src/commands/deploy/release/` is RFC-0046 §11b's `deploy --release`: the signed key and yank lists (`trust.ts`, the yank memory in `~/.cloudhal/release-trust.json`), the release lookup and download, the theme check against the CLI's starter (`theme-check.ts`; recheck its build-input list on every Astro or Vite major), the build keys of `src/config-build-keys.ts`, extraction and the `no_bundle` wrangler configs; tests use `@cloudhal/release-verify`'s synthetic bundle (`test/fixtures/release-deploy.ts`), never the network. `src/selfhost/` is RFC-0047's self-host image on workerd (`cloudhal selfhost fetch|check|config|secrets|start`): the settings (`_FILE` secrets), the generated Cap'n Proto config (Durable Object `uniqueKey`s are constants, never change them), the bundle check, the Node-volume guard, the first site and the SMTP sender behind `EMAIL` (`smtp-*.ts`, #291: STARTTLS or TLS only; `smtp-client.ts` has no imports because the config embeds it as a Worker module); `deploy/docker/workerd/` pins workerd (an npm lockfile Dependabot bumps weekly, ADR-0047; never the Miniflare pin), `scripts/docker-smoke.ts` runs it on SeaweedFS.
- `packages/cloudflare` — the admin Worker (`createAdminWorker`); `./playground` is RFC-0036's playground Worker (`createPlaygroundWorker`, the `PlaygroundSite` Durable Object, signed session cookies). Generated entries must import `@cloudhal/cloudflare/workerd-prelude` first (ADR-0012).
- `packages/agent-runtime` / `packages/mcp-server` — policy, skills, audit; MCP tools and transports (ADR-0011). `@cloudhal/mcp-server/render` is RFC-0021's `render_page` core: a small DevTools client, the in-page checks and limits; the CLI drives local Chrome with it (`render-chrome.ts`), the admin Worker Browser Rendering (`browser-render.ts`).
- `starters/blog` — the theme boundary: `src/pages/[...path].astro`, `src/layouts`, `src/theme.ts`.
Expand Down
12 changes: 12 additions & 0 deletions deploy/docker/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,17 @@
# uploads after a day.
#CLOUDHAL_S3_LIFECYCLE=on

# Mail: invites and password resets by email. Off unless CLOUDHAL_SMTP_URL is set (or
# CLOUDHAL_SMTP_URL_FILE names a file holding it). smtp:// is STARTTLS (port 587 by default),
# smtps:// TLS from the start (465); a server without STARTTLS is refused, never used unencrypted.
# CLOUDHAL_MAIL_FROM is the one sender address; CLOUDHAL_SMTP_CA_FILE adds certificates to trust.
#CLOUDHAL_SMTP_URL=smtp://user:password@smtp.example.com:587
#CLOUDHAL_MAIL_FROM=cloudhal@example.com
#CLOUDHAL_MAIL_FROM_NAME=Cloudhal
#CLOUDHAL_SMTP_CA_FILE=
# The mail profile (Mailpit, http://127.0.0.1:8025) instead: `docker compose --profile mail up -d`.
#CLOUDHAL_SMTP_URL=smtp://cloudhal:mailpit@mailpit:1025
#CLOUDHAL_SMTP_CA_FILE=/run/cloudhal-mail/cert.pem

# Traces of every Worker invocation to an OTLP/HTTP collector.
#OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4318
6 changes: 4 additions & 2 deletions deploy/docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ The official self-host image, `ghcr.io/cloudhal-dev/cloudhal`, built from each r
3. checks the bundle;
4. writes the workerd config and runs workerd, passing one SIGTERM on;
5. creates the site under `CLOUDHAL_SITE_ID`.
- **`compose.yml`, `.env.example`, `Caddyfile`:** Cloudhal with SeaweedFS and a one-shot that creates the bucket. With the `caddy` profile, Caddy proxies both hosts with TLS and sets `CF-Connecting-IP`.
- **`compose.yml`, `.env.example`, `Caddyfile`:** Cloudhal with SeaweedFS and a one-shot that creates the bucket.
- With the `caddy` profile, Caddy proxies both hosts with TLS and sets `CF-Connecting-IP`.
- With the `mail` profile, Mailpit catches every message at http://127.0.0.1:8025. It requires STARTTLS, with a certificate the `mail-tls` one-shot makes once.

Build a release:

Expand All @@ -30,4 +32,4 @@ node scripts/pack-packages.ts deploy/docker/tarballs && pnpm --filter @cloudhal/

`node scripts/docker-smoke.ts --image cloudhal:local` runs what CI runs after every build (`.github/workflows/docker.yml`); `--platform linux/arm64` runs the other architecture where Docker can.

`scripts/failover-smoke.ts` is the cluster failover test (#290): three instances, one killed with SIGKILL while a release is due, then graceful handoffs under load. It runs in CI only and refuses to start anywhere else.
`scripts/failover-smoke.ts` is the cluster failover test (#290): three instances, one killed with SIGKILL while a release is due, then graceful handoffs under load. It runs in CI only and refuses to start anywhere else. So does `scripts/mail-smoke.ts` (#291), which sends an invite and a password reset through Mailpit with STARTTLS and AUTH required.
48 changes: 48 additions & 0 deletions deploy/docker/compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# docker compose up -d Studio on http://localhost:8787, the site on :8788
# docker compose --profile caddy up -d + Caddy with automatic TLS for CLOUDHAL_BASE_URL
# (Studio) and CLOUDHAL_SITE_URL (the site)
# docker compose --profile mail up -d + Mailpit, which catches every mail Cloudhal sends
# (http://127.0.0.1:8025; see the mailpit service)
# Every instance of an installation needs the same .env; this file runs one instance (the cluster
# of one). More instances: deploy/swarm or deploy/helm.
x-store: &store
Expand Down Expand Up @@ -50,8 +52,17 @@ services:
CLOUDHAL_SITE_NAME: ${CLOUDHAL_SITE_NAME:-My site}
CLOUDHAL_AUTOMATIONS: ${CLOUDHAL_AUTOMATIONS:-}
OTEL_EXPORTER_OTLP_ENDPOINT: ${OTEL_EXPORTER_OTLP_ENDPOINT:-}
# Mail (invites, password resets): off unless CLOUDHAL_SMTP_URL is set. smtp:// is STARTTLS,
# smtps:// TLS from the start; there is no unencrypted mode. CLOUDHAL_SMTP_CA_FILE adds
# certificates to trust (the mail profile's, a private relay's).
CLOUDHAL_SMTP_URL: ${CLOUDHAL_SMTP_URL:-}
CLOUDHAL_SMTP_CA_FILE: ${CLOUDHAL_SMTP_CA_FILE:-}
CLOUDHAL_MAIL_FROM: ${CLOUDHAL_MAIL_FROM:-}
CLOUDHAL_MAIL_FROM_NAME: ${CLOUDHAL_MAIL_FROM_NAME:-}
volumes:
- cloudhal-data:/data
# The mail profile's certificate (empty without the profile).
- mail-tls:/run/cloudhal-mail:ro
read_only: true
tmpfs:
- /tmp
Expand Down Expand Up @@ -109,6 +120,42 @@ services:
- caddy-data:/data
- caddy-config:/config

# The mail profile: Mailpit catches every message at http://127.0.0.1:8025 and sends nothing on.
# It requires STARTTLS, with a certificate mail-tls makes once. Set in .env (.env.example):
# CLOUDHAL_SMTP_URL=smtp://cloudhal:mailpit@mailpit:1025
# CLOUDHAL_SMTP_CA_FILE=/run/cloudhal-mail/cert.pem
# CLOUDHAL_MAIL_FROM=cloudhal@example.com
mail-tls:
profiles: [mail]
image: alpine/openssl:3.5.9@sha256:b5d60ce9b9a318fa4efda9b0cd2111fa1e536342072885e8e2ce37c40f653ed9
entrypoint: ["/bin/sh", "-c"]
command:
- |
[ -s /tls/cert.pem ] && exit 0
openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes -days 3650 \
-subj /CN=mailpit -addext subjectAltName=DNS:mailpit \
-keyout /tls/key.pem -out /tls/cert.pem && chmod 644 /tls/key.pem /tls/cert.pem
volumes:
- mail-tls:/tls

mailpit:
profiles: [mail]
image: axllent/mailpit:v1.34.0@sha256:23a2ef85bc50853ab3093645d1d64679afd8887e89da5e48a88940c172591a4e
restart: unless-stopped
depends_on:
mail-tls:
condition: service_completed_successfully
environment:
MP_SMTP_TLS_CERT: /tls/cert.pem
MP_SMTP_TLS_KEY: /tls/key.pem
MP_SMTP_REQUIRE_STARTTLS: "true"
# Any user and password: it is a catcher, not a relay.
MP_SMTP_AUTH_ACCEPT_ANY: "true"
ports:
- "127.0.0.1:${MAILPIT_PORT:-8025}:8025"
volumes:
- mail-tls:/tls:ro

volumes:
# Each instance's Durable Object files (they replicate through the store) and the v2 marker.
cloudhal-data:
Expand All @@ -118,3 +165,4 @@ volumes:
name: ${CLOUDHAL_STORE_VOLUME:-cloudhal-store}
caddy-data:
caddy-config:
mail-tls:
17 changes: 17 additions & 0 deletions deploy/helm/cloudhal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,23 @@ helm install cloudhal deploy/helm/cloudhal --set store.enabled=false \

The store must enforce conditional writes. That covers AWS S3, GCS's XML API, R2 and RustFS, but not MinIO's archived community edition or Garage. Give the bucket a lifecycle rule that aborts incomplete multipart uploads.

## Mail

Invites and password resets go by email once the chart knows an SMTP server. Keep its URL in a Secret of your own, then name it and the sender address:

```bash
kubectl create secret generic cloudhal-smtp --from-literal=CLOUDHAL_SMTP_URL='smtp://user:password@smtp.example.com:587'
```

```bash
helm upgrade cloudhal deploy/helm/cloudhal --reuse-values \
--set mail.smtpUrlSecret.name=cloudhal-smtp --set mail.from=cloudhal@example.com
```

- `smtp://` means STARTTLS, and a server that does not offer it is refused. `smtps://` means TLS from the first byte. There is no unencrypted mode.
- For a relay whose certificate no browser trusts, put its CA in a ConfigMap and set `mail.caConfigMap.name` (key `ca.pem` by default).
- The pods connect to the server themselves. Under an egress NetworkPolicy of your own, allow its port.

## Upgrades

```bash
Expand Down
27 changes: 27 additions & 0 deletions deploy/helm/cloudhal/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,23 @@ spec:
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: {{ . | quote }}
{{- end }}
{{- with .Values.mail.smtpUrlSecret.name }}
- name: CLOUDHAL_SMTP_URL
valueFrom:
secretKeyRef:
name: {{ . | quote }}
key: {{ $.Values.mail.smtpUrlSecret.key | quote }}
- name: CLOUDHAL_MAIL_FROM
value: {{ required "mail.from is required with mail.smtpUrlSecret.name" $.Values.mail.from | quote }}
{{- with $.Values.mail.fromName }}
- name: CLOUDHAL_MAIL_FROM_NAME
value: {{ . | quote }}
{{- end }}
{{- if $.Values.mail.caConfigMap.name }}
- name: CLOUDHAL_SMTP_CA_FILE
value: "/etc/cloudhal/smtp-ca/{{ $.Values.mail.caConfigMap.key }}"
{{- end }}
{{- end }}
{{- with .Values.extraEnv }}
{{- toYaml . | nindent 12 }}
{{- end }}
Expand Down Expand Up @@ -109,11 +126,21 @@ spec:
mountPath: /data
- name: tmp
mountPath: /tmp
{{- if and .Values.mail.smtpUrlSecret.name .Values.mail.caConfigMap.name }}
- name: smtp-ca
mountPath: /etc/cloudhal/smtp-ca
readOnly: true
{{- end }}
volumes:
- name: tmp
emptyDir:
medium: Memory
sizeLimit: 16Mi
{{- if and .Values.mail.smtpUrlSecret.name .Values.mail.caConfigMap.name }}
- name: smtp-ca
configMap:
name: {{ .Values.mail.caConfigMap.name | quote }}
{{- end }}
{{- if not .Values.persistence.enabled }}
- name: data
emptyDir: {}
Expand Down
Loading