console: SES events behind a secret path; temporary cert failures 503
Astra R2: anonymous misses could hold the cert-fetch budget a genuine notification needs, and a refused fetch answered 403, which SNS never retries. CARLOS_SES_EVENTS_TOKEN, when set, moves the ingest to /api/ses/events/<token>; the bare path or a wrong token is the unknown route's 404 before the body is read (constant-time compare). Unset keeps today's path. Busy and failed fetches now answer 503. README has the operator switch-over; parity and claim route tables updated.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
11 files changed,
+276
−13
README.md+19 −0cmd/console/main.go+1 −0docs/parity.md+1 −1internal/console/claim_invariant_fixtures_test.go+24 −0internal/console/lifetimes_cutover.go+2 −0internal/console/routedecls.go+3 −0internal/console/server.go+6 −0internal/console/sesevents.go+56 −8internal/console/sesevents_test.go+162 −3internal/console/testdata/claim-routes.txt+1 −0parity/parity.tsv+1 −1
CI failed — run details
Intent
diff --git a/README.md b/README.md| index 6c448fc4d..651f2f3b3 100644 |
| --- a/README.md |
| +++ b/README.md |
| @@ -598,6 +598,25 @@ Roll it in this order: |
| 6. apply IAM step 2. condition the role's `iam:CreateUser` and `iam:PutUserPolicy` on `iam:PermissionsBoundary` equal to the boundary ARN. do this only after every console runs this release, because an older console creates users without the boundary and step 2 refuses them. |
| 7. wait a few minutes for IAM to propagate, then run the check in step 5 again with your own operator credentials, not the console role. `iam:CreateAccessKey` cannot be conditioned on the boundary, so anyone holding the console role could have made an unbounded user between step 5 and step 2. delete any user without the boundary, or set the boundary on it. the gap is closed only when this second check is clean. |
| +### SES events on a secret path (2026-11-16) |
| + |
| +SES reports sends, bounces and complaints to the console through an SNS subscription to `POST /api/ses/events`. Anyone can post to that path, and a post naming a signing certificate the console has not seen makes it fetch one. Enough of those can use up the fetches a real notification needs after a restart or a certificate change. This release lets the path carry a secret, so only the SNS subscription can reach the code that reads the body or fetches anything. |
| + |
| +- `CARLOS_SES_EVENTS_TOKEN` is optional. unset, nothing changes: SNS keeps posting to `/api/ses/events`. |
| +- set, the console takes notifications only at `/api/ses/events/<token>`. the old path, and any other token, get the same 404 as a path that does not exist, before the console reads the body. |
| +- the token is a secret. keep it where the console's other secrets live, never in a repo, a ticket or a log. the console never logs it. |
| +- a notification whose signing certificate the console cannot fetch right now gets a 503, which SNS retries. before this release it got a 403, and SNS gives up on a 403. |
| + |
| +Switch over in a window, one console at a time: |
| + |
| +1. roll the console to this release. nothing changes yet. |
| +2. make a token: `openssl rand -hex 32`. |
| +3. set `CARLOS_SES_EVENTS_TOKEN` to it in the console's environment and restart the console. from now on it answers only the new path, so do steps 4 and 5 straight away. a notification sent in between gets a 404, and SNS does not retry a 404. |
| +4. subscribe the SES events topic (`CARLOS_MAIL_SNS_TOPIC_ARN`) to `https://<console origin>/api/ses/events/<token>` over HTTPS. the console confirms the subscription itself. check that `aws sns list-subscriptions-by-topic --topic-arn <arn>` shows the new endpoint with a subscription ARN, not `PendingConfirmation`. |
| +5. delete the old subscription to `/api/ses/events` with `aws sns unsubscribe --subscription-arn <old arn>`. |
| + |
| +The subscription is not in this repo's `infra/`. Make the change wherever the deployment's SES events topic and its subscription are managed. If that is Terraform, change the endpoint there instead of by hand, or the next apply puts the old one back. |
| + |
| ### App policies: egress allows and sizes (2026-10-25) |
| This release adds the app policy (#328, #329). A system operator can let an app's instances reach named private addresses with `carlos apps set --egress-allow`, and choose the size they run at with `carlos apps set --size` and `carlos instances set --size`. `carlos apps show` reads it back. Each app's policy is one signed object in the deployment bucket, under `control/app-policy/`. |
diff --git a/cmd/console/main.go b/cmd/console/main.go| index 2790394ab..3aca7ecad 100644 |
| --- a/cmd/console/main.go |
| +++ b/cmd/console/main.go |
| @@ -515,6 +515,7 @@ func serve() { |
| DemoAbuseAddress: demoAbuseAddress, |
| Origin: origin, |
| Keymail: envOr("CONSOLE_KEYMAIL", "https://keymail.dev"), |
| + SESEventsToken: strings.TrimSpace(os.Getenv("CARLOS_SES_EVENTS_TOKEN")), |
| Registry: envOr("CARLOS_REGISTRY", "/data/registry.db"), |
| Releases: rel, |
| AnalyticsRetentionDays: os.Getenv("CARLOS_ANALYTICS_RETENTION_DAYS"), |
diff --git a/docs/parity.md b/docs/parity.md| index a2c903b9e..46da3ad8c 100644 |
| --- a/docs/parity.md |
| +++ b/docs/parity.md |
| @@ -472,6 +472,6 @@ Discussion #742. |
| | alert-signing-key | platform | | `GET /alerts/signing-key` | The public key alert webhook receivers fetch. | |
| | legacy-apps | platform | | `GET /apps`<br>`GET /apps/{app}` | Old URLs kept as redirects into the account. | |
| | billing-webhook | platform | | `POST /billing/webhook` | Stripe calls it. | |
| -| ses-events | platform | | `POST /api/ses/events` | Amazon SES delivery events. | |
| +| ses-events | platform | | `POST /api/ses/events`<br>`POST /api/ses/events/{token}` | Amazon SES delivery events. | |
| | box-doors | platform | | `POST /api/fleet/enrol`<br>`GET /api/box/interactive/{id}`<br>`GET /api/box/runs/{id}`<br>`POST /api/fleet/replicas/{account}/{app}/{host}/coordinator`<br>`POST /api/fleet/replicas/{account}/{app}/{host}/release`<br>`POST /api/fleet/replicas/{account}/{app}/{host}/deploy` | Doors boxes and managed fleets call, not people. | |
| | plumbing | platform | `__demo-snapshot`<br>`__registry-child`<br>`__rootfs-check-probe`<br>`__rootfs-check-prepare`<br>`__cgexec`<br>`__cgprobe` | | Words the binary runs itself as, dispatched before the command switch. | |
diff --git a/internal/console/claim_invariant_fixtures_test.go b/internal/console/claim_invariant_fixtures_test.go| index dcd213d97..81cca6eae 100644 |
| --- a/internal/console/claim_invariant_fixtures_test.go |
| +++ b/internal/console/claim_invariant_fixtures_test.go |
| @@ -1510,6 +1510,30 @@ var claimFixtures = map[string]claimFixture{ |
| }, |
| }}, |
| + "route POST /api/ses/events/{token}": {door: &claimDoor{ |
| + apps: claimRefs("bab/titogo"), |
| + setup: func(t *testing.T, cx *claimCase) { |
| + cx.srv.cfg.SESEventsToken = "claim-fixture-ses-token" // the secret door (H5-M12 review 2) |
| + cx.srv.snsVerify = func(snsEnvelope) error { return nil } // the signature check's own seam |
| + cx.emailProvisioned(t) |
| + }, |
| + // The same Send through the token door, which runs the same ingest. |
| + // A Send named by the app's own IAM user: the named path writes the |
| + // app's log rows (mail_events), its per-sender count |
| + // (mail_sender_counts) and its caller-class count |
| + // (mail_caller_sends, platform mail submission Task 2), all under |
| + // bab/titogo's permit. |
| + do: func(t *testing.T, cx *claimCase) int { |
| + resp := sesPostPath(t, cx.consoleFixture, "/api/ses/events/claim-fixture-ses-token", `{"Type":"Notification","TopicArn":"arn:aws:sns:eu-west-1:1:carlos-mail",`+ |
| + `"Message":"{\"eventType\":\"Send\",\"mail\":{\"source\":\"hello@`+claimMailDomain+`\",`+ |
| + `\"messageId\":\"claim-fixture-message\",\"destination\":[\"claim@example.com\"],`+ |
| + `\"tags\":{\"ses:caller-identity\":[\"carlos-mail-bab-titogo\"]}}}",`+ |
| + `"SigningCertURL":"https://sns.eu-west-1.amazonaws.com/x.pem","Signature":"x"}`) |
| + resp.Body.Close() |
| + return resp.StatusCode |
| + }, |
| + }}, |
| + |
| // The billing webhook re-reads a subscription and writes the account's |
| // plan row and billing state (plans 6a). |
| "route POST /billing/webhook": claimNonApp("re-reads a billing subscription and writes the account's plan row, billing state and billing problems; names no app"), |
diff --git a/internal/console/lifetimes_cutover.go b/internal/console/lifetimes_cutover.go| index b81ca8b36..452045a33 100644 |
| --- a/internal/console/lifetimes_cutover.go |
| +++ b/internal/console/lifetimes_cutover.go |
| @@ -380,6 +380,8 @@ func lifetimesExempt(path string) bool { |
| switch { |
| case path == "/healthz", path == "/api/ses/events", path == lifetimesCutoverPath: |
| return true |
| + case strings.HasPrefix(path, "/api/ses/events/"): |
| + return true |
| case strings.HasPrefix(path, "/auth/"), strings.HasPrefix(path, "/static/"): |
| return true |
| case path == demoBuildStreamPath, strings.HasPrefix(path, interactive.AttachPathPrefix), strings.HasPrefix(path, interactive.RunAttachPathPrefix): |
diff --git a/internal/console/routedecls.go b/internal/console/routedecls.go| index ee2026f39..e7a8d70da 100644 |
| --- a/internal/console/routedecls.go |
| +++ b/internal/console/routedecls.go |
| @@ -401,6 +401,9 @@ var routeDecls = []routeDecl{ |
| // label-aware SigningCertURL host check, and a verified signature, |
| // all run before any field of the message is trusted. |
| {Pattern: "POST /api/ses/events", Handler: (*Server).handleSESEvents}, |
| + // The same ingest behind a secret path (Config.SESEventsToken): when |
| + // one is set, it is the only door that reads anything. |
| + {Pattern: "POST /api/ses/events/{token}", Handler: (*Server).handleSESEventsWithToken}, |
| {Pattern: "POST /api/fleet/enrol", Handler: (*Server).handleManagedEnrol}, |
| // The box door of interactive sessions (apiinteractivebox.go, rootfs |
| // apps spec §5.10): no console principal either. The box that owns a |
diff --git a/internal/console/server.go b/internal/console/server.go| index b4fd01c29..a32e7d7ce 100644 |
| --- a/internal/console/server.go |
| +++ b/internal/console/server.go |
| @@ -928,6 +928,12 @@ type Config struct { |
| // MailDeployment carries the region, the platform suffix, the DMARC rua |
| // and the SNS topic. |
| MailDeployment mail.Deployment |
| + // SESEventsToken (CARLOS_SES_EVENTS_TOKEN), when set, is the secret the |
| + // SES event ingest's path must carry: SNS posts to |
| + // /api/ses/events/<token>, and the bare /api/ses/events, or a wrong |
| + // token, is a 404 before anything is read (sesevents.go). Empty keeps |
| + // the bare path, as before. |
| + SESEventsToken string |
| // MailOperators are the addresses allowed to drive the email pause/cap |
| // door (CARLOS_MAIL_OPERATORS, apimail.go): pausing or resuming a |
| // tenant's sending, and raising its daily cap above what its tier |
diff --git a/internal/console/sesevents.go b/internal/console/sesevents.go| index b27786cd7..187e47ca7 100644 |
| --- a/internal/console/sesevents.go |
| +++ b/internal/console/sesevents.go |
| @@ -102,6 +102,7 @@ import ( |
| "crypto/rsa" |
| "crypto/sha1" |
| "crypto/sha256" |
| + "crypto/subtle" |
| "crypto/x509" |
| "encoding/base64" |
| "encoding/json" |
| @@ -303,7 +304,39 @@ func (e snsEnvelope) canonicalString() string { |
| // 200 — SNS retries non-2xx, so refusing an unknown case with a |
| // failure status would turn one unrecognised field into an unbounded |
| // retry flood against the console. |
| +// |
| +// With Config.SESEventsToken set, this bare path is a 404 before anything |
| +// is read, and SNS posts to handleSESEventsWithToken instead. |
| func (s *Server) handleSESEvents(w http.ResponseWriter, r *http.Request) { |
| + if s.cfg.SESEventsToken != "" { |
| + http.NotFound(w, r) |
| + return |
| + } |
| + s.ingestSESEvents(w, r) |
| +} |
| + |
| +// handleSESEventsWithToken is POST /api/ses/events/{token}: the ingest |
| +// behind a secret only SNS's subscription knows (H5-M12 review 2). The |
| +// signature check alone cannot keep anonymous requests from spending the |
| +// certificate-fetch budget a genuine delivery needs after a restart or a |
| +// rotation; a path nobody else can name can. No token configured, or a |
| +// wrong one, is the unknown route's 404 before the body, the envelope or |
| +// any certificate is touched. The token is compared in constant time, as |
| +// fixed-length digests so its length does not show either, and never |
| +// logged. |
| +func (s *Server) handleSESEventsWithToken(w http.ResponseWriter, r *http.Request) { |
| + want := s.cfg.SESEventsToken |
| + got := sha256.Sum256([]byte(r.PathValue("token"))) |
| + exp := sha256.Sum256([]byte(want)) |
| + if want == "" || subtle.ConstantTimeCompare(got[:], exp[:]) != 1 { |
| + http.NotFound(w, r) |
| + return |
| + } |
| + s.ingestSESEvents(w, r) |
| +} |
| + |
| +// ingestSESEvents is the ingest itself, behind whichever door is open. |
| +func (s *Server) ingestSESEvents(w http.ResponseWriter, r *http.Request) { |
| // 1. Bound the body first. |
| r.Body = http.MaxBytesReader(w, r.Body, sesEventMaxBody) |
| body, err := io.ReadAll(r.Body) |
| @@ -356,6 +389,14 @@ func (s *Server) handleSESEvents(w http.ResponseWriter, r *http.Request) { |
| verify = func(e snsEnvelope) error { return s.verifySNSSignature(r.Context(), e) } |
| } |
| if err := verify(env); err != nil { |
| + // A certificate not to be had right now is a retry, not a verdict: |
| + // SNS retries only 429 and 5xx, and treats any other 4xx as final, |
| + // so a 403 here would lose a genuine bounce or complaint for good. |
| + if errors.Is(err, errSNSCertUnavailable) { |
| + log.Printf("console: ses events: signing certificate unavailable: %v", err) |
| + jsonError(w, http.StatusServiceUnavailable, "signing certificate unavailable; retry later") |
| + return |
| + } |
| log.Printf("console: ses events: signature verification failed: %v", err) |
| jsonError(w, http.StatusForbidden, "signature verification failed") |
| return |
| @@ -733,9 +774,11 @@ func (s *Server) confirmSNSSubscription(ctx context.Context, subscribeURL string |
| // and the failures remembered are bounded too; and the door as a whole |
| // starts at most snsCertFetchesPerMinute fetches a minute and holds at most |
| // snsCertFetchesInFlight at once, refusing past either without fetching. |
| -// A genuine message whose certificate is cached never fetches, so an |
| -// attacker filling these windows delays only a certificate rotation, and |
| -// SNS retries a refused delivery. |
| +// A genuine message whose certificate is cached never fetches. One that |
| +// needs a fetch it cannot have right now answers 503 (errSNSCertUnavailable), |
| +// which SNS retries; it treats 403 and every other 4xx but 429 as final. And |
| +// with Config.SESEventsToken set, an anonymous request never reaches here, |
| +// so these windows are SNS's own. |
| // |
| // A value type with a nil-safe zero value on purpose: Server embeds one |
| // directly (no constructor call needed), the same way ceClientOnce |
| @@ -782,8 +825,13 @@ const ( |
| snsCertBackoffMax = 15 * time.Minute |
| ) |
| +// errSNSCertUnavailable marks a signing certificate that cannot be had right |
| +// now (a refusal past the fetch limits, a failed or refused fetch): the |
| +// delivery is answered 503, so SNS tries again later, never 403. |
| +var errSNSCertUnavailable = errors.New("sns: signing cert unavailable") |
| + |
| // errSNSCertBusy refuses a miss past the door's fetch limits, unfetched. |
| -var errSNSCertBusy = errors.New("sns: signing cert fetches over their limit; not fetched") |
| +var errSNSCertBusy = fmt.Errorf("%w: fetches over their limit; not fetched", errSNSCertUnavailable) |
| func (c *snsCertCache) clock() time.Time { |
| if c.now != nil { |
| @@ -868,7 +916,7 @@ func (c *snsCertCache) key(ctx context.Context, certURL string, fetch func(conte |
| case <-call.done: |
| return call.pub, call.err |
| case <-ctx.Done(): |
| - return nil, ctx.Err() |
| + return nil, fmt.Errorf("%w: %v", errSNSCertUnavailable, ctx.Err()) |
| } |
| } |
| kept := c.started[:0] |
| @@ -1020,15 +1068,15 @@ func fetchVerifiedCertKey(ctx context.Context, certURL string) (*rsa.PublicKey, |
| } |
| resp, err := snsFetchClient.Do(req) |
| if err != nil { |
| - return nil, fmt.Errorf("sns: fetching signing cert: %w", err) |
| + return nil, fmt.Errorf("%w: fetching: %v", errSNSCertUnavailable, err) |
| } |
| defer resp.Body.Close() |
| if resp.StatusCode != http.StatusOK { |
| - return nil, fmt.Errorf("sns: signing cert fetch status %d", resp.StatusCode) |
| + return nil, fmt.Errorf("%w: fetch status %d", errSNSCertUnavailable, resp.StatusCode) |
| } |
| certPEM, err := io.ReadAll(io.LimitReader(resp.Body, sesCertMaxBody)) |
| if err != nil { |
| - return nil, fmt.Errorf("sns: reading signing cert: %w", err) |
| + return nil, fmt.Errorf("%w: reading: %v", errSNSCertUnavailable, err) |
| } |
| block, _ := pem.Decode(certPEM) |
| if block == nil { |
diff --git a/internal/console/sesevents_test.go b/internal/console/sesevents_test.go| index 1fea8107b..f69783947 100644 |
| --- a/internal/console/sesevents_test.go |
| +++ b/internal/console/sesevents_test.go |
| @@ -27,6 +27,7 @@ import ( |
| "encoding/pem" |
| "errors" |
| "fmt" |
| + "io" |
| "log" |
| "math/big" |
| "net" |
| @@ -158,7 +159,13 @@ func TestSigningCertURLPinsToConfiguredRegionExactly(t *testing.T) { |
| // sesPost drives the ingest endpoint the way SNS would. |
| func sesPost(t *testing.T, fx *consoleFixture, body string) *http.Response { |
| t.Helper() |
| - req, err := http.NewRequest(http.MethodPost, fx.ts.URL+"/api/ses/events", strings.NewReader(body)) |
| + return sesPostPath(t, fx, "/api/ses/events", body) |
| +} |
| + |
| +// sesPostPath is sesPost to path (the token door, say). |
| +func sesPostPath(t *testing.T, fx *consoleFixture, path, body string) *http.Response { |
| + t.Helper() |
| + req, err := http.NewRequest(http.MethodPost, fx.ts.URL+path, strings.NewReader(body)) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -795,8 +802,10 @@ func TestSNSCertFetchesAreCapped(t *testing.T) { |
| }) |
| resp := sesPost(t, fx, string(env)) |
| resp.Body.Close() |
| - if resp.StatusCode != http.StatusForbidden { |
| - t.Fatalf("request %d = %d, want 403", i, resp.StatusCode) |
| + // 403 for a fetched certificate the bogus signature fails; 503, |
| + // which SNS retries, past the fetch limits. |
| + if resp.StatusCode != http.StatusForbidden && resp.StatusCode != http.StatusServiceUnavailable { |
| + t.Fatalf("request %d = %d, want 403 or 503", i, resp.StatusCode) |
| } |
| } |
| if got := fetches.Load(); got > snsCertFetchesPerMinute { |
| @@ -892,6 +901,156 @@ func TestSNSCertMissesCoalesce(t *testing.T) { |
| } |
| } |
| +// ---- the secret ingest door (H5-M12 review 2) ----------------------------- |
| + |
| +const sesTestToken = "a-test-ses-events-token-0123456789abcdef" |
| + |
| +// signedSNS is a Notification on fx's topic, signed with key for certURL. |
| +func signedSNS(t *testing.T, fx *consoleFixture, key *rsa.PrivateKey, certURL string) string { |
| + t.Helper() |
| + env := snsEnvelope{ |
| + Type: "Notification", MessageID: "legit-1", TopicArn: fx.srv.cfg.MailDeployment.SNSTopicARN, |
| + Message: "{}", Timestamp: "2026-11-16T00:00:00Z", SignatureVersion: "1", SigningCertURL: certURL, |
| + } |
| + sum := sha1.Sum([]byte(env.canonicalString())) |
| + sig, err := rsa.SignPKCS1v15(rand.Reader, key, crypto.SHA1, sum[:]) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + env.Signature = base64.StdEncoding.EncodeToString(sig) |
| + b, _ := json.Marshal(env) |
| + return string(b) |
| +} |
| + |
| +// sesTokenFixture is a console on topic carlos-mail in eu-west-1 with the |
| +// ingest token set (or not), and a hijacked SNS host serving a signing |
| +// certificate whose key it returns. Fetches are counted. |
| +func sesTokenFixture(t *testing.T, token string) (*consoleFixture, *rsa.PrivateKey, *atomic.Int64) { |
| + t.Helper() |
| + fx := newConsoleFixture(t) |
| + fx.srv.cfg.MailDeployment.SNSTopicARN = "arn:aws:sns:eu-west-1:1:carlos-mail" |
| + fx.srv.cfg.MailDeployment.Region = "eu-west-1" |
| + fx.srv.cfg.SESEventsToken = token |
| + tlsDER, tlsLeaf, tlsKey := genLeafCert(t, "sns.eu-west-1.amazonaws.com") |
| + pemDER, _, signKey := genLeafCert(t, snsCertDNSName) |
| + certPEM := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: pemDER}) |
| + var fetches atomic.Int64 |
| + ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + fetches.Add(1) |
| + w.Write(certPEM) |
| + })) |
| + ts.TLS = &tls.Config{Certificates: []tls.Certificate{{Certificate: [][]byte{tlsDER}, PrivateKey: tlsKey}}} |
| + ts.StartTLS() |
| + t.Cleanup(ts.Close) |
| + hijackFetchClient(t, ts.Listener.Addr().String(), tlsLeaf) |
| + return fx, signKey, &fetches |
| +} |
| + |
| +// No token configured: the bare path ingests as before, and a token path is |
| +// the unknown route's 404. |
| +func TestSESEventsWithoutATokenKeepsTheBarePath(t *testing.T) { |
| + fx, key, fetches := sesTokenFixture(t, "") |
| + resp := sesPost(t, fx, signedSNS(t, fx, key, snsCertPath(1))) |
| + resp.Body.Close() |
| + if resp.StatusCode != http.StatusOK || fetches.Load() != 1 { |
| + t.Fatalf("bare path, no token = %d after %d fetches; want 200 after 1", resp.StatusCode, fetches.Load()) |
| + } |
| + resp = sesPostPath(t, fx, "/api/ses/events/anything", signedSNS(t, fx, key, snsCertPath(1))) |
| + resp.Body.Close() |
| + if resp.StatusCode != http.StatusNotFound { |
| + t.Fatalf("token path with no token configured = %d, want 404", resp.StatusCode) |
| + } |
| +} |
| + |
| +// With a token: the bare path and a wrong token are 404 before anything is |
| +// read (a malformed body would otherwise be a 400) and fetch nothing; the |
| +// right token ingests. |
| +func TestSESEventsTokenDoorRefusesUnreadAndUnfetched(t *testing.T) { |
| + fx, key, fetches := sesTokenFixture(t, sesTestToken) |
| + unknown := sesPostPath(t, fx, "/no/such/route", "x") |
| + want, _ := io.ReadAll(unknown.Body) |
| + unknown.Body.Close() |
| + for _, path := range []string{ |
| + "/api/ses/events", |
| + "/api/ses/events/" + sesTestToken[:len(sesTestToken)-1], |
| + "/api/ses/events/" + sesTestToken + "x", |
| + "/api/ses/events/x", |
| + } { |
| + for _, body := range []string{"{not json", signedSNS(t, fx, key, snsCertPath(2))} { |
| + resp := sesPostPath(t, fx, path, body) |
| + got, _ := io.ReadAll(resp.Body) |
| + resp.Body.Close() |
| + if resp.StatusCode != http.StatusNotFound || string(got) != string(want) { |
| + t.Fatalf("POST %s = %d %q; want the unknown route's 404 %q", path, resp.StatusCode, got, want) |
| + } |
| + } |
| + } |
| + if n := fetches.Load(); n != 0 { |
| + t.Fatalf("refused requests made %d certificate fetches, want 0", n) |
| + } |
| + resp := sesPostPath(t, fx, "/api/ses/events/"+sesTestToken, signedSNS(t, fx, key, snsCertPath(2))) |
| + resp.Body.Close() |
| + if resp.StatusCode != http.StatusOK { |
| + t.Fatalf("the right token = %d, want 200", resp.StatusCode) |
| + } |
| +} |
| + |
| +// A genuine delivery that needs a certificate the console has never fetched |
| +// gets through while anonymous requests flood the door's other paths. |
| +func TestSESEventsColdCacheDeliveryUnderAFlood(t *testing.T) { |
| + fx, key, fetches := sesTokenFixture(t, sesTestToken) |
| + stop := make(chan struct{}) |
| + var wg sync.WaitGroup |
| + for g := 0; g < 8; g++ { |
| + wg.Add(1) |
| + go func() { |
| + defer wg.Done() |
| + for i := 0; ; i++ { |
| + select { |
| + case <-stop: |
| + return |
| + default: |
| + } |
| + body := `{"Type":"Notification","TopicArn":"arn:aws:sns:eu-west-1:1:carlos-mail","Message":"{}","Signature":"Ym9ndXM=","SigningCertURL":"` + snsCertPath(1000*g+i) + `"}` |
| + for _, path := range []string{"/api/ses/events", "/api/ses/events/guess-" + fmt.Sprint(i)} { |
| + req, _ := http.NewRequest(http.MethodPost, fx.ts.URL+path, strings.NewReader(body)) |
| + if resp, err := fx.ts.Client().Do(req); err == nil { |
| + io.Copy(io.Discard, resp.Body) |
| + resp.Body.Close() |
| + } |
| + } |
| + } |
| + }() |
| + } |
| + time.Sleep(50 * time.Millisecond) |
| + resp := sesPostPath(t, fx, "/api/ses/events/"+sesTestToken, signedSNS(t, fx, key, snsCertPath(7))) |
| + resp.Body.Close() |
| + close(stop) |
| + wg.Wait() |
| + if resp.StatusCode != http.StatusOK { |
| + t.Fatalf("genuine cold-cache delivery under a flood = %d, want 200", resp.StatusCode) |
| + } |
| + if n := fetches.Load(); n != 1 { |
| + t.Fatalf("%d certificate fetches, want the genuine delivery's 1", n) |
| + } |
| +} |
| + |
| +// A certificate the door cannot fetch right now is a 503, which SNS |
| +// retries, never a 403, which it does not. |
| +func TestSESEventsBusyIsRetryable(t *testing.T) { |
| + fx, key, fetches := sesTokenFixture(t, sesTestToken) |
| + fx.srv.snsCerts.mu.Lock() |
| + for i := 0; i < snsCertFetchesPerMinute; i++ { |
| + fx.srv.snsCerts.started = append(fx.srv.snsCerts.started, time.Now()) |
| + } |
| + fx.srv.snsCerts.mu.Unlock() |
| + resp := sesPostPath(t, fx, "/api/ses/events/"+sesTestToken, signedSNS(t, fx, key, snsCertPath(9))) |
| + resp.Body.Close() |
| + if resp.StatusCode != http.StatusServiceUnavailable || fetches.Load() != 0 { |
| + t.Fatalf("delivery past the fetch limit = %d after %d fetches; want 503 after 0", resp.StatusCode, fetches.Load()) |
| + } |
| +} |
| + |
| // ---- event-to-domain attribution (I6, review follow-up) -------------------- |
| // |
| // ParseEvent attributes an event by the domain of mail.source. If SES |
diff --git a/internal/console/testdata/claim-routes.txt b/internal/console/testdata/claim-routes.txt| index 8522e136f..af31b24bc 100644 |
| --- a/internal/console/testdata/claim-routes.txt |
| +++ b/internal/console/testdata/claim-routes.txt |
| @@ -383,6 +383,7 @@ route POST /api/fleet/replicas/{account}/{app}/{host}/deploy |
| route POST /api/link/publications |
| route POST /api/link/rotate |
| route POST /api/ses/events |
| +route POST /api/ses/events/{token} |
| route POST /auth/cli/accounts |
| route POST /auth/cli/approve |
| route POST /auth/cli/poll |
diff --git a/parity/parity.tsv b/parity/parity.tsv| index 33bf1b6bf..998179e19 100644 |
| --- a/parity/parity.tsv |
| +++ b/parity/parity.tsv |
| @@ -254,6 +254,6 @@ healthz platform internal GET /healthz Health check for the load balancer. |
| alert-signing-key platform internal GET /alerts/signing-key The public key alert webhook receivers fetch. |
| legacy-apps platform internal GET /apps ; GET /apps/{app} Old URLs kept as redirects into the account. |
| billing-webhook platform internal POST /billing/webhook Stripe calls it. |
| -ses-events platform internal POST /api/ses/events Amazon SES delivery events. |
| +ses-events platform internal POST /api/ses/events ; POST /api/ses/events/{token} Amazon SES delivery events. |
| box-doors platform internal POST /api/fleet/enrol ; GET /api/box/interactive/{id} ; GET /api/box/runs/{id} ; POST /api/fleet/replicas/{account}/{app}/{host}/coordinator ; POST /api/fleet/replicas/{account}/{app}/{host}/release ; POST /api/fleet/replicas/{account}/{app}/{host}/deploy Doors boxes and managed fleets call, not people. |
| plumbing platform internal __demo-snapshot ; __registry-child ; __rootfs-check-probe ; __rootfs-check-prepare ; __cgexec ; __cgprobe Words the binary runs itself as, dispatched before the command switch. |