Skip to content

Scopes

Normally, every incoming event is fully parsed and evaluated against every rule. Scopes can be used to route incoming events to specific rule subsets and to drop irrelevant events before full JSON parsing.

When scopes are used, each incoming event is tested against the scope definitions. The matched scope determines which rules the event is evaluated against. Events that don't match a scope, or match a scope with no referencing rules, are dropped.

Consider defining scopes when ingesting multiple log types but detecting on only a few, or when most events are irrelevant to most rules.

Defining Scopes

Scopes are defined inside YAML files in a directory:

scopes/auth.yaml
scopes:
  - name: auth
    field: action
    prefix: login-
Field Required Description
name Unique scope identifier
field Raw JSON field path to inspect. Supports gjson path syntax.
parent Parent scope. The event must match the parent's filter before this scope is evaluated.
case_sensitive If true, string comparisons use exact case matching. Default: false (case-insensitive).
(operator) Exactly one filter operator (see Filter Operators)

Filter Operators

Exactly one operator must be defined per scope.

Operator Example
equals equals: login-success
contains contains: login
prefix prefix: login-
suffix suffix: -failure
wildcard wildcard: login-*
exists exists: true

Hierarchy

All .yaml files in the scopes directory are merged at startup.

Scopes form a tree through parent references. The router evaluates scopes depth-first: when a scope matches, its children are tested next. The deepest and last match wins, a rule referencing network does not receive events scoped to network-traffic.

The engine always evaluates parent scopes before their children regardless of declaration order. Among siblings (scopes sharing the same parent), evaluation order follows file alphabetical order, then declaration order within each file.

Tip

To have a rule cover both a parent and child scope, list both in the scopes field on the rule.

Using Scopes in Rules

Add a scopes field at the top level of each rule with the scope names it should receive events from. Scopes are supported on event and aggregation rules. Composite rules must not specify scopes.

title: Password spraying activity
id: 100
type: aggregation
scopes: [auth]

detection:
  match: event.action == "login-failure"
  group_by: [source.ip]
  aggregation: len(uniq(map(events, .user.name))) > 3
  timespan: 20s

When scope definitions are loaded, scopes is required on every event and aggregation rule. Inobi will not start if a rule references an unknown scope name.

Configuration

Scopes are enabled by setting scopes.directory in the main config file. When absent, scope routing is disabled and every event is fully parsed and evaluated against every rule. See Config: Scopes.

Testing

Use inobi route to check which scope an event is routed to. It uses the scopes directory from the config:

inobi route -c config.yaml -e '{"action": "login-failure", "source": {"ip": "10.0.0.1"}}'

Events can also be piped from stdin, one per line. Add --json for JSON output:

cat events.json | inobi route -c config.yaml --json

inobi test also validates scope definitions and references.