diff --git a/infrastructure/logging/alloy/config.alloy b/infrastructure/logging/alloy/config.alloy index 01e1560..b6a2216 100644 --- a/infrastructure/logging/alloy/config.alloy +++ b/infrastructure/logging/alloy/config.alloy @@ -247,21 +247,25 @@ loki.source.file "audit_rotated" { } loki.process "audit" { - // Field allowlist, as one JMESPath multi-select hash: the emitted line is a - // JSON object containing exactly these keys. Everything not listed — - // requestObject/responseObject in particular — is discarded with the parsed - // record, and a line that does not parse is dropped rather than forwarded. - // - // `stage.pack` is NOT used: promtail's pack stage embeds the original line - // under `_entry`, which would put responseObject.data straight back into the - // store. Verified end-to-end with loki.echo on a record carrying a plaintext - // `data.password`: 0 occurrences of the value in the output. + // Field allowlist. Everything not listed here — in particular + // requestObject/responseObject — is discarded with the parsed record. stage.json { expressions = { - time = "requestReceivedTimestamp", - verb = "verb", - resource = "objectRef.resource", - auditline = "{level: level, stage: stage, verb: verb, user: user.username, resource: objectRef.resource, apiGroup: objectRef.apiGroup, ns: objectRef.namespace, name: objectRef.name, subresource: objectRef.subresource, code: responseStatus.code, sourceIP: sourceIPs[0], userAgent: userAgent, auditID: auditID, requestURI: requestURI}", + level = "level", + stage = "stage", + verb = "verb", + user = "user.username", + resource = "objectRef.resource", + apiGroup = "objectRef.apiGroup", + ns = "objectRef.namespace", + name = "objectRef.name", + subresource = "objectRef.subresource", + responseCode = "responseStatus.code", + sourceIP = "sourceIPs[0]", + userAgent = "userAgent", + auditID = "auditID", + requestURI = "requestURI", + time = "requestReceivedTimestamp", } } @@ -270,8 +274,8 @@ loki.process "audit" { format = "RFC3339Nano" } - // verb x resource is small and fixed; `user` and the object name stay inside - // the JSON body so they do not multiply the stream count. + // verb x resource is small and fixed; `user` and the object name stay in the + // packed body so they do not multiply the stream count. stage.labels { values = { verb = "verb", @@ -279,8 +283,8 @@ loki.process "audit" { } } - stage.output { - source = "auditline" + stage.pack { + labels = [] } forward_to = [loki.write.local.receiver]