Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
8721de0
feat(eval): add TenantId and stamp it on results
mostafa Nov 19, 2026
2e4b239
feat(eval): key correlation state by tenant
mostafa Nov 19, 2026
7b452bf
feat(eval): version correlation snapshots by tenant
mostafa Nov 19, 2026
8a8699d
feat(eval): bind rulesets to tenants
mostafa Nov 19, 2026
2f7b7da
feat(runtime): carry the tenant from each source to its results
mostafa Nov 19, 2026
6eaf88d
feat(runtime): key alert, risk, disposition, and capture state by tenant
mostafa Nov 19, 2026
7159394
feat: cap correlation, alert, and risk state per tenant
mostafa Nov 19, 2026
af20e26
feat(runtime): scope enrichers, webhooks, and sinks by tenant
mostafa Nov 19, 2026
e8e2c8a
feat(cli): configure tenancy and bind tokens and sources to tenants
mostafa Nov 19, 2026
6858a41
feat(cli): scope the daemon API to the token's tenant
mostafa Nov 19, 2026
86ec5e2
feat(cli): route sinks by tenant and export tenant metrics
mostafa Nov 19, 2026
b74ebba
feat(mcp): let silence and disposition tools name a tenant
mostafa Nov 19, 2026
fbf777d
bench(eval): measure correlation state across many tenants
mostafa Nov 19, 2026
7a213f6
test(cli): cover multi-tenant isolation end to end
mostafa Nov 20, 2026
5fc7898
docs: document multi-tenancy
mostafa Nov 20, 2026
a152f8d
fix: route incident lines by tenant and validate scope tenant bindings
mostafa Nov 20, 2026
d90fe08
fix(cli): close tenancy validation and API scoping gaps
mostafa Nov 20, 2026
86141c4
fix: check the tenant on capture and incident-disposition lookups
mostafa Nov 20, 2026
5f7d5e9
fix(runtime): keep tenant tokens from removing untenanted silences
mostafa Nov 20, 2026
daaf4f3
fix(eval): refuse dots in tenant ids
mostafa Nov 20, 2026
995475c
fix(runtime): validate {tenant} NATS subjects, filter incidents, and …
mostafa Nov 20, 2026
9cae146
fix(runtime): keep OTLP finding uids under a tenant filter and create…
mostafa Nov 20, 2026
fb4244c
fix(cli): limit tenant routing to findings file and NATS sinks
mostafa Nov 20, 2026
626c27f
fix(runtime): parse URL templates to keep tenants out of the authority
mostafa Nov 20, 2026
729bc0d
docs: document tenant id characters and sink routing limits
mostafa Nov 20, 2026
c015cfa
fix(cli): check scoped webhooks in directories during tenancy validation
mostafa Nov 20, 2026
11583f9
fix(eval): keep suppression on quota eviction and index state per tenant
mostafa Nov 20, 2026
59b305d
fix(eval): import every ruleset unit that fits when one is rejected
mostafa Nov 20, 2026
2f32de9
fix(eval): check the tenant slice length in detection-only routers
mostafa Nov 20, 2026
e088aed
fix(runtime): apply the incident quota only to new incidents and inde…
mostafa Nov 20, 2026
d8bcd8c
fix(runtime): index risk entities per tenant and trim tenants on rest…
mostafa Nov 20, 2026
a52053c
docs: describe when tenant quotas evict
mostafa Nov 20, 2026
dfc53b9
fix(cli): require tenancy and a positive value for tenant quotas
mostafa Nov 20, 2026
79a7fbb
docs: document quota and sink routing refusals in the daemon reference
mostafa Nov 20, 2026
f911921
fix(runtime): pass the tenancy mode to DispositionStore::restore
mostafa Nov 20, 2026
74c39ec
fix(runtime): count restored alert-pipeline entries after pruning and…
mostafa Nov 20, 2026
b2937c9
test(runtime): cover entity-graph isolation across tenants
mostafa Nov 20, 2026
f0b5a77
test(eval): prove a chained correlation never completes across tenants
mostafa Nov 20, 2026
6edd05f
bench(eval): measure tenant state without event payloads and under a …
mostafa Nov 20, 2026
55ee89a
fix(runtime): resume per-tenant file deliveries and check tenants bef…
mostafa Nov 20, 2026
dfa0606
fix(runtime): render every NATS tenant subject before publishing a batch
mostafa Nov 20, 2026
6b8d7a5
fix(cli): refuse tenant ids that differ only by case
mostafa Nov 20, 2026
c2e6f22
docs: add the PR number to the multi-tenancy changelog entry
mostafa Nov 20, 2026
2a1143b
fix(runtime): key the HTTP enrichment cache on rendered headers
mostafa Nov 20, 2026
593eda3
fix: keep silence ids unique per tenant and refuse ambiguous deletes
mostafa Nov 20, 2026
3896eb7
fix: add per-tenant quotas for silences, inhibition sources, and stre…
mostafa Nov 20, 2026
f41e23c
fix(daemon): sum the false-positive ratio gauge across tenants
mostafa Nov 20, 2026
01aa749
docs(mcp): state that a tenant-bound token naming another tenant gets…
mostafa Nov 20, 2026
0be4cf6
docs: recommend tenant-bound MCP bridges and a read-only all_tenants …
mostafa Nov 20, 2026
cd9abb9
fix(daemon): refuse tenant-bound token secrets shorter than 32 bytes
mostafa Nov 20, 2026
beeab66
fix(daemon): audit all_tenants writes under the tenant they affect
mostafa Nov 20, 2026
618a761
test: write forward-slash paths into tenancy test configs for Windows
mostafa Nov 20, 2026
fddfc48
test: wait for a periodic state save before stopping the tenancy daemon
mostafa Nov 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@ All notable changes to RSigma are documented in this file. Each entry correspond

## [Unreleased]

### Multi-tenant daemon (#732)

`rsigma engine daemon` can serve several tenants in one process while keeping their state apart. A tenant comes only from an operator binding: the bearer token that authenticated a REST or OTLP ingest request, the configured tenant of the single selected pull source, or a NATS subscription declared for one tenant. 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`; `all_tenants` is not implied by a role, and an `all_tenants` token cannot ingest because it has no tenant to bind. A tenant id is 1 to 64 ASCII letters, digits, `_`, and `-`; a `.` is refused so an id is always one NATS subject token.

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, so untenanted output is unchanged. Correlation, alert-pipeline, risk, and disposition snapshots move to version 2, which nests state under `tenants`; version 1 snapshots stay readable as the untenanted bucket, and a restore discards entries that do not match the current tenancy mode and logs the counts.

Named rulesets can bind to tenants. A bound ruleset receives only events whose tenant is listed, while an unbound ruleset receives every tenant's events with its state still keyed per tenant. `daemon.tenancy.quotas` caps correlation state, active alerts, incidents, and risk entities per tenant; at a tenant's cap a new entry evicts its own expired entries first, then its stalest entries, 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, so one tenant cannot take every slot of a shared control. Disposition idempotency ids are kept per tenant, and `max_seen_ids` bounds each tenant's set.

With tenancy enabled, startup refuses without bearer-token auth, with a quota of 0, with anonymous permissions, with a token that declares both or neither binding, with a tenant-bound token secret shorter than 32 bytes, with a non-HTTP source that has no tenant binding (checked after CLI flags such as `--input` apply), with a disposition pull source (a record's own `tenant` field is never identity), with overlapping `nats_tenants` subjects or a repeated tenant, with two tenant ids that differ only by case, with a project config layer loaded, and with a ruleset binding no token, `input.tenant`, or `nats_tenants` entry can produce. With tenancy disabled, startup refuses any tenant binding, any quota, any `{tenant}` or `tenant=` sink, and any non-empty webhook or enricher `scope.tenants`.

The API scopes every route to a tenancy class. Tenant tokens get `403` on operator-only routes that span tenants (`/metrics`, `/api/v1/status`, field and schema observers, dynamic sources, watchlists, STIX sources, and reload). Tenant-scoped reads, including the tap and the detection stream, are filtered to the token's tenant; `?tenant=` only narrows, and a tenant token naming another tenant gets `403`. A resource id owned by another tenant is `404`, so ids do not leak existence. Silences and dispositions written by a tenant token are bound to its tenant. A silence id must be unique among the silences its tenant can see, so a reused id returns `409`, and an `all_tenants` delete of an id that several tenants use returns `409` until `?tenant=` names one. An `all_tenants` token must send `tenant` on a write. The audit trail records an `all_tenants` token's silence and disposition writes under the tenant they affected, so that tenant's audit reads include them.

Findings sinks can filter by tenant 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; file sinks create the tenant's directory and keep a bounded LRU of per-tenant handles. `{tenant}` may appear once, only in a file path or a NATS subject (including the alert pipeline and risk `nats_subject` keys), and the DLQ and audit sinks refuse `{tenant}`, `tenant=`, and `max_open=`. A result without a tenant on a `{tenant}` subject or path is a permanent delivery failure and reaches the DLQ. OTLP sinks carry `tenant_id` as a log-record attribute. The HTTP enrichment response cache includes the rendered headers in its key, so a header that carries the tenant or an event field never shares a cached response. Three metric families report tenancy: `rsigma_tenant_rejected_total`, `rsigma_tenant_quota_evictions_total`, and `rsigma_detection_matches_by_tenant_total`, the last bucketing tenants outside `daemon.tenancy.metrics_tenant_allowlist` under `other`. `rsigma_rule_false_positive_ratio` sums each rule across tenants, so one tenant's verdicts no longer overwrite the series after a restore or prune.

The MCP `create_silence` and `post_disposition` tools accept an optional `tenant` argument. The library gains `TenantId`, `tenant_at`, `WithTenant`, the `_for_tenant` and `_for_tenants` evaluation methods, `TenantStateSnapshot`, `ImportStats`, `Scope::with_tenants`, tenant bindings on rulesets, and three `MetricsHook` methods.

**Breaking changes:** `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`, and `RulesetBinding.tenants` need defaults in struct literals, and so does the new `CacheKey.headers_hash`. `SilenceStore::remove_scoped` returns `SilenceRemoval`, whose `Removed` variant carries the removed silence's tenant, and `SilenceStore::try_add` also refuses a duplicate id. `CaptureRing::snapshot_incident` takes the tenant, `DispositionStore::restore` takes the tenancy flag, and `AlertPipelineConfigError` and `RiskConfigError` gain a `NatsSubject` variant. Correlation, alert-pipeline, risk, and disposition snapshots move to version 2, which older releases cannot read. Path-mode output and existing daemon behavior are unchanged with tenancy off.

### Draft rules from STIX indicators (#731)

`rsigma rule draft --from-stix` reads a STIX 2.1 bundle, or a single indicator, and prints one Sigma rule per logsource. It needs the `stix-draft` feature. The Docker image includes it, because that image is built with `--all-features`.
Expand Down
124 changes: 121 additions & 3 deletions crates/rsigma-cli/src/commands/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ pub(crate) struct DaemonArgs {
#[arg(long = "max-group-entries")]
pub max_group_entries: Option<usize>,

/// Enable logical multi-tenancy. Startup-only; requires bearer-token auth
/// and a tenant binding on every input source.
#[arg(long = "tenancy")]
pub tenancy: bool,

/// Per-tenant correlation state cap. Requires `--tenancy` or
/// `daemon.tenancy.enabled`.
#[arg(long = "max-tenant-state")]
pub max_tenant_state: Option<usize>,

/// Event field name(s) for timestamp extraction in correlations
#[arg(long = "timestamp-field")]
pub timestamp_fields: Vec<String>,
Expand Down Expand Up @@ -718,15 +728,52 @@ pub(crate) fn cmd_daemon(
);
let capture = resolve_capture_settings(&base, args.enable_capture, dispositions.enabled);
let api_auth = resolve_auth_settings(&base, args.api_token_env.clone());
let api_token_env_used = args.api_token_env.is_some();
let (tenancy, input_tenant, nats_tenants) =
match daemon::tenancy::resolve_tenancy_settings(&base, args.tenancy, args.max_tenant_state)
{
Ok(values) => values,
Err(message) => {
eprintln!("error: {message}");
process::exit(exit_code::CONFIG_ERROR);
}
};
let project_layer_loaded = config::load_layered(args.config.as_deref())
.map(|loaded| loaded.project_layer_loaded)
.unwrap_or(false);
let state_db_from_config = base
.daemon
.as_ref()
.and_then(|d| d.state.as_ref())
.and_then(|s| s.db.as_ref());
let has_state_db = args.state_db.is_some() || state_db_from_config.is_some();
let audit = resolve_audit_settings(&base, has_state_db);
let tenancy_base = base.clone();
apply_daemon_config(&mut args, matches, base);

let ruleset_tenants = config_ruleset_tenants(&args.ruleset_entries);
if let Err(message) = daemon::tenancy::validate_tenancy_from_config(
&tenancy_base,
&tenancy,
input_tenant.as_ref(),
&nats_tenants,
&daemon::tenancy::ResolvedDaemonInputs {
input_source: &args.input,
sink_specs: &args.output,
ruleset_tenants: &ruleset_tenants,
alert_pipeline: args.alert_pipeline.as_deref(),
risk: args.risk.as_deref(),
enrichers: args.enrichers.as_deref(),
webhooks: &args.webhooks,
disposition_source: dispositions.source.is_some(),
},
project_layer_loaded,
api_token_env_used,
) {
eprintln!("error: {message}");
process::exit(exit_code::CONFIG_ERROR);
}

let DaemonArgs {
config,
dry_run: _,
Expand All @@ -748,6 +795,8 @@ pub(crate) fn cmd_daemon(
max_correlation_events,
max_state_entries,
max_group_entries,
tenancy: _cli_tenancy,
max_tenant_state: _cli_max_tenant_state,
timestamp_fields,
state_db,
state_save_interval,
Expand Down Expand Up @@ -935,6 +984,9 @@ pub(crate) fn cmd_daemon(
max_correlation_events,
max_state_entries,
max_group_entries,
tenancy,
input_tenant,
nats_tenants,
timestamp_fields,
timestamp_fallback,
state_db,
Expand Down Expand Up @@ -1077,6 +1129,8 @@ fn resolve_auth_settings(
role: Some("admin".into()),
permissions: None,
token_env: var,
tenant: None,
all_tenants: false,
}],
Vec::new(),
)
Expand All @@ -1098,11 +1152,25 @@ fn resolve_auth_settings(
eprintln!("daemon.api.auth: token '{name}' missing 'token_env'");
process::exit(exit_code::CONFIG_ERROR);
});
let tenant = t
.tenant
.as_deref()
.map(rsigma_eval::TenantId::new)
.transpose();
let tenant = match tenant {
Ok(tenant) => tenant,
Err(error) => {
eprintln!("daemon.api.auth: token '{name}': {error}");
process::exit(exit_code::CONFIG_ERROR);
}
};
TokenSpec {
name,
role: t.role,
permissions: t.permissions,
token_env,
tenant,
all_tenants: t.all_tenants.unwrap_or(false),
}
})
.collect();
Expand Down Expand Up @@ -1723,6 +1791,37 @@ fn apply_daemon_config(
}
}

/// Extract the tenant bindings declared on the resolved ruleset entries,
/// validating each id so a typo fails startup with the ruleset name. A CLI
/// `--ruleset` list replaces the configured entries and carries no bindings.
fn config_ruleset_tenants(
entries: &[config::RulesetEntryPartial],
) -> Vec<(String, Vec<rsigma_eval::TenantId>)> {
let mut out = Vec::new();
for entry in entries {
let config::RulesetEntryPartial::Bound {
name,
tenants: Some(tenants),
..
} = entry
else {
continue;
};
let mut parsed = Vec::new();
for raw in tenants {
match rsigma_eval::TenantId::new(raw) {
Ok(tenant) => parsed.push(tenant),
Err(error) => {
eprintln!("error: ruleset '{name}': {error}");
process::exit(exit_code::CONFIG_ERROR);
}
}
}
out.push((name.clone(), parsed));
}
out
}

/// Helper struct grouping TLS flags so `cmd_daemon` stays readable.
#[cfg(feature = "daemon-tls")]
pub(crate) struct TlsCliArgs {
Expand All @@ -1747,11 +1846,12 @@ fn build_ruleset_bindings(
let mut any_when = false;

for entry in entries {
let (name, when_schemas) = match entry {
crate::config::RulesetEntryPartial::Name(name) => (name, Vec::new()),
let (name, when_schemas, tenants) = match entry {
crate::config::RulesetEntryPartial::Name(name) => (name, Vec::new(), Vec::new()),
crate::config::RulesetEntryPartial::Bound {
name,
when,
tenants,
unknown,
} => {
if !unknown.is_empty() {
Expand All @@ -1772,7 +1872,18 @@ fn build_ruleset_bindings(
);
process::exit(exit_code::CONFIG_ERROR);
}
(name, when.schemas)
let tenants = tenants.unwrap_or_default();
let mut parsed = Vec::with_capacity(tenants.len());
for tenant in tenants {
match rsigma_eval::TenantId::new(&tenant) {
Ok(tenant) => parsed.push(tenant),
Err(error) => {
eprintln!("error: ruleset '{name}': {error}");
process::exit(exit_code::CONFIG_ERROR);
}
}
}
(name, when.schemas, parsed)
}
};
if !seen.insert(name.clone()) {
Expand Down Expand Up @@ -1831,6 +1942,7 @@ fn build_ruleset_bindings(
spec: spec.clone(),
pipelines,
when_schemas,
tenants,
});
}

Expand Down Expand Up @@ -1882,6 +1994,9 @@ fn run_daemon(
max_correlation_events: usize,
max_state_entries: usize,
max_group_entries: Option<usize>,
tenancy: daemon::tenancy::TenancySettings,
input_tenant: Option<rsigma_eval::TenantId>,
nats_tenants: Vec<daemon::tenancy::NatsTenantBinding>,
timestamp_fields: Vec<String>,
timestamp_fallback: String,
state_db: Option<PathBuf>,
Expand Down Expand Up @@ -2085,6 +2200,9 @@ fn run_daemon(
pipelines,
pipeline_paths: file_pipeline_paths,
corr_config,
tenancy,
input_tenant,
nats_tenants,
include_event,
match_detail,
pretty,
Expand Down
10 changes: 10 additions & 0 deletions crates/rsigma-cli/src/commands/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -834,8 +834,15 @@ fn cmd_eval_rulesets(args: EvalArgs, ctx: OutputCtx) -> bool {
crate::config::RulesetEntryPartial::Bound {
name,
when,
tenants,
unknown,
} => {
if tenants.as_ref().is_some_and(|t| !t.is_empty()) {
eprintln!(
"error: ruleset '{name}' sets `tenants`, which is only valid under daemon.rulesets"
);
process::exit(exit_code::CONFIG_ERROR);
}
if !unknown.is_empty() {
eprintln!(
"error: ruleset '{name}' has unknown keys: {}",
Expand Down Expand Up @@ -997,6 +1004,7 @@ fn cmd_eval_rulesets(args: EvalArgs, ctx: OutputCtx) -> bool {
units.push(RulesetUnit {
name: Arc::from(name.as_str()),
when_schemas: Vec::new(),
tenants: Vec::new(),
engine: UnitEngine::Routed(Box::new(router)),
field_set,
});
Expand Down Expand Up @@ -1045,6 +1053,7 @@ fn cmd_eval_rulesets(args: EvalArgs, ctx: OutputCtx) -> bool {
units.push(RulesetUnit {
name: Arc::from(name.as_str()),
when_schemas,
tenants: Vec::new(),
engine,
field_set,
});
Expand Down Expand Up @@ -2483,6 +2492,7 @@ mod tests {
crate::config::RulesetEntryPartial::Bound {
name,
when,
tenants: _,
unknown,
} => {
assert_eq!(name, "a");
Expand Down
15 changes: 12 additions & 3 deletions crates/rsigma-cli/src/config/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,23 @@ fn ruleset_list_errors(
let path = format!("{section}.rulesets");
let mut seen = HashSet::new();
for entry in entries {
let (name, when, unknown) = match entry {
super::RulesetEntryPartial::Name(name) => (name, None, None),
let (name, when, tenants, unknown) = match entry {
super::RulesetEntryPartial::Name(name) => (name, None, None, None),
super::RulesetEntryPartial::Bound {
name,
when,
tenants,
unknown,
} => (name, when.as_ref(), Some(unknown)),
} => (name, when.as_ref(), tenants.as_ref(), Some(unknown)),
};
if section != "daemon" && tenants.is_some_and(|t| !t.is_empty()) {
errors.push(SemanticError::new(
&path,
format!(
"ruleset '{name}' sets `tenants`, which is only valid under daemon.rulesets"
),
));
}
if !seen.insert(name.as_str()) {
errors.push(SemanticError::new(
&path,
Expand Down
3 changes: 3 additions & 0 deletions crates/rsigma-cli/src/config/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ pub(crate) fn defaults_partial() -> RsigmaConfigPartial {
batch_size: Some(BATCH_SIZE),
jq: None,
jsonpath: None,
tenant: None,
nats_tenants: None,
}),
output: Some(OutputPartial {
sinks: Some(vec![STDOUT_SINK.to_string()]),
Expand Down Expand Up @@ -247,6 +249,7 @@ pub(crate) fn defaults_partial() -> RsigmaConfigPartial {
event_logsource: None,
strict: Some(LOGSOURCE_STRICT),
}),
tenancy: None,
}),
eval: Some(EvalPartial {
rules: None,
Expand Down
Loading
Loading