From 4a3ce60c11c9655415bffa1d9cedc5263ad1c432 Mon Sep 17 00:00:00 2001 From: Pier-Hugues Pellerin Date: Wed, 5 Sep 2018 13:03:33 -0400 Subject: [PATCH] Clone any cached data from docker and k8s (#8240) Using cached data can lead to race condition if we have some reference in place, this commit force a clone on the retrieved data so each event has his own copy. (cherry picked from commit 65e2e5ea3c531cb00ada6078ef0bb15f5439bf68) --- CHANGELOG.asciidoc | 1 + libbeat/processors/add_docker_metadata/add_docker_metadata.go | 2 +- libbeat/processors/add_kubernetes_metadata/kubernetes.go | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 102c93a24ed..bdaadc59e0f 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -41,6 +41,7 @@ https://github.com/elastic/beats/compare/v6.4.0...6.x[Check the HEAD diff] - Add backoff support to x-pack monitoring outputs. {issue}7966[7966] - Removed execute permissions systemd unit file. {pull}7873[7873] - Fix a race condition with the `add_host_metadata` and the event serialization. {pull}8223[8223] +- Enforce that data used by k8s or docker doesn't use any reference. {pull}8240[8240] *Auditbeat* diff --git a/libbeat/processors/add_docker_metadata/add_docker_metadata.go b/libbeat/processors/add_docker_metadata/add_docker_metadata.go index c4af0c848c2..5a81f5a6909 100644 --- a/libbeat/processors/add_docker_metadata/add_docker_metadata.go +++ b/libbeat/processors/add_docker_metadata/add_docker_metadata.go @@ -181,7 +181,7 @@ func (d *addDockerMetadata) Run(event *beat.Event) (*beat.Event, error) { meta.Put("container.id", container.ID) meta.Put("container.image", container.Image) meta.Put("container.name", container.Name) - event.Fields["docker"] = meta + event.Fields["docker"] = meta.Clone() } else { d.log.Debugf("Container not found: cid=%s", cid) } diff --git a/libbeat/processors/add_kubernetes_metadata/kubernetes.go b/libbeat/processors/add_kubernetes_metadata/kubernetes.go index df98e1dd68e..63915e4b6ea 100644 --- a/libbeat/processors/add_kubernetes_metadata/kubernetes.go +++ b/libbeat/processors/add_kubernetes_metadata/kubernetes.go @@ -155,7 +155,7 @@ func (k *kubernetesAnnotator) Run(event *beat.Event) (*beat.Event, error) { } event.Fields.DeepUpdate(common.MapStr{ - "kubernetes": metadata, + "kubernetes": metadata.Clone(), }) return event, nil