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 FILEwrites Semgrep's findings as SARIF 2.1.0.check --sarif FILEdoes the same for runtime findings, when log lines say where they were logged:code.file.path,code.line.numberandcode.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'sAddSource. A finding without a location is attached to its line in the log file, so it isn't lost.--source-rootremoves a path prefix, so locations match the repository.- Each SARIF rule links to its section of
docs/rules.mdat this version. - The GitHub Action gets a new input,
sarif: "true"(default"false"). It uploads the check's SARIF withgithub/codeql-action/upload-sarif, which needssecurity-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 runlint-code;docs/integration.mdshows the two steps that upload its SARIF. - Kibana and Elasticsearch exports as input.
check,baseline,catalogand--snapshot/--compareaccept 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,logormessagecolumn holds the whole JSON line, that line is used. Withmessage_fieldset (Fluent Bit'slog), a cell that isn't JSON is a non-JSON line. - Kibana's
-for missing values and its.keywordcopies 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
_sourcecolumn as-, so "all fields" is the way to get whole records.)
- When a
es: an Elasticsearch_searchresponse, as saved from Kibana Dev Tools orcurl. Records come fromhits.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 byelasticdumpand 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=Truetoconfigure(), then setsarif: "true"andsecurity-events: writein the workflow. - To analyse production logs: export from Kibana (CSV with all fields, or
_searchJSON), add a[source]section that matches your Fluent Bit output, and runlogwarden 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. Real publish: tag v0.8.0 → release run 44685482948 published 0.8.0 to PyPI, pushed ghcr.io/ingeniator/logwarden:0.8.0 and :latest (both report 0.8.0) and created the GitHub release. From PyPI in a clean environment with empty caches: uvx logwarden==0.8.0 on bad.jsonl → 10 violations, and its --sarif validates; the real Kibana CSV and _search exports → 10 violations with the per-service table and a 20-line --metrics file; logwarden[mcp]==0.8.0 serves its 4 tools. The image :0.8.0, offline as --user 4242, reads the Kibana CSV: 10 violations. pre-commit try-repo https://github.com/Ingeniator/logwarden --ref v0.8.0 fails on the staged bad.py with the finding |
✅ |