Metadata-Version: 2.4
Name: pySigma-backend-databricks
Version: 0.2.1
Summary: pySigma backend for Apache Spark/Databricks
Author-email: Alex Ott <alexott@gmail.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/alexott/pySigma-backend-databricks
Project-URL: Issues, https://github.com/alexott/pySigma-backend-databricks/issues
Project-URL: Repository, https://github.com/alexott/pySigma-backend-databricks
Keywords: cybersecurity,apache spark,spark,sigma,databricks,lakewatch
Requires-Python: <3.15,>=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: THIRD_PARTY_NOTICES
Requires-Dist: inflection<0.6.0,>=0.5.1
Requires-Dist: pysigma<2.0.0,>=1.3.2
Provides-Extra: deploy
Requires-Dist: databricks-sdk>=0.171; extra == "deploy"
Dynamic: license-file

![Tests](https://github.com/alexott/databricks-sigma-backend/actions/workflows/test.yml/badge.svg)
![Coverage Badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/alexott/GitHub Gist identifier containing coverage badge JSON expected by shields.io./raw/alexott-databricks-sigma-backend.json)
![Status](https://img.shields.io/badge/Status-pre--release-orange)

Status: **experimental**, work in progress:

* Requires more testing

# pySigma Databricks Backend

This is the Databricks backend for pySigma. It provides the package `sigma.backends.databricks` with the `DatabricksBackend` class.
Further, it contains the following processing pipelines in `sigma.pipelines.databricks`:

* `snake_case`: convert column names into snake case format

See [CHANGELOG.md](CHANGELOG.md) for the changes in each release.

It supports the following output formats:

* `lakewatch`: Lakewatch detection rules (Unity Catalog governed), batch by default;
* `default`: plain Databricks/Apache Spark SQL queries;
* `dbsql`: Databricks SQL queries with rules metadata (title, status) embedded as comment;
* `detection_yaml`: Yaml markup for my own detection framework.

## Installation

```bash
pip install sigma-cli pySigma-backend-databricks
```

To deploy Lakewatch rules with `lakewatch-rule-deploy`, install the `deploy` extra as well (see
[Deploying rules](#deploying-rules)).

## Documentation

The README covers what you need to get started. The details are in `docs/`:

| Document | Contents |
|----------|----------|
| [Lakewatch rule output](https://github.com/alexott/pySigma-backend-databricks/blob/main/docs/lakewatch-output.md) | Sigma metadata mapping, output files, target modes (`workspace`, `content_pack`), content-pack output, alert summaries and overrides |
| [Parser discovery and conversion reports](https://github.com/alexott/pySigma-backend-databricks/blob/main/docs/discovery-and-reports.md) | Finding the parsers that fit your rules, and the `conversion_report.yaml` format |
| [Built-in profiles](https://github.com/alexott/pySigma-backend-databricks/blob/main/docs/built-in-profiles.md) | The profile of each supported parser, and its known limitations |
| [Writing profiles](https://github.com/alexott/pySigma-backend-databricks/blob/main/docs/writing-profiles.md) | Profile format, VARIANT paths and named entries, value transforms, keyword search and routing, scaffolding scripts, validation against live data |
| [Deploying rules](https://github.com/alexott/pySigma-backend-databricks/blob/main/docs/deploying.md) | `lakewatch-rule-deploy` in detail: ownership, updates, output and exit codes |
| [OCSF mode](https://github.com/alexott/pySigma-backend-databricks/blob/main/docs/ocsf.md) | Converting against OCSF gold tables, and how OCSF fields are rendered |

## Lakewatch Output

Generate [Lakewatch](https://www.databricks.com/product/lakewatch) detection rules from Sigma rules
(see the [Lakewatch documentation](https://docs.databricks.com/aws/en/lakewatch/)). Each rule is a
Unity Catalog governed resource. Rules are converted against the tables of Lakewatch parsers. A
*profile* maps the Sigma fields of a logsource to the columns of one parser's table, and the backend
ships a profile for each supported parser (see
[Built-in profiles](https://github.com/alexott/pySigma-backend-databricks/blob/main/docs/built-in-profiles.md)).
Converting against OCSF gold tables is optional (see
[OCSF mode](https://github.com/alexott/pySigma-backend-databricks/blob/main/docs/ocsf.md)).

### Lakewatch quick start

1. **Find the parsers that fit your rules.** Without `-O parsers`, nothing is converted. Instead,
   the backend reports which profiles can convert each rule, and suggests a `-O parsers=...` value:

   ```bash
   sigma convert -t databricks -f lakewatch rules/windows/
   ```

   Pick the parsers whose data you ingest: the suggestion lists every profile that fits. See
   [Parser discovery](https://github.com/alexott/pySigma-backend-databricks/blob/main/docs/discovery-and-reports.md#parser-discovery).

2. **Convert the rules** for the selected parsers. `-s` skips the rules that fail, instead of
   stopping at the first error:

   ```bash
   sigma convert -s -t databricks -f lakewatch -O parsers=aws_cloudtrail \
     -O table_name=main.sec.aws_cloudtrail -O catalog_name=main -O schema_name=sec \
     -O warehouse_id=1234567890abcdef rules/ -o detections.yaml
   ```

   With several parsers, give each its table with `table_map`:

   ```bash
   sigma convert -s -t databricks -f lakewatch \
     -O parsers=windows_sysmon_process,windows_security_process \
     -O table_map=windows_sysmon_process:main.sec.sysmon,windows_security_process:main.sec.winsec \
     -O catalog_name=main -O schema_name=sec -O warehouse_id=1234567890abcdef \
     -O output_dir=detections rules/windows/
   ```

   Each selected parser produces one rule per Sigma rule, named `<rule_name>__<profile>`. Multiple
   rules are emitted as separate `---` documents in one file. With `-O output_dir=<dir>`, each rule
   is written to its own `<dir>/<rule_name>.yaml`, together with a `conversion_report.yaml` that
   lists what converted, what failed and why (see
   [Conversion report](https://github.com/alexott/pySigma-backend-databricks/blob/main/docs/discovery-and-reports.md#conversion-report)).
   Don't use the `--output-dir`/`-od` option of sigma-cli: it writes only the bare SQL condition of
   each rule, not the rule documents.

3. **Review and deploy the rules** (see [Deploying rules](#deploying-rules)). Converted rules are
   disabled by default, so they can be tested first.

### Lakewatch options

Options are passed as `-O key=value`.

| Option | Default | Meaning |
|--------|---------|---------|
| `parsers` | *(none)* | Comma-separated profile ids, for example `aws_cloudtrail,okta_system_log`. Without it, parser discovery runs instead of a conversion. |
| `table_name` | *(none)* | Table to read from. Use it when exactly one parser is selected. |
| `table_map` | *(none)* | `profile:table,profile:table` for several parsers. Every selected profile needs a table. |
| `catalog_name` | *(required)* | `catalog_name` of the rule, also used as `batch.sql.default_catalog_name` to resolve unqualified tables. Conversion fails if it's unset. |
| `schema_name` | *(required)* | `schema_name` of the rule, also used as `batch.sql.default_schema_name`. Conversion fails if it's unset. |
| `warehouse_id` | *(required)* | `batch.warehouse_id`: the SQL warehouse that runs the rule. Conversion fails if it's unset (the server rejects batch rules without one). |
| `schedule` | `24h` | Rule schedule (Lakewatch duration). |
| `extend_lookback` | *(none)* | `timerange.extend_lookback`: widens the time window beyond the schedule. |
| `enabled` | `false` | `schedule.enabled`. Set `-O enabled=true` to schedule the rules immediately. |
| `default_fidelity` | *(from status)* | Override the rule fidelity. Accepts both `Investigative` and `FIDELITY_INVESTIGATIVE`. |
| `default_category` | `Static Signature` | Rule category. |
| `output_dir` | *(none)* | Write one file per rule, and `conversion_report.yaml`, into this directory. |
| `target` | `workspace` | `workspace` creates rules for the Lakewatch API, `content_pack` the rule documents of a Lakewatch content pack (see [Target modes](https://github.com/alexott/pySigma-backend-databricks/blob/main/docs/lakewatch-output.md#target-modes)). |
| `overrides` | *(none)* | YAML file with per-rule alert `summary`, `context` and `select` settings (see [Alert summaries](https://github.com/alexott/pySigma-backend-databricks/blob/main/docs/lakewatch-output.md#alert-summaries)). |
| `lakewatch_profiles_dir` | *(none)* | Directory with your own `*.yml` profiles. They are added to the built-in ones, and an id replaces a built-in id (see [Writing profiles](https://github.com/alexott/pySigma-backend-databricks/blob/main/docs/writing-profiles.md)). |
| `lakewatch_schemas` | *(none)* | JSON file with additional parser schemas, in the format of the bundled catalog. |
| `raw_log_field` | *(none)* | STRING column searched by keyword (unbound) searches, for every selected profile. |
| `prune_unsupported` | `true` | Drop fields that a profile lists as `unsupported` where that only narrows the rule, and fail the rule otherwise. `false` fails every rule that uses one. |

Sigma metadata maps to the rule: `title` becomes the alert summary, `description` the description
and objective, `level` the severity, `attack.*` tags the MITRE entries, and `falsepositives` the
runbook. Sigma `stable` rules get `FIDELITY_INVESTIGATIVE`, and all others `FIDELITY_DEVELOPMENT`.
The full mapping is in
[Lakewatch rule output](https://github.com/alexott/pySigma-backend-databricks/blob/main/docs/lakewatch-output.md#rule-metadata).
Only batch rules are generated (streaming is future work).

A profile lists the Sigma fields its parser has no data for as `unsupported`, for example
`OriginalFileName`. By default, a rule that uses one converts in a narrower form when dropping the
field can't make the rule match more than it was written to (for example one alternative of an
OR), and fails otherwise. This is visible: a `LakewatchPrunedWarning`, a `pruned` list in
`conversion_report.yaml` and a `sigma_pruned_fields` annotation. Pass `-O prune_unsupported=false`
to fail instead. See
[Pruning unsupported fields](https://github.com/alexott/pySigma-backend-databricks/blob/main/docs/writing-profiles.md#pruning-unsupported-fields).

### Supported parsers

Built-in profiles cover these Lakewatch parsers:

* **Cloud:** AWS CloudTrail, Okta, Azure (audit, sign-in, activity, Identity Protection),
  Microsoft 365 audit (general, Azure AD, Exchange), GCP Cloud Audit Logs, Google Workspace.
* **Web servers and proxies:** Cloudflare, GCP HTTP load balancer, Akamai WAF, AWS WAF, Zscaler ZIA,
  Cisco Umbrella.
* **EDR:** CrowdStrike FDR, SentinelOne Deep Visibility, Carbon Black Cloud.
* **Windows event logs:** Sysmon, Security, PowerShell and other channels. Most of these profiles
  need the custom Windows parsers, which aren't Lakewatch built-ins yet.

See [Built-in profiles](https://github.com/alexott/pySigma-backend-databricks/blob/main/docs/built-in-profiles.md)
for the profile ids, the logsources they match, and their limitations. To support another parser,
write your own profile (see
[Writing profiles](https://github.com/alexott/pySigma-backend-databricks/blob/main/docs/writing-profiles.md)).

### Correlation rules (Lakewatch)

The `lakewatch` format converts Sigma correlation rules of these types: `event_count`,
`value_count`, `temporal`, `temporal_ordered`, `value_sum`, `value_avg`, `value_percentile` and
`value_median`. They work over signals, as Lakewatch correlations do:

* A *base rule* (a rule that a correlation references) is a normal Lakewatch rule that writes
  signals. When the correlation has `generate: false` (the Sigma default), the base rule gets
  `suppress_until_time: "9999-12-31T23:59:59Z"`: it writes signals and opens no alerts. With
  `generate: true` it also alerts. Every referenced base rule gets
  `deduplication: DEDUPLICATION_ENABLED` and a `deduplication_time_window` equal to its run window
  (`schedule` plus `extend_lookback`), so overlapping runs don't write a signal twice.
* The *correlation rule* reads `` `<catalog>`.`__lakewatch`.`signals` `` for the rules of its base
  rules (one per converted profile). It uses a sliding window: for each signal, window `g` holds
  the signals of the same group in the `timespan` before it (`RANGE BETWEEN INTERVAL <seconds>
  SECONDS PRECEDING AND CURRENT ROW`), so a burst is found wherever it starts. The condition
  (`gt`, `gte`, `lt`, `lte`, `eq`, `neq`) is checked on each window, and the matching windows are
  reduced to one row per group: `window_start` is the earliest signal of a matching window and
  `window_end` the latest matching signal. When a group matches several times in one run,
  `window_start` and `window_end` span from its first to its last matching signal, which can be
  longer than `timespan`, and `event_count` and `value_count` are the largest values among the
  matching windows. The `timespan` can be given in seconds (`30s`).
* Each type adds its own output column to the alert context. Every correlation also has its
  group-by keys, `window_start`, `window_end` and `rules`.

  | Type | Output column |
  | --- | --- |
  | `event_count` | `event_count` |
  | `value_count` | `event_count`, `value_count` |
  | `temporal` | `event_count`, `rule_count` (no `rule_count` with an extended condition) |
  | `value_sum`, `value_avg`, `value_percentile`, `value_median` | `event_count` and the column named like the type |
  | `temporal_ordered` | none (no count column) |

* The numeric types read the value with `try_cast(<field> AS DOUBLE)`. A signal with a missing or
  non-numeric value is dropped. `value_median` is rendered as `percentile(<field>, 0.5)`, as
  Databricks rejects `median()` as a window function with a frame.
* A `temporal` correlation can use an extended condition (`rule_a and rule_b`, `a or (b and c)`,
  `not`): each rule name becomes a test on the rules seen in the window. Other types reject
  extended conditions.
* A `temporal_ordered` correlation matches when its rules fire in the order listed, within the
  `timespan`, for the same group. Only the default condition (`gte <number of rules>`) is
  supported, and extended conditions are rejected. A step at the same timestamp as the previous one
  counts as in order, except two consecutive steps of the same rule, which must be strictly
  ordered. Limit: with a non-consecutive repeat (`a, b, a`) and all three signals in the same
  second, one `a` signal can fill steps 1 and 3. Cost: one window pass per step after the first.
* A *chain* is a correlation that references another correlation. When the parent correlation has
  `generate: false` (the default), a referenced child correlation is emitted suppressed, so it
  writes signals and opens no alerts; with `generate: true` on the parent it alerts too. The parent's
  `group-by` keys must be output columns of the child, otherwise the parent fails, naming the child
  and the key. A parent fails when any correlation it references has no converted document, and a
  `temporal` or `temporal_ordered` parent fails when any rule it references has none. A chained
  `event_count` counts the child's signals (alerts), not events. The `extend_lookback` is the
  timespan plus the schedule times the chain depth. Reference cycles fail with
  `correlation reference cycle`.
* A `value_count` counts the distinct values of its `field`. With a list of fields it counts the
  distinct combinations (`size(collect_set(struct(f1, f2)))`), and every field becomes a context key.
* `event_count`, `value_count`, `temporal` and `value_sum` conditions with `lt`, `lte`, `neq` or
  `eq`, and extended conditions with `not`, convert with a `UserWarning` (also in the report's
  result `warnings`; it points at the caller). A window with few signals exists around almost any
  signal, and the count of a sliding window climbs one signal at a time through a burst, so `eq: 5`
  fires for any group with at least 5 signals in the timespan. Such a rule can match much more
  than intended. `value_avg`, `value_percentile` and `value_median` don't warn: their values
  don't climb with the signal count.
* Each `group-by` and value field becomes a context key of the base rule, with the characters
  outside `[A-Za-z0-9_]` replaced by `_` (`userIdentity.arn` becomes `userIdentity_arn`) and a `_`
  prefix when it starts with a digit. The key is filled from the select column `sigma_corr_<key>`.
  An alias adds a key from the alias name, built the same way (`src-ip` becomes `src_ip`), and the
  correlation groups by it. For a base rule, a key that clashes with a context or `select` entry
  of its own override is an error, and so are two keys that differ only in case (`User` and `user`).
* The correlation's `extend_lookback` is the timespan plus the schedule (times the chain depth), or
  `-O extend_lookback` when that is larger. Its alert summary is `<title> by {keys}`. Only the `default` entry of
  the overrides file for the correlation id and the `lakewatch:` attribute apply, and they can change
  the summary and context. Entries scoped to a profile for that id are ignored, with a `UserWarning`
  that names them. A `select` override on a correlation is an error (this is separate from the
  base-rule clash rule above).

Converted from a `value_count` correlation with `-O parsers=aws_cloudtrail` (trimmed):

```yaml
rule_name: access_denied__aws_cloudtrail     # base rule
batch:
  sql:
    query: |-
      SELECT *, ..., try_variant_get(userIdentity, '$.arn', 'string') AS `sigma_corr_userIdentity_arn`,
             eventName AS `sigma_corr_eventName`
      FROM main.sec.aws_cloudtrail
      WHERE IN_TIMERANGE(time) AND (lower(errorCode) = 'accessdenied')
deduplication: DEDUPLICATION_ENABLED
deduplication_time_window: 1d
suppress_until_time: '9999-12-31T23:59:59Z'
output:
  context:
    userIdentity_arn: '{sigma_corr_userIdentity_arn}'
    eventName: '{sigma_corr_eventName}'
---
rule_name: access_denied_sweep               # correlation rule
timerange:
  extend_lookback: 1450m
batch:
  sql:
    query: |-
      WITH sig AS (
      SELECT DISTINCT event_time, regexp_extract(rule_name, '([^.]+)$', 1) AS rule, CASE rule_name WHEN 'main.sec.access_denied__aws_cloudtrail' THEN 'base' END AS sigma_rule, get_json_object(context, '$.userIdentity_arn') AS `userIdentity_arn`, get_json_object(context, '$.eventName') AS `eventName`
      FROM `main`.`__lakewatch`.`signals`
      WHERE IN_TIMERANGE(event_time) AND rule_name IN ('main.sec.access_denied__aws_cloudtrail')
      ),
      w AS (
      SELECT *, count(*) OVER g AS event_count, size(collect_set(`eventName`) OVER g) AS value_count, min(event_time) OVER g AS window_start, collect_set(sigma_rule) OVER g AS window_rules
      FROM sig
      WHERE `userIdentity_arn` IS NOT NULL AND `eventName` IS NOT NULL
      WINDOW g AS (PARTITION BY `userIdentity_arn` ORDER BY event_time RANGE BETWEEN INTERVAL 600 SECONDS PRECEDING AND CURRENT ROW)
      )
      SELECT max(event_time) AS time, min(window_start) AS window_start, max(event_time) AS window_end, `userIdentity_arn`, max(event_count) AS event_count, max(value_count) AS value_count, array_join(array_sort(array_distinct(flatten(collect_list(window_rules)))), ', ') AS rules
      FROM w
      WHERE value_count >= 15
      GROUP BY `userIdentity_arn`
      HAVING count(*) > 0
deduplication: DEDUPLICATION_ENABLED
deduplication_time_window: 2890m
output:
  summary: Access Denied Sweep by {userIdentity_arn}
  default_context: false
  event_time_column: time
```

Limits:

* Only `target=workspace` in parsed mode (`-O parsers=...`). `content_pack` and OCSF mode reject
  correlations.
* `temporal_ordered` supports only `gte <number of rules>`, and no extended condition.
* A suppressed signal-only rule (a base rule or child correlation) whose correlations all failed is
  not emitted; the report lists it as skipped with `its correlation rules failed`.
* A `group-by` or value key can't be named like a column the correlation SQL adds (`rule`,
  `sigma_rule`, `event_time`, `time`, `window_start`, `window_end`, `event_count`, `value_count`,
  `rule_count`, `value_sum`, `value_avg`, `value_percentile`, `value_median`, `rules`,
  `window_rules`, `window`, `g`, `start`, `prev_start`, `is_new`; in any case): the correlation
  fails with `group-by key <key> clashes with a column of the correlation SQL`.
* So a parent can't use a child's output column such as `event_count` directly as its `field` or
  `group-by`. Give it an alias (`aliases: {n: {<child name>: event_count}}`) and use `field: n`;
  the error message suggests this.
* A value key that is also a `group-by` key is read as a number (`try_cast(... AS DOUBLE)`), so
  its values render like `5.0` and groups with a non-numeric value are dropped.
* A correlation fails with `no converted base rules` when none of its base rules converted. When a
  base rule converted for only some profiles, the correlation uses those, and its report result has
  a `note` naming the missing ones (a base rule with no matching profile is listed too).
* In `content_pack` and OCSF mode, a base rule with `generate: false` is skipped, with the reason
  `referenced by a correlation rule`.
* Known gap: the `azure_monitor_activity` profile has no `caller` field, so a group-by on `caller`
  fails.

See [Conversion report](https://github.com/alexott/pySigma-backend-databricks/blob/main/docs/discovery-and-reports.md#conversion-report)
for how base rules and correlations show up in the report.

## Deploying rules

To deploy the converted workspace rules, use one of the options below. Content-pack output isn't
deployed this way; install the pack instead.

**UI.** Open Detection rules, pick the rule, then Edit rule, Edit as YAML, and Save changes. See
[Edit a rule as YAML](https://docs.databricks.com/aws/en/lakewatch/detections/manage-detection-rules#edit-a-rule-as-yaml).
`catalog_name`, `schema_name` and `rule_name` can't be changed after the rule is created.

**One rule with the Databricks CLI** (Beta, CLI v1.27 or later). The CLI takes JSON, so convert the
YAML file first:

```bash
python -c 'import json,sys,yaml; json.dump(yaml.safe_load(open(sys.argv[1])), sys.stdout)' rule.yaml > rule.json
databricks lakewatch create-rule --json @rule.json --profile <profile>
```

**Many rules with `lakewatch-rule-deploy`.** The command creates or updates the workspace rules
written by `sigma convert -t databricks -f lakewatch`. It deploys detection rules only, not parsers,
data sources or content packs. Install it with the `deploy` extra:

```bash
pip install "pySigma-backend-databricks[deploy]"
```

```bash
sigma convert -s -t databricks -f lakewatch -O parsers=aws_cloudtrail \
  -O table_name=main.sec.aws_cloudtrail -O catalog_name=main -O schema_name=sec \
  -O warehouse_id=1234567890abcdef -O output_dir=detections rules/
lakewatch-rule-deploy --profile <profile> --dry-run detections/
lakewatch-rule-deploy --profile <profile> detections/
```

Common flags:

| Flag | Meaning |
|------|---------|
| `--profile PROFILE` | Databricks CLI profile. Default: the SDK's standard auth chain. |
| `--dry-run` | Validate and print the planned changes; write nothing. |
| `--validate-only` | Validate the rules that would be written; write nothing. |
| `--warehouse-id ID` | Deploy with another SQL warehouse than the one in the files; also used for the validation dry run. |
| `--catalog C`, `--schema S` | Deploy into another catalog or schema than the one in the files. |
| `--force` | Overwrite rules that were not made from this Sigma rule. |
| `--json` | Print the result as JSON. |

Redeploying is safe: a rule is updated only if it was made from the same Sigma rule, unchanged
rules are left alone, `schedule.enabled` is kept, and nothing is ever deleted. Creating or updating
a rule starts a one-time run of it on the server. See
[Deploying rules](https://github.com/alexott/pySigma-backend-databricks/blob/main/docs/deploying.md)
for all flags, the output format and the exit codes.

## Plain SQL output

The `default`, `dbsql` and `detection_yaml` formats produce Spark SQL `WHERE` conditions, with no
parser profile:

```bash
sigma convert -t databricks rules/windows/process_creation/proc_creation_win_whoami_execution.yml
sigma convert -t databricks -f dbsql -p snake_case rules/windows/
```

Equality lists on one field render as a single `IN (...)`, and `|cidr` lists as one
`exists(array(...), ...)`, so a long list repeats the field expression once:

```sql
lower(Image) IN ('a.exe', 'b.exe')
```

### CIDR Matching

The `|cidr` modifier is converted using the built-in Databricks IP functions
[`ip_cidr_contains`](https://docs.databricks.com/aws/en/sql/language-manual/functions/ip_cidr_contains)
and `try_ip_as_binary` (Databricks Runtime 18.2+, IPv4 and IPv6). Field values that aren't valid
IP addresses evaluate to `NULL` instead of failing the query. Note that, following SQL `NULL`
semantics, such rows don't match the negated condition either (e.g. `condition: not sel`), so they
are excluded from both `sel` and `not sel` results:

```yaml
detection:
    sel:
        src_ip|cidr: 192.168.0.0/16
    condition: sel
```
Generates: `ip_cidr_contains('192.168.0.0/16', try_ip_as_binary(src_ip))`

For other Spark SQL engines (e.g. open source Apache Spark), override the expression with the
`cidr_expression` option. It's a format string with the placeholders `{field}`, `{value}`
(whole CIDR), `{network}`, `{prefixlen}` and `{netmask}`:

```bash
sigma convert -t databricks -O "cidr_expression=cidrmatch({field}, '{value}')" rule.yml
```

```python
backend = DatabricksBackend(cidr_expression="cidrmatch({field}, '{value}')")
```

You need to register the corresponding function (here `cidrmatch`) as a UDF yourself.

### Unbound Keyword Search

Sigma rules with unbound keywords (values without field names) search the raw log line. By
default, the backend looks for keywords in a field named `raw` (`raw_data` when the target is
OCSF). Set another field with `-O raw_log_field=message`, or
`DatabricksBackend(raw_log_field="message")`. With `-f lakewatch`, each profile defines its own raw
event (see
[Keyword search and routing](https://github.com/alexott/pySigma-backend-databricks/blob/main/docs/writing-profiles.md#keyword-search-and-routing)).

```yaml
detection:
    selection:
        EventID: 4688
    keywords:
        - 'mimikatz'
        - '|re': '.*evil(cmd|powershell).*'
    condition: selection and keywords
```

Generates: `EventID = 4688 AND (contains(lower(raw), 'mimikatz') OR raw rlike '.*evil(cmd|powershell).*')`

Keywords in a list are ORed, and `'|all'` ANDs them. Wildcards turn into `contains()`
(`*malware*`), `startswith()` (`cmd.exe*`) or `endswith()` (`*.dll`).

## Maintainer

This backend is currently maintained by:

* [Alex Ott](https://github.com/alexott/)
