Skip to content

Conversation

@kshi36
Copy link
Contributor

@kshi36 kshi36 commented Nov 25, 2025

Fixes #56099

Manual Tests

Test: types filter works correctly for clients using new bulk export API

  • When connected to a storage backend supporting bulk export API (eg. Teleport Cloud, Athena backend), and setting toml configuration file with the following options:
    • Verify types="user.login" filter forwards only user.login events to fluentd audit events endpoint
    • Verify skip-event-types="user.login" filter skips forwarding user.login events to fluentd audit events endpoint
    • Verify skip-session-types="db.session.query" filter skips forwarding db.session.query events to fluentd session events endpoint
    • Verify options above yield same results using both toml config file and CLI arguments

changelog: Fixed bug where event handler types filter is ignored for Teleport clients using Athena storage backend

@kshi36 kshi36 changed the title Fixed event handler types filter when using bulk export API Fix event handler types filter when using bulk export API Nov 25, 2025
@kshi36 kshi36 marked this pull request as ready for review November 25, 2025 20:13
@github-actions github-actions bot added audit-log Issues related to Teleports Audit Log size/md labels Nov 25, 2025
// filter out unwanted event types (in the v1 event export logic this was an internal behavior
// of the event processing helper since it would perform conversion prior to storing the event
// in its internal buffer).
if len(j.app.Config.Types) > 0 && !slices.Contains(j.app.Config.Types, evt.Event.Type) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for the length check since the slice contains does exactly that check before.
Should we create a map to avoid looping through config types?

Similar to skip events

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding was that if the types option was an empty slice, we would forward all event types (default behavior). Then slices.Contains would return false given the slice is empty, and the event type would be erroneously skipped.

I can change it into a map, although the length check will still be required

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct. I forgot about that

return nil
}

j.app.log.DebugContext(ctx, "Not skipping event", "type", evt.Event.Type)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd remove this one. The event handler processes many thousands of events, we probably don't need to debug log the normal operation.

Comment on lines +115 to +116
require.NotRegexp(t, regexp.MustCompile("\"Event sent\".*type=role.created"), out.String())
require.Regexp(t, regexp.MustCompile("\"Event sent\".*type=join_token.create"), out.String())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compile these regexes outside of the loop so you don't waste time recompiling them for each test case.

@@ -38,7 +38,6 @@ You may specify configuration options via command line arguments, environment va
| skip-session-types | Comma-separated list of session event types to skip | FDFWD_SKIP_SESSION_TYPES |
| start-time | Minimum event time (RFC3339 format) | FDFWD_START_TIME |
| timeout | Polling timeout | FDFWD_TIMEOUT |
| cursor | Start cursor value | FDFWD_CURSOR |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cursor CLI option (and environment variable) do not seem to exist anymore

@@ -357,6 +357,8 @@ Loop:

_, ok = j.app.Config.SkipSessionTypes[e.Type]
if !ok {
j.app.log.DebugContext(ctx, "Not skipping session event", "type", e.Type)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, I'd remove this one.

}

switch e.GetType() {
switch evt.Type {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this change necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't necessary, although it matches how we are operating on the newly created event (hence removing the unused method fields as well)

Although if there is some other drawback or inconvenience I can revert it

Copy link
Collaborator

@r0mant r0mant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small comment in addition to what other people commented on already.

Good job figuring this out @kshi36!

// filter out unwanted event types (in the v1 event export logic this was an internal behavior
// of the event processing helper since it would perform conversion prior to storing the event
// in its internal buffer).
if len(j.app.Config.Types) > 0 && !slices.Contains(j.app.Config.Types, evt.Event.Type) {
j.app.log.DebugContext(ctx, "Skipping event from types filter", "type", evt.Event.Type)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To echo Zac's similar comments, I would consider removing all of these extra debug statements that are logged whenever an event is processed, whether it's skipped or not. They can still clog the logs if you e.g. choose to skip a frequent event.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of logging a debug message when dropping an event. This can help troubleshoot issues like this one: #61729.

For the config I agree that this is not especially useful as we usually have access to the config.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Event Handler types filter should work with new bulk export API

6 participants