Skip to content

Phase 6: rate-limit the zarr data plane (#901) - #942

Merged
neuromechanist merged 2 commits into
feature/issue-896-epic-arch-hardeningfrom
feature/issue-901-phase6-dataplane
Jul 7, 2026
Merged

neuromechanist merged 2 commits into
feature/issue-896-epic-arch-hardeningfrom
feature/issue-901-phase6-dataplane

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Summary

zarr.nemar.org's host fork in index.ts dispatched straight to zarrDataRoutes.fetch(), bypassing the api middleware stack — including the rate limiter. As the highest-request-volume data-plane path, it ran completely unthrottled (it does have edge caching, so this is availability-hardening, not correctness).

  • __selectBucket now routes /<id>/zarr/* (via ZARR_PATH_RE) to the same generous data-plane IP bucket as data.nemar.org (DATA_MAX_REQUESTS = 10000), so a runaway viewer/scraper is bounded while a real reader runs unthrottled.
  • zarrDataRoutes applies the shared rateLimiter middleware, skipping OPTIONS so a 429 never strips a CORS preflight's headers. A small cast bridges the sub-app's Bindings-only generic to rateLimiter's context (runtime-safe).

Scope

The STS s3:ListBucket prefix-scoping half of #901 is deliberately deferred to #941: it's a larger, riskier change (git-annex HeadBucket authorizes as s3:ListBucket with no prefix, so no IAM condition can allow HeadBucket while blocking no-prefix enumeration — the real fix removes HeadBucket from the user token and needs live git-annex validation before deploy). Full analysis in #941.

Test plan

  • backend/test/rate-limit-buckets.test.ts — /data, /nemar/data, and /<id>/zarr/* all bucket to data-ip at DATA_MAX_REQUESTS; a tokened zarr request still uses the data bucket; /datasets/* stays on the ip bucket.
  • Full backend unit suite (425) green; tsc + Biome clean; existing zarr-data route tests unaffected.

Part of epic #896. (zarr half of #901; STS half -> #941.)

Epic #896 Phase 6 (#901), zarr half. zarr.nemar.org's host fork dispatched
straight to zarrDataRoutes, bypassing the api middleware stack and its rate
limiter -- the highest-request-volume data-plane path ran unthrottled.
- __selectBucket routes /<id>/zarr/* to the generous data-plane IP bucket
  (same DATA_MAX_REQUESTS as data.nemar.org), so a runaway viewer/scraper is
  bounded while a real reader runs unthrottled.
- zarrDataRoutes applies the rateLimiter middleware (skipping OPTIONS so a 429
  never strips a CORS preflight's headers).
- The STS ListBucket prefix-scoping half of #901 is tracked as a follow-up
  (941); it needs live git-annex validation (HeadBucket == ListBucket).
- ZARR_PATH_RE now matches the /zarrproxy/<id>/zarr/* shape too. Hono's
  app.route('/zarrproxy', ...) PREPENDS the prefix (doesn't strip it), so
  c.req.path keeps /zarrproxy — reachable at api.nemar.org (prod) and the
  workers.dev fallback. The old anchor missed it, OVER-throttling real zarr
  viewers to 500 instead of 10000. Corrected the misleading comment; added
  /zarrproxy path cases to the bucket test (the gap that let it through).
- The rate-limiter 429 on the zarr host now carries the zarr CORS headers,
  so a throttled browser viewer reads the 429 + retry_after instead of an
  opaque cross-origin failure.
- Shared data-ip bucket with data.nemar.org is per the issue's spec (10000/
  60s is generous); flagged by review, kept deliberately.
@neuromechanist

Copy link
Copy Markdown
Contributor Author

Review (sonnet) — findings addressed in dbabac3

  • [important] ZARR_PATH_RE missed the /zarrproxy/<id>/zarr/* shape. Confirmed via Hono source: app.route('/zarrproxy', ...) PREPENDS the prefix (no strip), so c.req.path keeps /zarrproxy — reachable at api.nemar.org (prod) + workers.dev fallback — and the old anchor OVER-throttled real zarr viewers to 500 instead of 10000. Regex now matches both shapes; misleading comment corrected.
  • [important] the 429 from the rate limiter carried no zarr CORS, so a throttled browser viewer saw an opaque failure. The wrapper now re-applies corsHeaders to a 429 so the viewer reads the 429 + retry_after.
  • [important, test gap] added /zarrproxy/... path cases to the bucket test (the gap that let the misrouting through).
  • [moderate] shared data-ip bucket with data.nemar.org is per the issue's spec ('apply the data-plane bucket'); 10000/60s is generous, kept deliberately.
  • Reviewer confirmed clean: OPTIONS not throttled + keeps CORS, rate-limit runs before cache lookup (intended), the context cast is runtime-safe, dev-bypass/X-Test-Bypass unaffected.

@neuromechanist
neuromechanist merged commit 30f00b1 into feature/issue-896-epic-arch-hardening Jul 7, 2026
1 check passed
@neuromechanist
neuromechanist deleted the feature/issue-901-phase6-dataplane branch July 7, 2026 00:07

This branch was previously deployed

1 inactive deployment
npm — dbabac38 Deployed Jul 7, 2026 by neuromechanist via publish #1706
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant