infra(logging): ship kube-apiserver audit log with secret bodies stripped #59
2 changed files with 110 additions and 0 deletions
|
|
@ -83,6 +83,12 @@ spec:
|
|||
- name: dockerlogs
|
||||
mountPath: /var/lib/docker/containers
|
||||
readOnly: true
|
||||
# kube-apiserver audit log (siriussec only). Read-only: the
|
||||
# apiserver owns that directory and its rotation; the collector
|
||||
# never writes to or prunes it.
|
||||
- name: audit
|
||||
mountPath: /var/log/kubernetes/audit
|
||||
readOnly: true
|
||||
# NOT /var/lib/alloy/...: that path is 0770 alloy:alloy in the
|
||||
# image, and this pod drops ALL capabilities (so root has no
|
||||
# CAP_DAC_OVERRIDE) — traversal of the parent is denied. /var/lib
|
||||
|
|
@ -114,6 +120,10 @@ spec:
|
|||
hostPath:
|
||||
path: /var/lib/docker/containers
|
||||
type: DirectoryOrCreate
|
||||
- name: audit
|
||||
hostPath:
|
||||
path: /var/log/kubernetes/audit
|
||||
type: DirectoryOrCreate
|
||||
- name: data
|
||||
hostPath:
|
||||
path: /var/lib/alloy-data
|
||||
|
|
|
|||
|
|
@ -190,6 +190,106 @@ loki.source.file "docker_logs" {
|
|||
tail_from_end = false
|
||||
}
|
||||
|
||||
// ------------------------------------------- kube-apiserver audit log (host file)
|
||||
// siriussec only. The apiserver writes JSON audit records to
|
||||
// /var/log/kubernetes/audit/audit.log (mode 600 root; the apiserver rotates it
|
||||
// itself: 100 MB x 48, compressed, ~2.2 GB/day). This is a host file, not pod
|
||||
// output, hence the extra hostPath mount in alloy.yaml.
|
||||
//
|
||||
// SECURITY — this source does NOT forward records as-is. At
|
||||
// `level: RequestResponse` the record for a `get secrets` carries
|
||||
// `responseObject.data`: the plaintext secret value. Shipping verbatim would
|
||||
// copy every secret that has been read into a second queryable system. Instead
|
||||
// the record is parsed and re-emitted as a packed *allowlist* of fields, so
|
||||
// `requestObject` / `responseObject` never reach Loki. `stage.json` drops any
|
||||
// line it cannot parse, so a malformed record cannot fall through to raw bytes.
|
||||
// (Filter is deliberately unconditional — stricter than "strip only for
|
||||
// objectRef.resource == secrets". If audit bodies for *writes* are ever wanted,
|
||||
// that is a separate, reviewed change.)
|
||||
//
|
||||
// Only the live file plus the rotated `.gz` archives are read; nothing in this
|
||||
// directory is ever deleted by the collector, so the apiserver's own 4.8 GB /
|
||||
// 7-day rotation stays the only thing pruning it. Loki's 192h retention is
|
||||
// independent and applies to the *stored copies*.
|
||||
local.file_match "audit_live" {
|
||||
path_targets = [{
|
||||
"__path__" = "/var/log/kubernetes/audit/audit.log",
|
||||
job = "kube/apiserver-audit",
|
||||
node = sys.env("NODE_NAME"),
|
||||
}]
|
||||
sync_period = "10s"
|
||||
}
|
||||
|
||||
local.file_match "audit_rotated" {
|
||||
path_targets = [{
|
||||
"__path__" = "/var/log/kubernetes/audit/*.log.gz",
|
||||
job = "kube/apiserver-audit",
|
||||
node = sys.env("NODE_NAME"),
|
||||
}]
|
||||
sync_period = "1m"
|
||||
}
|
||||
|
||||
loki.source.file "audit_live" {
|
||||
targets = local.file_match.audit_live.targets
|
||||
forward_to = [loki.process.audit.receiver]
|
||||
tail_from_end = false
|
||||
}
|
||||
|
||||
loki.source.file "audit_rotated" {
|
||||
targets = local.file_match.audit_rotated.targets
|
||||
forward_to = [loki.process.audit.receiver]
|
||||
tail_from_end = false
|
||||
|
||||
decompression {
|
||||
enabled = true
|
||||
format = "gz"
|
||||
}
|
||||
}
|
||||
|
||||
loki.process "audit" {
|
||||
// Field allowlist. Everything not listed here — in particular
|
||||
// requestObject/responseObject — is discarded with the parsed record.
|
||||
stage.json {
|
||||
expressions = {
|
||||
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",
|
||||
}
|
||||
}
|
||||
|
||||
stage.timestamp {
|
||||
source = "time"
|
||||
format = "RFC3339Nano"
|
||||
}
|
||||
|
||||
// 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",
|
||||
resource = "resource",
|
||||
}
|
||||
}
|
||||
|
||||
stage.pack {
|
||||
labels = []
|
||||
}
|
||||
|
||||
forward_to = [loki.write.local.receiver]
|
||||
}
|
||||
|
||||
loki.process "docker_logs" {
|
||||
stage.json {
|
||||
expressions = {
|
||||
|
|
|
|||
Loading…
Reference in a new issue