fix(logging): build the audit line from a JMESPath allowlist, never pack the raw record
stage.pack embeds the original line under `_entry`, so the first cut wrote responseObject.data (plaintext secrets) into Loki anyway. Replace pack with a single JMESPath multi-select hash + stage.output: the emitted line contains exactly the allowlisted keys and nothing else, with proper JSON escaping. Verified end-to-end against a synthetic record carrying data.password using loki.echo: 0 occurrences of the value, labels resource/verb still present.
This commit is contained in:
parent
d65296c92a
commit
78f94ab85e
1 changed files with 17 additions and 21 deletions
|
|
@ -247,25 +247,21 @@ loki.source.file "audit_rotated" {
|
||||||
}
|
}
|
||||||
|
|
||||||
loki.process "audit" {
|
loki.process "audit" {
|
||||||
// Field allowlist. Everything not listed here — in particular
|
// Field allowlist, as one JMESPath multi-select hash: the emitted line is a
|
||||||
// requestObject/responseObject — is discarded with the parsed record.
|
// 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.
|
||||||
stage.json {
|
stage.json {
|
||||||
expressions = {
|
expressions = {
|
||||||
level = "level",
|
time = "requestReceivedTimestamp",
|
||||||
stage = "stage",
|
verb = "verb",
|
||||||
verb = "verb",
|
resource = "objectRef.resource",
|
||||||
user = "user.username",
|
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}",
|
||||||
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",
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -274,8 +270,8 @@ loki.process "audit" {
|
||||||
format = "RFC3339Nano"
|
format = "RFC3339Nano"
|
||||||
}
|
}
|
||||||
|
|
||||||
// verb x resource is small and fixed; `user` and the object name stay in the
|
// verb x resource is small and fixed; `user` and the object name stay inside
|
||||||
// packed body so they do not multiply the stream count.
|
// the JSON body so they do not multiply the stream count.
|
||||||
stage.labels {
|
stage.labels {
|
||||||
values = {
|
values = {
|
||||||
verb = "verb",
|
verb = "verb",
|
||||||
|
|
@ -283,8 +279,8 @@ loki.process "audit" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage.pack {
|
stage.output {
|
||||||
labels = []
|
source = "auditline"
|
||||||
}
|
}
|
||||||
|
|
||||||
forward_to = [loki.write.local.receiver]
|
forward_to = [loki.write.local.receiver]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue