Skip to content

Rules

Rules are used to define detection logic. Incoming events are evaluated against the configured rules in real-time to generate alerts.

Overview

Each rule is defined in its own YAML file in the configured rules directory. Inobi loads all .yaml files from this directory (including subdirectories) at startup.

rules/example-rule.yaml
title: Suspicious login
id: 1
description: Login from blocklisted IP
level: high
type: event
status: stable
tags:
  - attack.initial_access
  - attack.t1078
references:
  - https://attack.mitre.org/techniques/T1078/

detection:
  match: event.action == "login-success" and ipInCIDRs(event.source.ip, "192.168.50.0/24")

Top-Level Fields

Field Required Description
title Human-readable rule name
id Unique numeric identifier
description Description of what this rule detects
level Alert severity: critical, high, medium, low, info
type Rule type: event, aggregation, composite
status Rule lifecycle status: stable, experimental, testing, deprecated. Rules with deprecated status are skipped during loading.
tags List of tags for categorization (e.g., MITRE ATT&CK techniques)
references List of reference URLs (documentation, advisories, blog posts)
detection Detection logic configuration (varies by rule type)
scopes Conditional List of scope names this rule applies to. Required on event and aggregation rules when scope filtering is enabled. Not valid on composite rules. See Scopes.
risk List of risk entries defining how this rule contributes to entity risk scores. See Risk.
alert If false, suppress regular alerts from this rule. Used for risk-only rules. (default: true) See Alert Suppression.

Rule Types

Event Rules

Evaluate individual events.

type: event
detection:
  match: >
    event.action == "login-success"
      and iEqual(event.user.name, "admin")
      and isPublicIP(event.source.ip)
  timeout: 1h
  timeout_by: [user.name]

Fields

Field Required Description
match Primary filter expression
extended_match List of secondary filter expressions with helper function access
timeout Suppress repeat alerts for the same group
timeout_by Conditional Required if timeout is set. List of field names to scope the timeout by
emit_suppressed Emit suppressed alerts with "suppressed": true field. Requires timeout. (default: false)

All defined expressions must return true for an alert to be generated. extended_match expressions are only evaluated if match returns true.

The extended_match field enables the creation of stateful detections by using persistent key-value storage.

Performance Tip

Place most filtering logic in match. Use extended_match for operations that require additional helpers (like key-value state, GeoIP, or parsing). extended_match expressions are only evaluated if match returned true.

Aggregation Rules

Alert based on aggregate computations over time windows. Groups related events and evaluates conditions against the group.

type: aggregation
detection:
  match: event.action == "login-failure"
  group_by: [source.ip]
  aggregation: len(uniq(map(events, .user.name))) > 5
  timespan: 2m
  slide: 1m
  timeout: 30m
  projections:
    total_attempts: len(events)

Fields

Field Required Description
match Primary filter expression
extended_match List of secondary filter expressions with helper function access
group_by List of fields to group events by
aggregation Expression evaluated on grouped events
timespan Time window duration (e.g., 30s, 5m, 1h)
slide Sliding window interval (default: equals timespan for tumbling windows). Cannot exceed timespan.
timeout Suppress repeat alerts for same group (e.g., 10m, 1h)
projections Map of named expressions to add computed fields to alerts
event_time Use event timestamps for windowing (see Event Time)
emit_suppressed Emit suppressed alerts with "suppressed": true field. Requires timeout. (default: false)

When a window closes, events within the same group must satisfy the aggregation expression for an alert to be generated.

The group_by field values are automatically projected to resulting alerts.

Performance Tip

Filter aggressively in match and extended_match to avoid accumulating unnecessary events inside windows. Poor filtering can lead to a significant increase in memory usage especially when combined with high event volumes and long window durations.

Aggregation Event Time

By default, Inobi uses processing time (arrival time) for aggregation windowing. Configure event_time to use embedded timestamps instead.

Event time windows use watermark-driven emission: the watermark is computed as max(event_timestamp) - allowed_lateness, and a window emits once the watermark passes the window's end boundary.

detection:
  event_time:
    field: timestamp
    layout: 2006-01-02T15:04:05Z07:00
    allowed_lateness: 5s
Field Required Description
field Event field path containing the timestamp
layout Go time format layout (reference)
allowed_lateness Grace period for out-of-order events. Events arriving after the watermark has passed their timestamp are discarded. Cannot exceed timespan.

Set allowed_lateness to the longest delay you expect between an event happening and the engine receiving it. Events that arrive later than that are dropped. The inobi_late_events_dropped_total metric counts dropped events per rule; if it keeps rising, increase allowed_lateness.

Composite Rules

Alert when multiple different rules fire within a time window.

A composite rule lists two or more entries under parts. Each part references an existing rule by ID and defines a group_by key used to join them. When every referenced rule has fired for the same group within the timespan, the composite rule alerts. Referenced rules typically set alert: false so they only produce output for the composite rule without alerting on their own (see Alert Suppression).

type: composite
detection:
  parts:
    - name: failed_logins
      rule: 1030
      group_by: [source.ip]
      store: [source.ip, action, failure_count]

    - name: successful_login
      rule: 1031
      group_by: [source.ip]
      store: [source.ip, user.name, action]

  timespan: 2m
  timeout: 30m

Detection Fields

Field Required Description
parts List of composite parts (minimum 2)
timespan Maximum time between first and last matching events for the alert to fire
ordered If true, parts must match in definition order (default: false)
ttl How long partial composite state is retained in KV (default: timespan + allowed_lateness). If set, cannot be less than timespan + allowed_lateness.
timeout Suppress repeat alerts for the same group
allowed_lateness Grace period for late events. Only valid when event_time is used. Cannot be set without it. Discarded late events are counted in inobi_late_events_dropped_total.
emit_suppressed Emit suppressed alerts with "suppressed": true field. Requires timeout. (default: false)

Part Fields

Field Required Description
name Identifier for this part. The matched event is projected into the resulting alert under this name.
rule ID of the referenced rule. Each part must reference a distinct rule.
group_by List of field names to use as the grouping key. All parts must resolve to the same key for the composite rule to match.
store Retain specific fields in state that are projected into the alert for this part. Useful when events are large and only a subset of fields is relevant.
event_time Per-part event-time configuration. If any part defines event_time, all parts must define it.

Ordering with processing time

Without event_time, ordered compares the order in which the engine processes events. The engine processes events concurrently in several stages, so events that arrive very close together (within few milliseconds of each other) may be handled out of arrival order. For those events, ordered matching is not reliable. If strict ordering of closely spaced events matters, use event_time, which orders parts by their event timestamps.

Event Time Fields

Field Required Description
field Event field path containing the timestamp
layout Go time format layout (reference)

allowed_lateness for composite rules is configured at the detection level, not inside event_time.

Risk

Any rule type can contribute risk scores to entities via Risk-Based Alerting. Each entry in the risk list defines how a rule contributes to an entity's risk score.

Risk entries require global risk configuration in the main config file. When the risk section is not present in the config, risk entries on rules are ignored. See Config: Risk.

rules/risk-failed-login.yaml
title: Risk - Failed login attempt
id: 200
description: Contributes risk score to user and source IP on failed login.
level: info
status: experimental
type: event
alert: false

detection:
  match: event.action == "login-failure"

risk:
  - entity_type: user
    field: user.name
    score: 5
    scaling: 0.1
    ttl: 1h
    decay: linear
  - entity_type: ip
    field: source.ip
    score: 3
    scaling: 0.5
    ttl: 30m
    decay: none

Risk Entries

Field Required Description
entity_type Category of the entity (e.g., user, device, ip). Entities are tracked independently per type.
field Event field containing the entity identifier (e.g., user.name). Must resolve to a string or numeric value; other types are ignored.
part Conditional Composite part to extract the entity from. Required for composite rules, disallowed on other rule types. Must match a part name.
score Risk points to contribute. Must be greater than 0.
scaling Diminishing returns for repeated firings. Range 0-1. (default: 1.0)
ttl How long this contribution remains active (e.g., 30m, 1h, 24h). Overrides the global risk.defaults.ttl.
decay Score decay function: none or linear. Overrides the global risk.defaults.decay.
normalize Expression to canonicalize entity values. See Expressions: Risk Normalize.

A single rule can contribute to multiple entities. For example, a failed login rule might contribute risk to both the user and the source ip.

Supported rule types:

Event Aggregation Composite

Scaling

Controls how repeated contributions from the same rule accumulate for an entity.

  • 1.0 (default) - every contribution at full value
  • 0.1 - most recent gets full score, score of duplicates is multiplied by the scaling factor
  • 0 - only one contribution per rule is kept (dedup mode)

A maximum of 10 contributions are stored per rule per entity. When the cap is reached, the oldest is evicted.

Decay

Controls how a contribution's score changes over its lifetime.

  • none (default) - full score until TTL expires, then drops to zero
  • linear - score decreases proportionally over the TTL

With linear decay, a 20-point contribution with a 100-second TTL is worth 10 points after 50 seconds.

Alert Suppression

Setting alert: false on a rule suppresses regular alerts while still contributing risk. This is useful for low-severity indicators that should only surface through accumulated risk.

alert: false
risk:
  - entity_type: user
    field: user.name
    score: 5

When alert is omitted or true, the rule alerts normally and the alert is enriched with risk context. See Risk-Based Alerting: Alert Enrichment.

Example Rules

The repository contains example rules in the examples/rules/ directory.