Skip to content

SIEM integration ​

BatleHub writes its audit trail twice: as rows in access_events, which the console's audit log reads, and — when [logging] format = "json" — as one JSON line per row on stdout, which a collector ships to a SIEM. The line is emitted where the row is written, with the same fields, so a detection rule and an export of the table never disagree about what happened. The repository ships Sigma rules for that stream under deploy/siem/sigma/.

This page is the reference for the stream and the rules. Turning it on is one setting, documented in configuration § [logging].

Turning it on ​

toml
[logging]
format = "json"

Every log line becomes a JSON object. The audit lines are the ones with event.dataset = "batlehub.audit" (equivalently target = "batlehub::audit"); every other line is an ordinary log line in the same format. There is no file sink and nothing to rotate: the collector reads stdout.

The default, text, writes exactly what this server wrote before the stream existed — and no audit lines at all, because a download per line is noise in a log a human reads.

Field reference ​

FieldExampleMeaning
event.datasetbatlehub.auditThe selector. Every audit line has it, no other line does
event.kindeventECS constant
event.categoryauthenticationauthentication, iam, configuration or package — fixed per action
event.actioncredential_rejectedThe action, in the audit log's own snake_case vocabulary
event.outcomedeniedallowed, denied or error
event.reasonblocked: malware flagged by osv (…)Why a request was refused; empty when allowed
event.idUUIDThe row's id in access_events
user.idaliceThe principal, as the authenticating provider names it; empty for anonymous; system, or system:<task>, for what the process did on its own — an automatic IP ban, an audit lifecycle run, the scheduled storage coherence check are system, a block the upstream-disappearance audit placed is system:upstream-audit. Match the system prefix to find them all
user.rolesuseranonymous, user or admin
source.ip203.0.113.9The caller, as the proxy-trust rules resolved it — never a raw X-Forwarded-For
user_agent.originalnpm/10.9.0The client's User-Agent
batlehub.registrynpmThe registry, for package events
package.name, package.versionleft-pad, 1.3.0The coordinate, for package events
batlehub.audit.detailtoken_id=… name="ci"What a non-package event is about — a token, a provider, a grant's subject. Never a secret
batlehub.audit.throttled_count20Attempts a throttled writer held back before this row (see below)
batlehub.audit.persistedtrueWhether the database write this line mirrors succeeded
span.request_id7f0c…The HTTP request the event belongs to; on every line of that request

A field with nothing to say is an empty string, not an absent key.

batlehub.audit.persisted = false means the line was emitted and the row was not stored — a database outage. The stream is then the only record, which is the case for shipping it at all.

What is recorded ​

Every action the audit log records is on the stream: downloads and listings, blocks, deletions, grants, retention and cache runs, purges. Six actions exist for authentication:

event.actionWhenbatlehub.audit.detail
sign_inAn OIDC sign-in completedprovider=<name>
sign_in_failedA callback failed; event.reason is the class — state_mismatch, token_exchange, claims, nonce, …provider=<name> when known
token_createA personal access token was mintedtoken_id=<uuid> name="<name>"
token_revokeA personal access token was revokedtoken_id=<uuid>
token_new_sourceA token was accepted from an address other than its last onetoken_id=<uuid> previous_ip=<ip>
credential_rejectedA credential was presented and no provider accepted it—

No line ever carries a token value, a token hash, an authorization code or a password.

credential_rejected is throttled: one row per source IP per minute, per server process. The attempts held back are counted, and the count rides on the next row written for that IP as batlehub.audit.throttled_count. When no attempt follows, the server writes that row itself within 10 seconds of the window's end, at most 70 seconds after the first attempt (and at a clean shutdown): it has no user agent, its time is when it was written, and it stands for one of the held-back attempts, so its count is the others. Either way, one plus throttled_count, summed over the rows, is the number of attempts. A burst of twenty-one refused attempts in a minute that then stops is therefore one row with a count of 0, then a row with a count of 19. A process that crashes loses what it held back. With n replicas each writes its own rows.

token_new_source is checked when the token's last-used time is written, at most once a minute per token. A token with no recorded address yet — the first use after an upgrade — is not "new".

Configuration reloads join the stream as config_applied and config_rejected, the latter for a candidate the file watcher or the console editor refused. Both carry the admin who sent the candidate in user.id; a candidate from the file watcher carries file-watcher.

The shipped rules ​

RuleFires onLevel
audit_purge.ymlany audit_purgehigh
grant_to_anonymous.ymla grant_write whose subject is * or role:anonymoushigh
blocked_package_pulled.ymla download of a coordinate a malware flag or a MALWARE_SIGNAL verdict blockshigh
credential_rejected_burst.ymla credential_rejected row carrying a throttled_count of 10 or moremedium
sign_in_failed_burst.yml5 sign_in_failed from one source.ip in 10 minutesmedium
denied_download_burst.yml50 denied downloads from one source.ip in 5 minutesmedium
bulk_pull.ymlone user.id downloading 300 distinct packages in 10 minutesmedium
token_new_source.ymlany token_new_sourcelow
retention_or_cache_clear.ymlcache_clear, retention_run, tombstone_compactlow
config_rejected.ymlany config_rejectedlow

The thresholds are starting points. bulk_pull.yml in particular should sit above the largest dependency graph your builds resolve, and retention_or_cache_clear.yml is meant to be restricted to outside your maintenance window with your SIEM's own time filter, which Sigma cannot express.

Convert them for your backend with sigma-cli:

bash
uvx --from sigma-cli sigma plugin install splunk
uvx --from sigma-cli sigma convert -t splunk --without-pipeline deploy/siem/sigma/

The field names are already ECS, so no processing pipeline is needed. deploy/siem/README.md in the repository carries a Vector and a Fluent Bit snippet for shipping the stream.

Adding a rule ​

  1. Write it under deploy/siem/sigma/, one file per rule. A burst rule is two documents in one file: a named base rule and the correlation that counts it.
  2. Add the file to deploy/siem/fixtures/expected.json — true if the recorded stream should make it fire, false if it should stay quiet — and, if the stream has nothing to test it against, add lines to fixtures/stream.jsonl that do and lines that nearly do.
  3. Run task siem:check. It runs sigma check strictly, then replays the stream through every rule, and fails if a rule reads a field the server does not emit. That last check reads the field list from crates/core/src/services/audit_stream.rs, so a renamed field breaks the build instead of silently blinding a rule.

Not covered yet ​

  • Tamper evidence. A signed hash chain over the trail, and the audit_chain_gap.yml rule that watches it from the SIEM side, land with RFC 0036's phase 5. Until then, a copy of the stream held outside the database is the only defence against an edited row.
  • Retention and pseudonymisation of the rows themselves are phase 4. The stream is unaffected: what a collector has stored is governed by the collector's own retention.

Released under the Apache 2.0 License. Made with care and too much coffee.