Repository navigation
feat(server): POST /v1/email over the SES API, no static credential - #203
Merged
Merged
Conversation
The BFF has always relayed mail through `POST /v1/email` with the operator
token (`relayEmail`), but that route did not exist in the Rust server. Every
invite and password-reset email has therefore been silently returning
`false`, with the UI falling back to handing an admin the raw link. The
reset page and `resetLink()` exist; nothing ever delivered their mail.
`er_server::mail` is the sender: three templates (`invite`,
`password_reset`, `signup_verify`), plain-text bodies assembled by
`format!`. No template engine — each template's required parameters are
declared in exactly one place, so a missing one is a 422 the caller sees
rather than a blank in a message someone already received. Rendering runs
before the backend is consulted, so a typo'd template is reported as the
caller's bug in every environment, including those with mail switched off.
Sending is synchronous, with no outbox and no retry. The Python design this
replaces had a durable `email_outbox` drained by the dispatcher's leader
tick; that is deliberately not what shipped, because the relay already
treats failure as data and every caller has a usable fallback. An outbox
would add a table, a drain loop and a retry policy to make reliable
something no flow blocks on.
`ER_MAIL_BACKEND` picks the transport: `ses` sends, `log` renders to the pod
log (how a dev namespace gets its links with no AWS at all), and unset
answers 503 — which is what `relayEmail` turns into `false`, i.e. exactly
today's behaviour. A misconfigured backend degrades to 503 with a warning
rather than failing the boot.
TRANSPORT IS THE SES API, NOT SMTP, and that inverts infrastructure.md
§9.3. The SMTP interface cannot accept credentials derived from temporary
ones, which was the entire reason §9.3 budgeted a second long-lived IAM
access key and then scheduled its retirement for Phase 4. Writing the Rust
sender fresh rather than porting it made that exit cheaper than the thing it
was scheduled to undo: `SendEmail` is signed by the pod's EKS Pod Identity
credentials, so the key was never created. §8.1's "one long-lived key" claim
now needs no amendment for email, and open question 17 is resolved.
Two dependency decisions, both `default-features = false`:
* `default-https-client` resolves TLS to aws-lc-rs, whose `-sys` crate
needs cmake the `rust:1-bookworm` build image does not carry. An
explicit ring-backed client is passed instead — the same provider
reqwest already uses, so the image links one crypto library.
* `sso`/`credentials-process` pull providers the server cannot use; it
authenticates by Pod Identity, which is in the base chain.
The workspace rust-version moves 1.85 -> 1.88. Not taste: the AWS SDK
depends on `time`, 0.3.45 carries RUSTSEC-2026-0009 (stack exhaustion
parsing RFC 2822), and the first patched release needs 1.88 — so declaring
1.85 was what pinned cargo's resolver to the vulnerable version. Nothing
verifies the floor downward (rust-toolchain.toml, every CI job and the image
all use stable), and a higher floor lets the resolver pick safer versions.
cargo-deny is clean.
Infra: `modules/ses` (domain identity + Easy DKIM, custom MAIL FROM with
behavior_on_mx_failure = REJECT_MESSAGE, a configuration set requiring TLS
on delivery with bounce/complaint suppression) and `envs/dev/ses.tf` (a role
carrying a SendEmail policy scoped to the identity and to a From address at
the domain, bound by Pod Identity association). DNS is outputs, not
resources — the zone is Cloudflare's. `mail_pod_namespaces` is empty by
default and explicitly listed, because a Pod Identity association binds one
namespace and dev namespaces are per-developer and not Terraform's.
Still manual, and both block real delivery: publish the DKIM/MAIL FROM
records, and file the SES production-access request (~24h).
Also replaces the dead Python-era `ERSERVER_EMAIL_FROM`/`_BASE_URL` chart
values and the `ERSERVER_SMTP_URL` secret, none of which any Rust code read.
BASE_URL in particular implied the server builds links, which it does not —
every link arrives fully formed in the request's params.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Mechanical consequence of the MSRV bump in the parent commit, separated so
that commit stays about email. Clippy suppresses lints whose suggestion
needs a language feature the declared rust-version does not have; at 1.88
`collapsible_if` starts proposing let-chains, so
if a { if let Some(x) = b { .. } }
becomes
if a && let Some(x) = b { .. }
14 sites across er-entity-diff, er-entity-gen, er-golden, er-match,
er-reconcile, er-server and er-sql-check — none of which the email change
touched. Applied by `cargo clippy --fix --allow-no-vcs --workspace
--all-targets` and then `cargo fmt --all`, which the fix pass does not do
for itself. Short-circuit semantics are identical in both directions
(`if A { if let .. }` and `if let .. { if B }`), so this is a reindent plus
a flattened condition and nothing else.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
athvin
force-pushed
the
feat/ses-email
branch
from
October 20, 2026 06:01
2eb65bd to
975a31a
Compare
athvin
pushed a commit
that referenced
this pull request
Oct 20, 2026
Supersedes #191, #192, #193, #197, #198, #199, #200. Three sibling dependabot PRs are NOT included because they cannot resolve — see below. CI actions: - sccache-action 0.0.9 -> 0.0.11 (5 call sites in rust.yml) - taiki-e/install-action 2.87.28 -> 2.87.29 Rust (#193 rust-minor-patch group, #197): - duckdb 1.10505.0 -> 1.10506.1 (exact pin), tokio -> 1.54.0, unicode-normalization -> 0.1.26 - rand 0.9 -> 0.10 rand 0.10 renamed the core trait: `RngCore` is gone from the crate root and `Rng` now carries `fill_bytes` (the old extension trait became `RngExt`). Two sites broke, both minting secrets — the API-key secret in `pg.rs` and the webhook HMAC secret in `lib.rs`. Both are `use rand::RngCore` -> `use rand::Rng`; the RNG itself is unchanged. Verified against rand 0.10.3's source that `ThreadRng` is still ChaCha12-backed and `TryCryptoRng`, so the cryptographic property these two secrets depend on is preserved. Frontend (#198 group of 22, #199, #200): - next 16.3.8 -> 16.4.2, react/react-dom 19.3.0 -> 19.3.1, eslint -> 10.13.0, zod -> 4.6.7, @anthropic-ai/sdk -> 0.135.0, lucide-react -> 1.58.0 and the rest of the minor-patch group - motion 13.4.4 -> 14.3.0, @testing-library/jest-dom ^6.9.1 -> ^7.0.1 `@playwright/test` stays pinned at 1.63.0 (it must equal the docker tag) and `typescript` stays at `5.x`; neither was in any of the bumps. Not included, both blocked on an external pin rather than on anything here: - #195 arrow 58 -> 59. The `duckdb` crate depends on arrow 58.4.0 even at 1.10506.1, and DuckDB's Arrow batches ARE the workspace Arrow type — e.g. er-entities returns `::duckdb::Result<Vec<::arrow::record_batch::RecordBatch>>`. Putting the workspace on 59 while duckdb emits 58 stops that type-checking; pr/195's own lock resolves three arrow versions (57.3.1/58.4.0/59.3.1). Needs `duckdb` on arrow 59 first. - #194 / #196 datafusion-common and datafusion-expr 52 -> 55. er-sql-check depends on both datafusion and `ff-analysis`, and feather-flow (git tag er-entity-v0.1.4) pins `datafusion-* = "52"`, a caret requirement that cannot unify with 55. Needs a feather-flow tag on datafusion 55 first. No MSRV change is needed: duckdb 1.10506.1 declares rust-version 1.88, and #203 already raised the workspace to 1.88 (with the 10 let-chain rewrites clippy then asks for, across er-sql-check, er-golden, er-eval and er-entity-gen). This branch leaves that line alone. Rebased onto #207, which fixes the runner disk exhaustion that had the `test` job failing on main since #188 — unrelated to these bumps and reproducible on main with duckdb 1.10505.0. Verified locally: frontend `pnpm check` 164 unit tests pass and a fresh-server e2e run is 324 passed; `make check` 263 tests pass with no genuine failures. Note that `make frontend` runs `test:e2e` rather than `test:e2e:fresh`, so it can adopt a stale server and report phantom failures — clean main does the same, with a different set of grow.spec.ts tests failing each run. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
athvin
pushed a commit
that referenced
this pull request
Oct 20, 2026
Supersedes #191, #192, #193, #197, #198, #199, #200. Three sibling dependabot PRs are NOT included because they cannot resolve — see below. CI actions: - sccache-action 0.0.9 -> 0.0.11 (5 call sites in rust.yml) - taiki-e/install-action 2.87.28 -> 2.87.29 Rust (#193 rust-minor-patch group, #197): - duckdb 1.10505.0 -> 1.10506.1 (exact pin), tokio -> 1.54.0, unicode-normalization -> 0.1.26 - rand 0.9 -> 0.10 rand 0.10 renamed the core trait: `RngCore` is gone from the crate root and `Rng` now carries `fill_bytes` (the old extension trait became `RngExt`). Two sites broke, both minting secrets — the API-key secret in `pg.rs` and the webhook HMAC secret in `lib.rs`. Both are `use rand::RngCore` -> `use rand::Rng`; the RNG itself is unchanged. Verified against rand 0.10.3's source that `ThreadRng` is still ChaCha12-backed and `TryCryptoRng`, so the cryptographic property these two secrets depend on is preserved. Frontend (#198 group of 22, #199, #200): - next 16.3.8 -> 16.4.2, react/react-dom 19.3.0 -> 19.3.1, eslint -> 10.13.0, zod -> 4.6.7, @anthropic-ai/sdk -> 0.135.0, lucide-react -> 1.58.0 and the rest of the minor-patch group - motion 13.4.4 -> 14.3.0, @testing-library/jest-dom ^6.9.1 -> ^7.0.1 @playwright/test stays pinned at 1.63.0 (it must equal the docker tag) and typescript stays at 5.x; neither was in any of the bumps. Also raises the lint and ducklake-e2e job timeouts from 30 to 45 minutes. Bumping duckdb invalidates the sccache/rust-cache, so both jobs rebuild the bundled duckdb C++ tree from scratch. On that cold run lint measured 30+ min and was cancelled mid-job with every gate already green — fmt, clippy with -D warnings, er-entity verify and rustdoc all passed, and only the step the workflow itself labels advisory (the OpenAPI breaking-change diff, which ends in `|| true`) was cut off. ducklake-e2e finished at 29 min, one minute inside the old limit. That margin was luck, and any future duckdb bump hits the same wall. Not included, both blocked on an external pin rather than on anything here: - #195 arrow 58 -> 59. The `duckdb` crate depends on arrow 58.4.0 even at 1.10506.1, and DuckDB's Arrow batches ARE the workspace Arrow type — e.g. er-entities returns `::duckdb::Result<Vec<::arrow::record_batch::RecordBatch>>`. Putting the workspace on 59 while duckdb emits 58 stops that type-checking; pr/195's own lock resolves three arrow versions (57.3.1/58.4.0/59.3.1). Needs `duckdb` on arrow 59 first. - #194 / #196 datafusion-common and datafusion-expr 52 -> 55. er-sql-check depends on both datafusion and `ff-analysis`, and feather-flow (git tag er-entity-v0.1.4) pins `datafusion-* = "52"`, a caret requirement that cannot unify with 55. Needs a feather-flow tag on datafusion 55 first. No MSRV change is needed: duckdb 1.10506.1 declares rust-version 1.88, and #203 already raised the workspace to 1.88 along with the 10 let-chain rewrites clippy then asks for. This branch leaves that line alone. Rebased onto #207, which fixes the runner disk exhaustion that had the `test` job failing on main since #188 — unrelated to these bumps and reproducible on main with duckdb 1.10505.0. Verified: CI green on the previous push for test, DuckLake e2e, cargo-deny, semgrep, pnpm audit, frontend lint/types/unit and the playwright tier. Locally, frontend `pnpm check` passes 164 unit tests and a fresh-server e2e run is 324 passed. Note that `make frontend` runs `test:e2e` rather than `test:e2e:fresh`, so it can adopt a stale server and report phantom failures — clean main does the same, with a different set of grow.spec.ts tests failing each run. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This was referenced Oct 20, 2026
athvin
added a commit
that referenced
this pull request
Oct 23, 2026
…er cannot answer (#306) `POST /v1/email` has existed since #203 and `AppState.mail` had exactly one caller: the `operator_only` send route. There was no dispatcher-side mailer at all, so nothing the engine did could ever reach a human by mail. The plan asked "which org members get a report". That has no answer in this process, and the absence is the finding rather than a gap to paper over: membership lives in the FRONTEND's database, so the process that knows a run finished has no user roster. Inventing a cross-store read for a notification would be a far worse trade than asking an operator for addresses. So recipients are an explicit list in the org's `env` under `ER_RUN_REPORT_TO` — the channel the dispatcher already reads nine `ER_*` keys from — and its ABSENCE is the opt-out. A tenant who never asked for mail does not get any because a run happened to finish. The mailer is built by `dispatch_once` from env and passed into `dispatch_once_with`, mirroring exactly how `Profile::from_env()` is injected so tests supply their own rather than depending on the runner's environment. The report rides the same settle as the `job.*` webhook and obeys the rule the comment there already states: one per OUTCOME, not per attempt. A job that fails twice and then succeeds is one success, and three notifications for one incident is how an integration learns to ignore them. A send that fails is logged and dropped — mail is best-effort by design, and reporting an outcome is not part of producing it. Reported kinds are a decision, not a default: run_all_full, run_all_incremental, correct, train — the ones whose outcome a steward waits on. `lake_maintain` is platform housekeeping a tenant cannot act on, and `provision` is already polled by the tenant-create UI with a progress indicator; mailing either teaches a recipient to filter the whole thread. Both still emit webhooks and still appear in the runs list. The whole decision is one pure function so every rule is testable without a mailer, a Postgres or a job — each branch is something someone will want to change later. Observed failing two ways: reporting every kind fails `housekeeping_kinds_are_not_reported`, and dropping the blank-address filter fails `absence_is_the_opt_out`, because configured-but-blank must send nothing rather than mail an empty address. A success report carries the O3c entity counts; a failure carries `error_detail`, which is already chain-flattened so it reads as a sentence rather than the outermost wrapper's Display. The two `dispatch_once_with` test call sites pass `Mailer::off()` deliberately: their orgs configure no recipients, so a mailer that CANNOT send turns a stray report into a logged error instead of a silent success. Verifiable without V0 — `ER_MAIL_BACKEND=log` renders to the server log, so only real delivery waits on an SES identity. Verified: `make check` green (165 suites), and `pg_provision` + `pg_entity_events` green against the test Postgres, which `make check` self-skips. Co-authored-by: bmoore813 <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why
The BFF has always relayed mail through
POST /v1/emailwith the operator token (relayEmail,frontend/src/lib/bff/relay.ts) — and the Rust server never had that route. Every member invite and every password reset has therefore been silently returningfalsesince the Python server was deleted, with the UI falling back to handing an admin the raw link. The/reset/{token}page andresetLink()both exist; nothing ever delivered their mail.Verify-by-email self-serve signup is blocked on this, which is why it comes first.
What
er_server::mail+POST /v1/email, operator-only. Three templates —invite,password_reset,signup_verify— as plain-textformat!bodies. No template engine: each template's required parameters are declared in exactly one place, so a missing one is a 422 the caller sees rather than a blank in a message someone already received.Status codes are the contract, because the relay treats failure as data:
relayEmail→falsealready does)Rendering runs before the backend is consulted, so a typo'd template is reported as the caller's bug even where mail is switched off — otherwise it would stay invisible until someone enabled a backend. The recipient is deliberately kept out of the transport error log, since this path runs for password resets.
Synchronous, no outbox, no retry. The Python design had a durable
email_outboxdrained by the dispatcher's leader tick. Deliberately not rebuilt: every caller already has a usable fallback, so an outbox would add a table, a drain loop and a retry policy to make reliable something no flow blocks on. When one does, the outbox is the right answer then.ER_MAIL_BACKEND=ses|log|off.logrenders to the pod log — how a dev namespace gets its links with no AWS at all. Unset answers 503, i.e. exactly today's behaviour. A misconfigured backend degrades to 503 with a warning rather than failing the boot.The §9.3 inversion
Transport is the SES API, not SES's SMTP interface, and that reverses infrastructure.md §9.3. The SMTP endpoint cannot accept credentials derived from temporary ones — which was the entire reason §9.3 budgeted a second long-lived IAM access key and then scheduled a Phase-4 port to retire it. Because the Python mailer was deleted rather than ported, writing the Rust one straight against the API was cheaper than building the SMTP path the retirement was scheduled to undo. So that key was never created.
observability.tfsays "No IRSA" explicitly).Reviewer attention: two wider-than-email changes
1. The workspace MSRV moves 1.85 → 1.88. Forced, not chosen.
cargo denyfailed: the AWS SDK depends ontime,0.3.45carries RUSTSEC-2026-0009 (DoS via stack exhaustion parsing RFC 2822), and the first patched release —0.3.47— requires 1.88. Declaring 1.85 was exactly what pinned cargo's MSRV-aware resolver to the vulnerable version.I checked the one thing that would have avoided this:
time'sparsingfeature is enabled in our tree (cargo tree -e features -i time), so the vulnerable code really is compiled. An ignore entry would have rested on "no user-controlled RFC 2822 input reaches it" — probably true, but reasoning about reachability rather than a structural guarantee. Nothing verifies the floor downward (rust-toolchain.toml=stable, every CI job installs stable, image isrust:1-bookworm), so taking the patch was strictly better than a thirddeny.tomlignore.2. Second commit: 14 let-chain sites across seven crates the email change never touches. Clippy suppresses lints whose suggestion needs a language feature the declared rust-version lacks; at 1.88
collapsible_ifstarts proposing let-chains. Applied bycargo clippy --fixthencargo fmt, kept as its own commit so the feature stays readable. Short-circuit semantics are identical in both directions, so it is a flattened condition plus a reindent.Dependency decisions
Both aws crates are
default-features = false, deliberately:default-https-clientresolves TLS to aws-lc-rs, whose-syscrate needs cmake therust:1-bookwormbuild image does not carry — this would have broken the Docker build only. An explicit ring-backed client is passed instead, which is also what reqwest uses, so the image links one crypto library.sso/credentials-processpull providers the server cannot use (Pod Identity is the container-credentials provider, already in the base chain). Consequence worth knowing:aws sso logincredentials do not work for a locally-run er-server — useER_MAIL_BACKEND=log.Infra — written here, applied by you
infra/terraform/modules/ses/main.tf(domain identity + Easy DKIM, custom MAIL FROM withbehavior_on_mx_failure = REJECT_MESSAGE, configuration set requiring TLS on delivery with bounce/complaint suppression) andinfra/terraform/envs/dev/ses.tf(a role carrying ases:SendEmailpolicy scoped to the identity and to a From address at the domain, bound by Pod Identity association).terraform validatecaught two real errors while writing it. DNS is outputs, not resources — the zone is Cloudflare's while the provider here is AWS.Two manual steps, both of which block real delivery:
terraform output ses_verification_dns(3 DKIM CNAMEs) andses_mail_from_dns(MX + SPF) in Cloudflare.mail_pod_namespacesis empty-by-default and explicitly listed, because a Pod Identity association binds one (cluster, namespace, SA) triple with no wildcard, while dev namespaces are per-developer and created byscripts/dev_env.sh/Helm rather than Terraform.Dead config removed rather than left beside the live config
Nothing read any of it: chart values
ERSERVER_EMAIL_FROM/ERSERVER_EMAIL_BASE_URL, and theERSERVER_SMTP_URLsecret inscripts/dev_env.sh.BASE_URLwas actively misleading — it implied the server builds links, but every link arrives fully formed in the request'sparams.Verification
make check— green (exit 0, 140 test groups, 0 failures)cargo deny check— advisories ok, bans ok, licenses ok, sources ok (it failed before thetimefix)RUSTDOCFLAGS="-D warnings" cargo doc— clean (the gate that caught feat(entities): the V-rules become a lint registry (er-entity-lint) #188)helm templateby hand — renders the threeER_MAIL_*vars when configured and nothing when not, so an unconfigured environment keeps today's behaviour. No CI job lints the chart, so this was manual.terraform fmt+validate— clean🤖 Generated with Claude Code