pySigma Loki backend
Project description
pySigma Loki Backend
This is the Loki backend for pySigma. It provides the package sigma.backends.loki
with the LogQLBackend
class.
It supports the following output formats for Sigma rules:
default
: plain Loki LogQL queriesruler
: creates Loki LogQL queries in the ruler (YAML) format for generating alerts
It also supports the following query formats for and categories of Sigma Correlation rules:
default
format using LogQL metric queries:event_count
value_count
It includes the following pipeline transformations in sigma.pipelines.loki
:
SetCustomAttributeTransformation
: adds a specified custom attribute to a rule, which can be used to introduce a stream selector or parser expression into the generated query- The
LokiCustomAttributes
enum contains the relevant custom attribute names used by the backend
- The
Further, it contains the processing pipelines in sigma.pipelines.loki
:
loki_log_parser
: converts field names to logfmt labels used by Grafanaloki_promtail_sysmon
: parse and adjust field names for Windows sysmon data produced by promtail- Note: most rules lack the
sysmon
service tag, and hence this pipeline should be used in combination with the generic sysmon pipeline
- Note: most rules lack the
loki_okta_system_log
: parse the Okta System Log event json, adjusting field-names appropriately
When converting rules into queries, the backend has the following optional arguments:
add_line_filters
(boolean, default:False
): ifTrue
, attempts to infer and add new line filters to queries without line filters, to improve Loki query performancecase_sensitive
(boolean, default:False
): ifTrue
, defaults to generating case-sensitive query filters, instead of case-insensitive filters that the Sigma specification expects, trading between Loki query performance and potentially missing data with unexpected casing- Note: if the generated query will be executed on Loki v2.8.2 or older, this argument should be set to
False
, as these versions of Loki may contain issues with case-insensitive filters, which cause such queries to fail to match desired data
- Note: if the generated query will be executed on Loki v2.8.2 or older, this argument should be set to
This backend is currently maintained by:
Installation
To get started developing/testing pySigma-backend-loki, these steps may help you get started:
- Install poetry
- Clone this repository and open a terminal/shell in the top-level directory
- Run
poetry install
to install the Python dependencies - Run
poetry shell
to activate the poetry environment - Check it all works by running
poetry run pytest
- (Optional) If you wish to validate the generated rules using sigma_backend_tester.py, install LogCLI
- (Optional, but recommended) To enable the Git hooks, run the following command from the root directory of the repository:
git config --local core.hooksPath .githooks/
Releasing
To release new versions of pySigma-backend-loki, we use GitHub actions to update PyPI. When the main branch is in state that is ready to release, the process is as follows:
- Determine the correct version number using the Semantic Versioning methodology. All version numbers should be in the format
\d+\.\d+\.\d+(-[0-9A-Za-z-]+)?
- Update pyproject.toml with the new version number
- Commit and push the change to GitHub, validate that the GitHub actions tests pass, and merge the PR into main
- Checkout main and create a signed tag for the release, named the version number prefixed with a v, e.g.,
git tag --sign --message="Release vX.X.X" vX.X.X
- Push the tag to GitHub, e.g.,
git push --tags
, and validate that the release to the test instance of PyPI is successful - Run
poetry build
to produce distributable versions indist/
- Create a release in GitHub against the appropriate tag. If the version number starts with
v0
, or ends with-alpha/beta
etc., mark it as a pre-release, and attach the distributable files to the release - Validate that the release to PyPI GitHub action is successful
- If this release supports a new minor or major version of
pySigma
, do a pull request on the pySigma-plugin-directory to reflect that
Work in progress
These features are currently either WIP or are planned to be implemented in the near future.
- Various processing pipelines for other applications and log sources
- Generating more accurate log stream selectors based on logsource
- Translate field names in Sigma signatures into relevant labels for Loki using pipelines
Won't implement (probably)
These features are not easily supported by the backend, and hence are unlikely to be implemented.
- More complex keyword/line filter searches than ANDs of ORs
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pysigma_backend_loki-0.12.1.tar.gz
.
File metadata
- Download URL: pysigma_backend_loki-0.12.1.tar.gz
- Upload date:
- Size: 23.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.0 CPython/3.8.18 Linux/5.15.0-1071-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b97dee78a93cbc1bab7b5f0ec96482a9de6e63625bbda5fd4cb266d39573aaf |
|
MD5 | a7b67ad7e673e00a52e1954f7fbdfbd1 |
|
BLAKE2b-256 | c96aed1d0c173b05ee42985b27f57cc2d7f21571f845a6d605e70ed74070c6cd |
File details
Details for the file pysigma_backend_loki-0.12.1-py3-none-any.whl
.
File metadata
- Download URL: pysigma_backend_loki-0.12.1-py3-none-any.whl
- Upload date:
- Size: 23.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.0 CPython/3.8.18 Linux/5.15.0-1071-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ad52b9a03701784361f7dbe6e6d6ecc608fa81bc73f172e26e7dfb6987c74ed |
|
MD5 | 9b49d56df6925b1bc2a55c08bff69360 |
|
BLAKE2b-256 | 7f3517e6b52c30fec11e91bfaef65f091a3e6ff18cf61c685a3803bdda467528 |