Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

Multi-tenant application: organization-scoped routes in Axum

说明与用途

Featherboard 实现了基于路径的组织范围路由,使用 CurrentOrg 提取器,并在 SQL 查询中强制执行 org_id 检查,添加了全面的测试以确保租户隔离。

问题

Ensuring that an organization identifier is consistently carried through and validated across all requests in a multi‑tenant Rust web application.

结果

Featherboard now reliably isolates data per organization, preventing accidental cross‑tenant access and simplifying hosting by using path‑based tenancy.

工作流

  • Define routes with /{org-slug}/… prefix.
  • Create CurrentOrg extractor to parse slug and load org from DB.
  • Inject CurrentOrg into handlers as a parameter.
  • Add org_id condition to all SELECT, UPDATE, and authorization queries.
  • Update HTML links, form actions, redirects, email links, Stripe checkout, and webhooks to include org slug.
  • Write unit and integration tests to verify routing, access control, and redirect preservation.
  • Deploy with path‑based tenancy to avoid wildcard DNS.
  • Monitor for cross‑tenant access errors.

证据

Multi‑tenancy sounds like a simple idea - reuse the same application across multiple organizations. Usually, you put the organization identifier somewhere in the URL, like a subdomain or a path parameter.

来源

Instead of extracting the organization from the slug in every request, Featherboard implemented a CurrentOrg request extractor. It takes the path, extracts the first parameter, looks up the organization in the database, and provides the organization struct to the request handler.

来源

Organization scope is enforced in the resource query, not just through a route lookup.

来源

All of the above are quite fragile, because the compiler will not help you validate them. Rendering a website with invalid links still produces valid HTML, so writing proper unit tests and integration tests is absolutely essential.

来源

  • 记录日期: 2026-11-01T09:13:58.293Z