Skip to the article
Senu 日本語

Deploy and operate

About 3 min read

Senu gives you an ordinary axum::Router. You bind it, put TLS in front of it and add the layers your service needs; Senu adds none of those and listens nowhere by itself.

What does Senu do on every request?

What stays with you?

ConcernWhere it belongs
TLS and HSTSA reverse proxy or load balancer in front of the router
Request logging and tracingA tower layer, such as tower_http::trace::TraceLayer
TimeoutsA tower layer, such as tower_http::timeout::TimeoutLayer
Rate limiting and lockoutYour gateway, or a tower layer
Sessions, login pages and OAuthYour authenticator and your own routes
Audit loggingYour operations; Principal::name is there for it
Health checksA custom route
Graceful shutdownaxum::serve(...).with_graceful_shutdown(...)

How do you bind and serve the router?

    let router = endpoints()
        .into_router(state)
        .map_err(|err| err.to_string())?;
    let listener = tokio::net::TcpListener::bind("127.0.0.1:3000")
        .await
        .map_err(|err| format!("inventory: cannot listen: {}", err.kind()))?;
    eprintln!("inventory: listening on http://127.0.0.1:3000");
    axum::serve(listener, router)
        .await
        .map_err(|_| "inventory: the server stopped".to_owned())

Layers go around the router in the usual Axum way, for example router.layer(TraceLayer::new_for_http()). To serve Senu's routes next to your own Axum routes, merge the routers with Router::merge. Layers you add must not log the Authorization or Cookie headers.

How should secrets be handled?

Read them from the environment or a secret store at startup and turn them into Secret values at once. Secret::new refuses anything but 1 to 256 visible ASCII characters, and a Secret never appears in Debug output. When configuration is wrong, name the variable in the message and never its value, as the example does. Fail before binding: a service that cannot authenticate should not start.

How do you serve several tenants?

Put the tenant in the principal when you authenticate, and filter by caller.tenant() inside every operation. Do not accept a tenant as a parameter. The contract tests check that an unknown parameter such as tenant=other is refused, and your own tests should check that one tenant's key cannot read another tenant's data, as tests/example_inventory.rs does.

What should a production checklist contain?

  1. TLS in front; no plain HTTP reachable from outside.
  2. Long, random, per-client secrets, loaded from a secret store.
  3. Each principal holds only the permissions it needs.
  4. Timeouts, request logging and rate limits are in place as tower layers or at the gateway.
  5. Operations that wait are Run::Async; nothing blocks the executor.
  6. OpError::Internal is logged with its cause on the server.
  7. The contract tests and your own tenant-isolation tests run in CI.
  8. Dependencies are pinned with Cargo.lock and checked with cargo audit or a similar tool.

Is Senu audited?

No. Senu is tested, and its contract is published as tests you can run, but it has had no independent security audit, and it makes no performance claim. Review it as you would any dependency that sits on your authentication path. Report a vulnerability privately, as SECURITY.md in the repository describes.

Next: test with the contract.