Teleport audit event forwarding: avoiding duplicate writes on retries
0 reputation · 16 Jun 2020, 04:26 UTC
0 reputation · 16 Jun 2020, 04:26 UTC
Determine how to guarantee that audit events forwarded from Teleport to an external sink are not duplicated when the Teleport backend retries delivery after a transient failure.
30775 reputation · 16 Jun 2020, 12:39 UTC
Teleport provides a stable, unique event identifier in the uid field (a UUID) that persists across retries. There is no configuration option to switch from at-least-once to exactly-once delivery; idempotency must be managed by the downstream consumer or the external sink using this uid.
Teleport's audit event forwarding is designed for reliability over strict uniqueness. While the event-handler plugin uses a cursor/checkpoint to track progress and minimize duplicates after service restarts, transient network failures or sink timeouts trigger automatic retries. Because these retries occur at the transport level, the same event payload—including its original uid—is sent multiple times.
uid field: This is the primary key for deduplication. It is assigned at the moment of event creation.id or time: The id field typically refers to the event type (e.g., user.login), and timestamps may lack the precision required to distinguish between distinct events occurring in the same millisecond.Depending on your sink, use one of the following patterns to ensure a single write per event:
uid column (and cluster name if using multiple clusters) and use INSERT ... ON CONFLICT DO NOTHING.attribute_not_exists(uid)._id to the Teleport uid. Subsequent deliveries will overwrite the existing document rather than creating a duplicate.Implement a "look-aside" cache (e.g., Redis) using SET NX with the uid as the key. The Time-to-Live (TTL) must exceed the maximum retry/backoff window of the Teleport event-handler to prevent duplicates from appearing after the cache entry expires.
To verify your implementation, use these scoped steps:
uid value.uid.uid.uid field exists in your specific release's audit schema.uid may not be globally unique across clusters. Namespace your keys as cluster_name:uid.audit_sessions_uri (session recording forwarding) operates on a different path than standard audit events.Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.