Skip to content

fix(shared/go/aws/cloudwatchlogs): do not skip late-ingested events - #1589

Open
roeeelnekave-spec wants to merge 1 commit into
falcosecurity:mainfrom
roeeelnekave-spec:fix/cloudwatchlogs-reorder-window
Open

roeeelnekave-spec wants to merge 1 commit into
falcosecurity:mainfrom
roeeelnekave-spec:fix/cloudwatchlogs-reorder-window

Conversation

@roeeelnekave-spec

Copy link
Copy Markdown

What type of PR is this?

/kind bug

Any specific area of the project related to this PR?

/area plugins

What this PR does / why we need it:

The shared CloudWatch Logs reader (shared/go/aws/cloudwatchlogs, used by k8saudit-eks) loses events.

After each poll it sets StartTime to the newest event timestamp it has seen. A log group is not ingested in timestamp order: each stream has its own delivery delay. EKS writes one kube-apiserver-audit-* stream per API server, and we measured 0 to 5 s ingestion lag per stream. An event ingested after a newer event from the other stream has a timestamp before StartTime at the next poll, so it is never read. The dedup check (*input.StartTime == *e.Timestamp && lastIngestionTime >= *e.IngestionTime) runs after the event has already been sent, so events at the boundary timestamp are also delivered twice.

In practice a kubectl get secret by a user was in CloudWatch but never reached Falco, so "K8s Secret Get Successfully" did not fire.

This PR re-reads a 60 s reorder window before the newest event on every poll and skips events already sent, using the CloudWatch event ID. The ID set is pruned to the window, so memory stays bounded.

Measured on a two-API-server EKS cluster (~20 audit events/s): stock k8saudit-eks 0.11.0 and a build with this patch ran side by side for 4 minutes, compared with the auditID/stage of every event FilterLogEvents returned for the same window:

duplicates missed (of 1000 events)
0.11.0 52 19
this PR 0 0

Which issue(s) this PR fixes:

None filed.

Special notes for your reviewer:

  • The window is a package constant (ReorderWindow, 60 s), not an option, to keep CreateOptions unchanged for other consumers. Happy to make it configurable.
  • Each poll now re-reads up to 60 s of events. FilterLogEvents has no per-event charge; read volume per poll grows by roughly 60 / polling_interval.

Each poll restarted at the newest event timestamp seen. CloudWatch Logs
ingests each stream of a log group with its own delay, so an event that
arrives after a newer event from another stream (e.g. a second EKS API
server) was never read. The boundary event was also sent twice.

Re-read a 60s reorder window before the newest event on every poll and
drop events already sent, by event ID.

Signed-off-by: Roee Elnekave <roee.elnekave@infinitylabs.co.il>
@poiana poiana added kind/bug Something isn't working dco-signoff: yes labels Oct 25, 2026
@poiana

poiana commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: roeeelnekave-spec
Once this PR has been reviewed and has the lgtm label, please assign leogr for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@poiana

poiana commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Welcome @roeeelnekave-spec! It looks like this is your first PR to falcosecurity/plugins 🎉

@poiana poiana added the size/M label Oct 25, 2026
@gustavoortega

Copy link
Copy Markdown

Tried this on an EKS cluster with 2 apiservers, 60 kubectl exec: 0.12.0 emitted 57, one of them twice. With this PR (and #1607), 60 and no duplicates.

I have tests for the window and the dedup against a fake FilterLogEvents endpoint (gustavoortega@dbc0616), happy to send them as a follow-up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants