Skip to content

logwarden v0.8.0

Choose a tag to compare

@github-actions github-actions released this 20 Nov 06:08
· 45 commits to main since this release

logwarden v0.8.0

Status: Released 2026-11-20 · tag v0.8.0.

Findings on the source line, and analysis of the logs already in Kibana. SARIF puts each
finding on the log.info(...) call in the PR diff. check reads Kibana and Elasticsearch
exports directly, unwraps what Fluent Bit added to each record, and breaks the result down
by service.

What's new

  • Findings on the source line: SARIF.

    • lint-code --sarif FILE writes Semgrep's findings as SARIF 2.1.0.
    • check --sarif FILE does the same for runtime findings, when log lines say where they were
      logged: code.file.path, code.line.number and code.function.name (semconv 1.45).
      logwarden.logging.configure(callsite=True) adds these fields, and the pytest plugin turns
      this on during tests. The Go recipe gets them from slog's AddSource. A finding without a
      location is attached to its line in the log file, so it isn't lost. --source-root
      removes a path prefix, so locations match the repository.
    • Each SARIF rule links to its section of docs/rules.md at this version.
    • The GitHub Action gets a new input, sarif: "true" (default "false"). It uploads the
      check's SARIF with github/codeql-action/upload-sarif, which needs
      security-events: write; without it, the upload warns and the check still decides the
      job. Code scanning then shows each finding on the log call in the PR diff. Code scanning
      is available on public repositories, and on private ones with GitHub Advanced Security.
      The Action doesn't run lint-code; docs/integration.md shows the two steps that upload
      its SARIF.
  • Kibana and Elasticsearch exports as input. check, baseline, catalog and
    --snapshot/--compare accept these exports as well as JSON lines. The format is detected
    automatically, or set with --format:

    • csv: a Kibana Discover CSV report. Each row is one record, and each column is a field.
      • When a _source, log or message column holds the whole JSON line, that line is used.
        With message_field set (Fluent Bit's log), a cell that isn't JSON is a non-JSON line.
      • Kibana's - for missing values and its .keyword copies of text fields are dropped.
      • CSV loses value types, so values are converted back using the field's type in the
        registry (int, double, boolean). An empty cell means the field is missing.
      • When the export leaves out columns, the required-field rules aren't applied to the
        missing columns, because those fields may exist but weren't exported. The output names
        the missing columns and suggests exporting all fields. (Kibana 8 exports a _source
        column as -, so "all fields" is the way to get whole records.)
    • es: an Elasticsearch _search response, as saved from Kibana Dev Tools or curl.
      Records come from hits.hits[]._source. The file can hold one response or several
      scroll pages, as a JSON array or one response per line.
    • jsonl: one document per line (the bare document, or an object with _source), as
      written by elasticdump and similar tools.

    Findings refer to the row or hit number instead of the line number, and the Elasticsearch
    _id is kept when the export has it. docs/integration.md shows how to export a time
    window from Kibana Discover and with _search.

  • Records wrapped by Fluent Bit: [source]. Fluent Bit adds its own fields, and often
    keeps the service's line as a string in log. With the Kubernetes filter's Merge_Log On,
    it puts the fields at the top level, or under Merge_Log_Key. A new config section
    handles all three cases:

    [source]
    message_field = "log"            # parse the service's JSON from this field (string or object)
    ignore_fields = ["@timestamp", "kubernetes", "stream", "time", "_p"]   # added by Fluent Bit

    Fields that Fluent Bit added are then not reported as unknown fields. --message-field
    and --ignore-field set the same options on the command line.

  • Metrics per service. A Kibana export usually covers many services, so check now
    breaks its result down by service.name (or the field set in service_field):

    • for each service: the lines, the lines with a violation, a compliance percentage
      (lines without a violation), the violations by rule and the most frequent rule;
    • --json gains a services key;
    • the text output, the HTML report and the Markdown summary get a "By service" table;
    • --service NAME (repeatable) checks only those services;
    • --metrics FILE writes the same numbers in Prometheus text format, for a Pushgateway or
      the node_exporter textfile collector. The metric names are logwarden_lines_total,
      logwarden_violations_total and logwarden_lines_with_violations_total, labelled by
      service, and by rule for violations. watch in v0.9.0 will use the same names.

    Lines without a service are grouped as (none). Logged values never appear, only the
    service names.

  • pre-commit hook. .pre-commit-hooks.yaml provides logwarden-lint-code, which runs
    lint-code on the staged Python, Go, JavaScript/TypeScript and Java files. Semgrep stays out
    of logwarden's dependencies: the hook finds it the way lint-code does, on PATH or with uvx.

    - repo: https://github.com/Ingeniator/logwarden
      rev: v0.8.0
      hooks:
        - id: logwarden-lint-code

Breaking changes

None. --sarif, --format, [source], --metrics, the services and input keys, the
service (and, for exports, id) key of each finding, and the Action's sarif input are
all additions. The text output, the HTML report and the Markdown summary gain a "By service"
table when there is more than one service or a named one (the goldens changed for that and
for the new keys). JSON-lines input is detected as before, so existing commands
behave the same. configure() adds the callsite fields only with callsite=True. In tests the
pytest plugin turns it on, and the fields are semconv names, so existing checks keep passing.

Upgrading from v0.7.0

  • For PR annotations: add callsite=True to configure(), then set sarif: "true" and
    security-events: write in the workflow.
  • To analyse production logs: export from Kibana (CSV with all fields, or _search JSON), add
    a [source] section that matches your Fluent Bit output, and run
    logwarden check export.csv --html report.html.

Verification

CI run 44683194633 (commit 359a506):
193 tests passed on ubuntu py3.10, ubuntu py3.13 and macos py3.13; on windows py3.13 188 passed
and 5 were skipped (the POSIX and Semgrep tests, as before, plus lint-code --sarif, which needs
Semgrep). The action, review, sarif, package, plugin, recipes and docker jobs passed.

# Claim How it was checked Result
1 SARIF tests/test_sarif.py: check --sarif and lint-code --sarif validate against the SARIF 2.1.0 schema (tests/data/sarif-schema-2.1.0.json, jsonschema); runtime findings point at code.file.path:code.line.number (relative, absolute under cwd, and a /build/svc prefix removed with --source-root); a finding without a location points at its line in the log file; rule helpUris go to docs/rules.md#<rule> at this version; a clean run and a baselined run give no results; fingerprints don't change when the code moves. configure(callsite=True) writes the 3 fields (also for stdlib loggers, and with LOGWARDEN_CALLSITE=1), and they pass check; the pytest plugin turns them on while capturing. The Go recipe's output (examples/recipes/check.sh go) has the fields and passes. Throwaway PR #2 (closed, not merged) with the CI sarif job (sarif: "true"): it moved the known call on tests/data/sarif_demo/orders.py down a line and added log.info("Shipping order now", http_route=...). Code scanning's check said "2 new alerts in code changed by this pull request", with both annotations on line 15, the added call; the moved call kept alert #5 from main (screenshot of the diff). Found and fixed while checking: the first fingerprints included the line number, and upload-sarif's own primaryLocationLineHash changed with nearby edits, so an unchanged call showed up as new; both are now line-independent. Not done by the Action: lint-code; its SARIF is uploaded with the two steps in docs/integration.md ✅
2 Kibana and Elasticsearch exports Real exports in tests/data/exports/ (README there): Fluent Bit 3.1.9 shipped bad.jsonl to Elasticsearch 8.15.3 twice (line in log, and json parser), then: a _search response, two scroll pages one per line, elasticdump NDJSON, and Kibana 8.15.3 CSV reports (reporting API) of both indices with all fields. Each gives exactly bad.jsonl's rule counts (10 violations) with [source] options (test_claim2_3_real_exports_give_the_bare_counts). A CSV with hand-picked columns and no log loses the plain-text line, as it should. Synthetic tests: _source CSV, column CSV, a response, pages as an array and as NDJSON, dumps; types come back ("200", '-1, "1,234"); a CSV without service.version names the column and doesn't report it; --format overrides detection; a bad export or format → exit 2; findings carry the hit number and _id (line 3 (id2)); baseline, catalog and --compare accept exports. Found and fixed with the real exports: Kibana 8 writes - for missing values, adds .keyword columns, and exports a _source column as - (docs now say to export all fields); a non-JSON log cell made every column count as missing ✅
3 Fluent Bit [source] test_claim3_*: records with the line as a string in log, merged at the top level (Merge_Log), and under log_processed, each with Kubernetes metadata, give the same findings (line, rule, field) as the bare lines; the plain-text log → adr_non_json_line; without ignore_fields, the pipeline fields are unknown fields; [source] in logwarden.toml gives the same as the options; a bad ignore_fields → exit 2. Real Fluent Bit output (fluent-bit-raw.jsonl, fluent-bit-merged.jsonl, from its file output) gives bad.jsonl's counts ✅
4 Metrics per service test_claim4_*: 3 services and lines without one: lines, violations by rule, lines with violations, 33.3% compliance and the top rule in --json; the text, Markdown and HTML tables; (none) for the line without service.name and the plain-text line; --service filters; --metrics lines all match the Prometheus text format, with the 3 documented families and the expected values; the logged password appears in none of the outputs. Goldens regenerated (make golden): only the new keys and the "By service" table changed ✅
5 pre-commit hook pre-commit try-repo <this repo> logwarden-lint-code in a scratch git repo: a staged file with extra={"error": str(e)} → Failed with logwarden-banned-key-python at bad.py:6; a clean file → Passed; only a Markdown file staged → "(no files to check) Skipped", so Semgrep didn't start ✅
6 Docs and wiring docs/integration.md (SARIF section, §6 pre-commit, new §7 for Kibana/Elasticsearch exports, Fluent Bit and per-service metrics; [source] in §4), README (use cases), skill, AGENTS.md (layout, constraints), roadmap; the docs site builds in strict mode; test_docs_name_this_version passes for 0.8.0 ✅
7 CI green; release publishes CI above. Dry run: release run 44684104678 published 0.7.0.dev11 (built from 359a506 before the version bump) to TestPyPI and pushed the image :0.7.0.dev11. From TestPyPI in a clean venv with an empty cache (Weaver and semconv downloaded): bad.jsonl → 10 violations, and its --sarif validates (10 results); the real Kibana CSV and _search exports → the same 10 violations with the "By service" table, and --metrics written; the MCP server lists its 4 tools. The image, offline as --user 4242, reads the Kibana CSV: 10 violations ✅