Skip to content

feat: multi-tenant daemon isolation - #732

Merged
mostafa merged 53 commits into
mainfrom
feat/multi-tenancy
Nov 20, 2026
Merged

mostafa merged 53 commits into
mainfrom
feat/multi-tenancy

Conversation

@mostafa

@mostafa mostafa commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes #358.

rsigma engine daemon can serve several tenants in one process while keeping their state, API views, and sink output apart. Tenancy is off by default, and with it off, path-mode output and existing daemon behavior are unchanged.

  • Identity. A tenant comes only from an operator binding: the bearer token that authenticated a REST or OTLP ingest request, daemon.input.tenant for a pull source, or a daemon.input.nats_tenants subscription. Event fields, client headers, NATS message headers, and OTLP attributes are never identity. A token declares exactly one of tenant: <id> or all_tenants: true. A tenant id is 1 to 64 ASCII letters, digits, _, and -, starts with a letter or digit, and must be unique ignoring case.
  • State. Every stateful key includes the tenant: correlation windows, dedup fingerprints, incident ids and entity join keys, inhibition sources, silences, risk entities, disposition buckets, and capture bundle identities. Hashes change only for tenanted results. Correlation, alert-pipeline, risk, and disposition snapshots move to version 2, which nests state under tenants. Version 1 snapshots load as the untenanted bucket, and a restore discards entries that do not match the current tenancy mode.
  • Rulesets. A ruleset with a tenants binding receives only those tenants' events. An unbound ruleset receives every tenant's events, with its state still keyed per tenant.
  • Quotas. daemon.tenancy.quotas caps correlation state, active alerts, incidents, and risk entities per tenant. At a tenant's cap, a new entry evicts that tenant's expired entries first, then its stalest ones. Joining an open incident never evicts. A restore or reload trims each tenant to its quota, and the global caps remain as a backstop. The silences, inhibition_sources, and stream_sessions quotas refuse a tenant's new dynamic silence (429), inhibition source, or tap and tail session (409) at its cap. Disposition idempotency ids are kept per tenant, so one tenant's volume cannot evict another's.
  • API. Every route has a tenancy class. Tenant tokens get 403 on operator-only routes that span tenants, tenant-scoped reads are filtered to the token's tenant, and a resource owned by another tenant is 404. Silences and dispositions written by a tenant token are bound to its tenant, and an all_tenants token must name a tenant on a write. Silence ids are unique per tenant: a duplicate is 409, and an all_tenants delete of an id that several tenants use is 409 unless ?tenant= names one. The audit trail records an all_tenants write under the tenant it affected, so that tenant's audit reads include it.
  • Sinks. Findings sinks can filter with tenant=<id>, route NATS subjects with {tenant} as a whole token into one wildcard JetStream stream, and route file paths with {tenant} as a whole path component. Per-tenant file sinks create the tenant's directory, keep a bounded handle LRU (max_open), and resume a retried delivery without rewriting lines. A result without a tenant on a {tenant} sink fails the batch before any write and reaches the DLQ. OTLP sinks carry tenant_id as a log-record attribute.
  • Enrichers and webhooks. scope.tenants limits an enricher or webhook to listed tenants. An HTTP enricher URL template cannot place the tenant in the scheme, credentials, host, or port, and the HTTP response cache keys on the rendered headers, so a per-tenant header never shares a cached response.
  • Startup refusals. With tenancy on, the daemon refuses to start without bearer-token auth, with a token secret shorter than 32 bytes, with anonymous permissions, with a quota of 0, with a pull source that has no tenant binding, with a disposition pull source, with overlapping nats_tenants subjects, with a project config layer, and with a ruleset binding that no token or source can produce. With tenancy off, it refuses any tenant binding, quota, {tenant} or tenant= sink, or scope.tenants.
  • Metrics. rsigma_tenant_rejected_total, rsigma_tenant_quota_evictions_total, and rsigma_detection_matches_by_tenant_total. The last buckets tenants outside daemon.tenancy.metrics_tenant_allowlist under other. rsigma_rule_false_positive_ratio sums each rule across tenants.
  • MCP. create_silence and post_disposition accept an optional tenant argument; a tenant-bound token naming another tenant gets 403. The docs recommend one tenant-bound bridge per tenant and a read-only bridge for an all_tenants token.
daemon:
  tenancy:
    enabled: true
    quotas:
      correlation_state: 50000
  input:
    source: http
  output:
    sinks:
      - file:///var/log/rsigma/{tenant}/findings.ndjson
  api:
    auth:
      tokens:
        - name: acme-ingest
          role: ingest
          token_env: ACME_TOKEN
          tenant: acme
        - name: soc
          role: admin
          token_env: SOC_TOKEN
          all_tenants: true

Breaking.

  • RuleHeader.tenant_id, RawEvent.tenant, CorrelationSnapshot.tenants, GroupStateInfo.tenant, RulesetUnit.tenants, RulesetStats.tenants, CorrelationConfig.require_tenant and max_state_entries_per_tenant, both ScopeConfig.tenants, RulesetBinding.tenants, and CacheKey.headers_hash need defaults in struct literals.
  • CaptureRing::snapshot_incident takes a tenant, DispositionStore::restore takes the tenancy mode, and the alert-pipeline and risk config errors gain NatsSubject variants. SilenceStore::remove_scoped returns SilenceRemoval, and SilenceStore::try_add also refuses a duplicate id.
  • Version 2 snapshots cannot be read by older releases.

Test plan

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo doc --workspace --all-features --locked --no-deps
  • cargo test --workspace --all-features --locked, including the end-to-end isolation suite in crates/rsigma-cli/tests/cli_daemon_tenancy.rs
  • cargo check --manifest-path fuzz/Cargo.toml --all-targets --locked
  • python3 scripts/mcp-smoke.py --bin target/debug/rsigma and the same with --http
  • npm run docs:build and npm run docs:validate
  • Sigma corpus regression on a release build: 3,807 rules, no parse or compile errors

…am sessions, and keep disposition ids per tenant
@mostafa
mostafa merged commit 1e8ca57 into main Nov 20, 2026
29 checks passed
@mostafa
mostafa deleted the feat/multi-tenancy branch November 20, 2026 12:54
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.

Multi-tenant daemon isolation (authenticated principal)

1 participant