Repository navigation
feat(email): launch the Bulwark webmail dark, with no route #6665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
devantler
wants to merge
2
commits into
main
Choose a base branch
from
claude/bulwark-dark-launch-6662
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+818
−0
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| # Bulwark webmail | ||
|
|
||
| [Bulwark](https://github.com/bulwarkmail/webmail) (AGPL-3.0-only) is a webmail for JMAP servers. | ||
| The platform runs it so that the maintainer can read the company mailbox from devices he does not | ||
| own ([#6662](https://github.com/devantler-tech/platform/issues/6662)). It is a Next.js server; the | ||
| browser talks JMAP straight to Stalwart, and the server handles the OAuth sign-in and checks | ||
| session limits. | ||
|
|
||
| It is a third-party app, so it runs in production only (ADR 0016), in the `bulwark` namespace | ||
| (`k8s/providers/hetzner/apps/bulwark/`). It is launched dark: it runs and must report ready, but | ||
| nothing routes to it until the swap step of #6662. | ||
|
|
||
| ## Decisions | ||
|
|
||
| The maintainer's decisions of 2026-11-25: | ||
|
|
||
| - Bulwark serves `mail.${domain}`; Stalwart's web side moves to `stalwart.${domain}`. | ||
| - Bulwark sits behind GitHub SSO, and the mailbox sign-in is only Stalwart's own OAuth login: the | ||
| mail password and two-factor code are typed on Stalwart's page, never Bulwark's. | ||
| - Sessions end after 15 minutes without activity and 12 hours after sign-in. "Remember me" is | ||
| offered and off unless ticked. | ||
| - Uploads are allowed for the maintainer's account only. That is a Stalwart setting, changed in | ||
| #6662's restart step. | ||
|
|
||
| ## What is deployed | ||
|
|
||
| `deployment.yaml` explains each setting. In short: | ||
|
|
||
| - Sign-in is OAuth only (`OAUTH_ONLY`) against `JMAP_SERVER_URL=https://stalwart.${domain}`, as | ||
| the public client `bulwark`. | ||
| - `NO_THIRD_PARTY_TRAFFIC` turns off every outside host Bulwark knows about: telemetry, update | ||
| check, push relay, extension directory, sender favicons and the rest. | ||
| - `STALWART_FEATURES=false` hides the Stalwart account screens. `STALWART_ADMIN_ACCESS=off` with | ||
| no `ADMIN_PASSWORD` leaves Bulwark's admin dashboard disabled: a Stalwart administrator gets no | ||
| Bulwark admin rights, and there is no admin password to guess. | ||
| - The admin config is a read-only ConfigMap (`config-map.yaml`). Its `policy.json` holds the | ||
| session limits in `organisation.session`: `idleMinutes: 15`, `maxHours: 12` and the default | ||
| `warnSeconds: 60` ([Bulwark's sign-out times](https://bulwarkmail.org/docs/guides/organisation/sessions)). | ||
| - The session secret is generated once by an External Secrets `Password` generator and read from | ||
| a file. A new secret, after a rebuild, signs everyone out once. | ||
| - One replica. Without a shared store (Valkey), sessions, sign-in limits and admin state are per | ||
| pod, and they live on scratch volumes. | ||
| - The pod runs under restricted pod security with a read-only root filesystem, as UID 65532. | ||
| - The network policy admits no ingress. Egress is `stalwart.${domain}` on 443 and the DNS lookups | ||
| for it. Readiness (`/api/health/ready`) proves that path: it needs an answer from Stalwart's | ||
| session resource. Liveness (`/api/health/live`) does not, so a mail outage never restarts Bulwark. | ||
|
|
||
| `scripts/tests/bulwark/` pins these settings. Run `go test ./scripts/tests/bulwark/`. | ||
|
|
||
| The `apps` layer waits for Bulwark to be ready, so `stalwart.${domain}` must resolve before this | ||
| deploys: #6662's first step adds that hostname to Stalwart's route. | ||
|
|
||
| ## Check it | ||
|
|
||
| Read-only checks against production: | ||
|
|
||
| ```bash | ||
| kubectl --context oidc@prod -n bulwark get deployment bulwark | ||
| kubectl --context oidc@prod -n bulwark logs deployment/bulwark --tail 50 | ||
| ``` | ||
|
|
||
| `READY 1/1` means Bulwark started, read its config and reached Stalwart. | ||
|
|
||
| ## Update the image | ||
|
|
||
| Bulwark is pinned by tag and digest in `deployment.yaml`, and the test pins the same reference. | ||
|
|
||
| 1. Read the release notes from the current version up to the new one, for changes to settings, | ||
| `policy.json` or sign-in. | ||
| 2. Resolve the new tag's digest, the multi-platform index: | ||
|
|
||
| ```bash | ||
| crane digest ghcr.io/bulwarkmail/webmail:<version> | ||
| # or: docker buildx imagetools inspect ghcr.io/bulwarkmail/webmail:<version> | ||
| ``` | ||
|
|
||
| 3. Check the settings against the new version's source: `lib/admin/types.ts` (environment | ||
| variables and defaults), `lib/admin/organisation-policy.ts` (the session schema), | ||
| `lib/admin/paths.ts` (config and state directories) and `Dockerfile` (port, user, writable | ||
| directories). | ||
| 4. Update the image in `deployment.yaml` and in `scripts/tests/bulwark/deployment_test.go`, then | ||
| validate the manifests and run the tests. | ||
|
|
||
| ## Planned route | ||
|
|
||
| The swap step of #6662 puts Bulwark at `mail.${domain}` behind GitHub SSO, like the platform's | ||
| other SSO-gated apps (for example `budget.${domain}`): | ||
|
|
||
| - An HTTPRoute in `bulwark` for `mail.${domain}` sends traffic to the `oauth2-proxy` Service. It | ||
| needs an entry in oauth2-proxy's ReferenceGrant and stays DNS-only. | ||
| - The auth-proxy routes the host to the `bulwark` Service and needs an egress rule to it. | ||
| - Bulwark's network policy then admits ingress on 3000 from the auth-proxy pods only, not from | ||
| the Gateway, so the SSO step cannot be bypassed. | ||
| - `TRUSTED_PROXY_DEPTH` is checked against that proxy chain. | ||
| - The SSO cookie's `__Host-` prefix lands before this route. | ||
|
|
||
| ## Limits | ||
|
|
||
| From [Bulwark's sign-out times](https://bulwarkmail.org/docs/guides/organisation/sessions): | ||
|
|
||
| - The browser enforces both session limits. The server also refuses to restore or renew a | ||
| session older than 12 hours, but Stalwart's own token lifetimes are separate. | ||
| - A sign-out after a limit does not end a sign-in session at the identity provider. If Stalwart | ||
| keeps one, the same browser can sign in again without the password while it lasts. |
46 changes: 46 additions & 0 deletions
46
k8s/providers/hetzner/apps/bulwark/cilium-network-policy.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| # Bulwark's server reaches exactly one place: Stalwart's web side at | ||
| # stalwart.${domain} on 443, for its readiness check, the OAuth token exchange | ||
| # and server-side JMAP. Browsers call Stalwart directly; this policy is about | ||
| # the pod. Everything else, including the telemetry, update check and other | ||
| # outside hosts that NO_THIRD_PARTY_TRAFFIC already turns off, stays blocked. | ||
| # | ||
| # No ingress is admitted yet: nothing routes to Bulwark until #6662's swap | ||
| # step. That step serves it behind GitHub SSO, so its requests will come from | ||
| # the oauth2-proxy namespace's auth-proxy pods, not straight from the Gateway, | ||
| # and the ingress rule added then must name those pods. | ||
| # | ||
| # DNS carries an L7 rule so the toFQDNs rule can learn Stalwart's addresses. | ||
| # The image resolves names with musl, which stops at the first refused answer, | ||
| # so the cluster search-domain lookups tried before the public name are | ||
| # allowed too, as for the mail server itself. | ||
| apiVersion: cilium.io/v2 | ||
| kind: CiliumNetworkPolicy | ||
| metadata: | ||
| name: allow-bulwark | ||
| namespace: bulwark | ||
| spec: | ||
| endpointSelector: | ||
| matchLabels: | ||
| k8s:app.kubernetes.io/name: bulwark | ||
| k8s:app.kubernetes.io/instance: bulwark | ||
| egress: | ||
| - toFQDNs: | ||
| - matchName: stalwart.${domain} | ||
| toPorts: | ||
| - ports: | ||
| - port: "443" | ||
| protocol: TCP | ||
| - toEndpoints: | ||
| - matchLabels: | ||
| k8s:io.kubernetes.pod.namespace: kube-system | ||
| k8s-app: kube-dns | ||
| toPorts: | ||
| - ports: | ||
| - port: "53" | ||
| protocol: UDP | ||
| - port: "53" | ||
| protocol: TCP | ||
| rules: | ||
| dns: | ||
| - matchName: stalwart.${domain} | ||
| - matchPattern: "*.cluster.local" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # Bulwark's admin config directory, mounted read-only (ADMIN_CONFIG_READONLY), | ||
| # so nothing changes it but a reviewed commit. Settings Bulwark also reads from | ||
| # the environment live in deployment.yaml. | ||
| # | ||
| # config.json: the setup wizard counts as done, so it never opens. | ||
| # | ||
| # policy.json: the maintainer's session limits (#6662), in the schema of | ||
| # Bulwark 1.22.0 (lib/admin/organisation-policy.ts; bulwarkmail.org | ||
| # docs/guides/organisation/sessions): signed out after 15 minutes without | ||
| # activity and 12 hours after signing in, with the default 60-second warning. | ||
| # The browser enforces both; the server also refuses to restore or renew a | ||
| # session older than 12 hours. Every other policy key keeps its default. | ||
| apiVersion: v1 | ||
| kind: ConfigMap | ||
| metadata: | ||
| name: bulwark-admin-config | ||
| namespace: bulwark | ||
| data: | ||
| config.json: | | ||
| { | ||
| "setupComplete": true | ||
| } | ||
| policy.json: | | ||
| { | ||
| "organisation": { | ||
| "session": { | ||
| "idleMinutes": 15, | ||
| "maxHours": 12, | ||
| "warnSeconds": 60 | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,185 @@ | ||
| # Bulwark 1.22.0, the webmail for the company mailbox (#6662), launched dark: | ||
| # no route reaches it until #6662's swap step puts it at mail.${domain} behind | ||
| # GitHub SSO. See docs/operations/bulwark.md. | ||
| # | ||
| # Settings, verified against the Bulwark source at 1.22.0 (lib/admin/types.ts, | ||
| # lib/admin/paths.ts, lib/admin/stalwart-admin-access.ts): | ||
| # - JMAP_SERVER_URL: Stalwart's web side. Browsers call it directly; the | ||
| # route there allows Bulwark's origin. | ||
| # - OAUTH_ENABLED, OAUTH_ONLY, OAUTH_CLIENT_ID: the mailbox sign-in is only | ||
| # Stalwart's own OAuth login (a PKCE public client, no client secret), so the | ||
| # mail password and two-factor code are typed on Stalwart's page. | ||
| # - NO_THIRD_PARTY_TRAFFIC: every built-in outside host is off (telemetry, | ||
| # update check, push relay, extension directory, connector, sender favicons, | ||
| # translation, maps links, WKD) and plugins that need the network don't run. | ||
| # - STALWART_FEATURES=false: none of the Stalwart-specific account screens. | ||
| # - STALWART_ADMIN_ACCESS=off, and no ADMIN_PASSWORD: a Stalwart administrator | ||
| # gets no Bulwark admin rights, and with no admin password Bulwark's own | ||
| # admin dashboard stays disabled (lib/admin/password.ts). Bulwark asks for a | ||
| # password only when the dashboard itself restricts admin access. | ||
| # - SESSION_SECRET_FILE: the generated session secret, read from a file so it | ||
| # never enters the environment (external-secret.yaml). | ||
| # - ADMIN_CONFIG_READONLY, ADMIN_CONFIG_DIR, ADMIN_STATE_DIR: the admin config | ||
| # is the read-only ConfigMap; runtime state goes to the scratch volume. The | ||
| # state directory is named explicitly because, with only the config | ||
| # directory set, Bulwark would put it inside that read-only mount. | ||
| # - LOGIN_SHOW_REMEMBER_ME, BROWSER_SESSION_SIGN_IN: "remember me" is offered | ||
| # and off unless ticked; an unticked sign-in lasts until the browser closes. | ||
| # The idle and maximum session limits are in the ConfigMap's policy.json. | ||
| # - TRUSTED_PROXY_DEPTH=1: sign-in limits key on the address one proxy back. | ||
| # - HOSTNAME: Next.js listens on this address; Kubernetes otherwise sets it to | ||
| # the pod's name. | ||
| # | ||
| # One replica: without a shared store (Valkey), sessions, sign-in limits and | ||
| # admin state are per pod. | ||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| name: bulwark | ||
| namespace: bulwark | ||
| labels: | ||
| app.kubernetes.io/name: bulwark | ||
| app.kubernetes.io/instance: bulwark | ||
| platform.devantler.tech/replica-floor: exempt | ||
| spec: | ||
| replicas: 1 | ||
| strategy: | ||
| type: RollingUpdate | ||
| rollingUpdate: | ||
| maxSurge: 1 | ||
| maxUnavailable: 0 | ||
| selector: | ||
| matchLabels: | ||
| app.kubernetes.io/name: bulwark | ||
| app.kubernetes.io/instance: bulwark | ||
| template: | ||
| metadata: | ||
| labels: | ||
| app.kubernetes.io/name: bulwark | ||
| app.kubernetes.io/instance: bulwark | ||
| spec: | ||
| serviceAccountName: bulwark | ||
| automountServiceAccountToken: false | ||
| # The image's own user is 1001, but it runs as any user: the app files | ||
| # are root's and read-only, and everything it writes is on the volumes | ||
| # below. A UID above 10000 keeps clear of host accounts. | ||
| securityContext: | ||
| runAsNonRoot: true | ||
| runAsUser: 65532 | ||
| runAsGroup: 65532 | ||
| fsGroup: 65532 | ||
| seccompProfile: | ||
| type: RuntimeDefault | ||
| containers: | ||
| - name: bulwark | ||
| image: ghcr.io/bulwarkmail/webmail:1.22.0@sha256:d02b77b4dea0607dafcd2592a6d89d481b8dd400e4b2b72f5a4466972dc4c5a8 | ||
| imagePullPolicy: IfNotPresent | ||
| env: | ||
| - name: HOSTNAME | ||
| value: 0.0.0.0 | ||
| - name: JMAP_SERVER_URL | ||
| value: https://stalwart.${domain} | ||
| - name: OAUTH_ENABLED | ||
| value: "true" | ||
| - name: OAUTH_ONLY | ||
| value: "true" | ||
| - name: OAUTH_CLIENT_ID | ||
| value: bulwark | ||
| - name: NO_THIRD_PARTY_TRAFFIC | ||
| value: "true" | ||
| - name: STALWART_FEATURES | ||
| value: "false" | ||
| - name: STALWART_ADMIN_ACCESS | ||
| value: "off" | ||
| - name: ADMIN_CONFIG_READONLY | ||
| value: "true" | ||
| - name: ADMIN_CONFIG_DIR | ||
| value: /app/data/admin | ||
| - name: ADMIN_STATE_DIR | ||
| value: /app/data/admin-state | ||
| - name: LOGIN_SHOW_REMEMBER_ME | ||
| value: "true" | ||
| - name: BROWSER_SESSION_SIGN_IN | ||
| value: "true" | ||
| - name: TRUSTED_PROXY_DEPTH | ||
| value: "1" | ||
| - name: SESSION_SECRET_FILE | ||
| value: /etc/bulwark/session/session-secret | ||
| ports: | ||
| - name: http | ||
| containerPort: 3000 | ||
| protocol: TCP | ||
| # Live only says the process answers. Ready also needs the config, | ||
| # writable data directories and an answer from Stalwart's session | ||
| # resource within 2 seconds, so the probe allows longer than that. | ||
| startupProbe: | ||
| httpGet: | ||
| path: /api/health/live | ||
| port: http | ||
| periodSeconds: 2 | ||
| failureThreshold: 60 | ||
| livenessProbe: | ||
| httpGet: | ||
| path: /api/health/live | ||
| port: http | ||
| periodSeconds: 10 | ||
| failureThreshold: 3 | ||
| readinessProbe: | ||
| httpGet: | ||
| path: /api/health/ready | ||
| port: http | ||
| timeoutSeconds: 5 | ||
| periodSeconds: 10 | ||
| failureThreshold: 3 | ||
| # Without its own CPU limit the namespace's default LimitRange would | ||
| # cap the container at 500m. | ||
| resources: | ||
| requests: | ||
| cpu: 100m | ||
| memory: 256Mi | ||
| limits: | ||
| cpu: 1000m | ||
| memory: 768Mi | ||
| securityContext: | ||
| runAsNonRoot: true | ||
| runAsUser: 65532 | ||
| runAsGroup: 65532 | ||
| seccompProfile: | ||
| type: RuntimeDefault | ||
| privileged: false | ||
| allowPrivilegeEscalation: false | ||
| readOnlyRootFilesystem: true | ||
| capabilities: | ||
| drop: | ||
| - ALL | ||
| volumeMounts: | ||
| # Scratch space only; nothing here needs to survive the pod. | ||
| - name: data | ||
| mountPath: /app/data | ||
| - name: admin-config | ||
| mountPath: /app/data/admin | ||
| readOnly: true | ||
| - name: next-cache | ||
| mountPath: /app/.next/cache | ||
| - name: tmp | ||
| mountPath: /tmp | ||
| - name: session | ||
| mountPath: /etc/bulwark/session | ||
| readOnly: true | ||
| volumes: | ||
| - name: data | ||
| emptyDir: {} | ||
| - name: admin-config | ||
| configMap: | ||
| name: bulwark-admin-config | ||
| - name: session | ||
| secret: | ||
| secretName: bulwark | ||
| defaultMode: 0440 | ||
| items: | ||
| - key: session-secret | ||
| path: session-secret | ||
| - name: next-cache | ||
| emptyDir: {} | ||
| - name: tmp | ||
| emptyDir: {} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # Bulwark's session secret, generated once in-cluster and never refreshed. It | ||
| # signs and encrypts remembered sign-ins and the server's record of when each | ||
| # session started, which the 12-hour maximum is checked against. Without one, | ||
| # Bulwark would generate its own on the scratch volume, and every restart would | ||
| # sign everyone out. A new one (after a rebuild) only signs everyone out once. | ||
| apiVersion: external-secrets.io/v1 | ||
| kind: ExternalSecret | ||
| metadata: | ||
| name: bulwark | ||
| namespace: bulwark | ||
| spec: | ||
| refreshInterval: "0" | ||
| target: | ||
| name: bulwark | ||
| creationPolicy: Owner | ||
| template: | ||
| engineVersion: v2 | ||
| data: | ||
| session-secret: "{{ .password }}" | ||
| dataFrom: | ||
| - sourceRef: | ||
| generatorRef: | ||
| apiVersion: generators.external-secrets.io/v1alpha1 | ||
| kind: Password | ||
| name: bulwark |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.