Skip to content

athena audit logs - publisher#23987

Merged
tobiaszheller merged 17 commits intomasterfrom
tobiaszheller/auditevents-athena-sns
Apr 13, 2023
Merged

athena audit logs - publisher#23987
tobiaszheller merged 17 commits intomasterfrom
tobiaszheller/auditevents-athena-sns

Conversation

@tobiaszheller
Copy link
Copy Markdown
Contributor

Part of https://github.com/gravitational/teleport.e/issues/894
RFD: #23700

This PR adds possibility to publish events to SNS for athena audit log.

@github-actions github-actions Bot requested review from atburke and zmb3 April 3, 2023 13:30
@github-actions github-actions Bot added audit-log Issues related to Teleports Audit Log size/md labels Apr 3, 2023
Comment thread lib/events/athena/publisher.go
Comment thread lib/events/athena/publisher.go Outdated
Comment on lines +105 to +108
retry, err := retryutils.NewLinear(retryutils.LinearConfig{
Step: 100 * time.Millisecond,
Max: 1 * time.Minute,
})
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@rosstimothy what do you think about those values? i think we can accept waiting for 1minute, but maybe I am wrong.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Doesn't the aws sdk have builtin retry and backoff?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good idea, I can use the one from AWS, what do you think about values there?

DefaultMaxAttempts int = 3
DefaultMaxBackoff time.Duration = 20 * time.Second

Is 1 minute good idea? default for aws is 20s.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think that any of our other AWS clients modify the default retry behavior at all, including the client used by the current dynamo events backend.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think it will hurt us to extend those values a little bit. I think that dynamo offers SLA 99.99% while SNS 99.9% so it make sense to retry a little bit more.

Comment thread lib/events/athena/publisher.go Outdated
Comment thread lib/events/athena/publisher.go Outdated
Comment thread lib/events/athena/publisher.go Outdated
Comment thread lib/events/athena/publisher.go Outdated
Comment on lines +105 to +108
retry, err := retryutils.NewLinear(retryutils.LinearConfig{
Step: 100 * time.Millisecond,
Max: 1 * time.Minute,
})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Doesn't the aws sdk have builtin retry and backoff?

Comment thread lib/events/athena/publisher.go
tobiaszheller and others added 3 commits April 5, 2023 10:00
Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com>
Comment thread lib/events/athena/athena.go Outdated
Comment thread lib/events/athena/publisher.go Outdated
Comment thread lib/events/athena/publisher_test.go Outdated
Comment thread lib/events/athena/publisher.go Outdated
}
}

// EmitAuditEvent emits audit event.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggestion add some more context to how this works for this particular implementation

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done in 6573cbc

Comment thread lib/events/athena/publisher.go Outdated
Comment on lines +105 to +108
retry, err := retryutils.NewLinear(retryutils.LinearConfig{
Step: 100 * time.Millisecond,
Max: 1 * time.Minute,
})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think that any of our other AWS clients modify the default retry behavior at all, including the client used by the current dynamo events backend.

@tobiaszheller
Copy link
Copy Markdown
Contributor Author

@rosstimothy @zmb3 @atburke PTAL

Comment thread lib/events/athena/publisher.go Outdated
}

// newPublisher returns new instance of publisher.
func newPublisher(cfg Config, awsCfg aws.Config, log *log.Entry) *publisher {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not include awsCfg aws.Config, log *log.Entry in the Config with the rest of the dependencies?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have reworked it in 47b7912, let me know if it's better now

@tobiaszheller
Copy link
Copy Markdown
Contributor Author

@atburke @zmb3 friendly ping

Comment thread lib/events/athena/athena.go Outdated
Comment thread lib/events/athena/publisher.go Outdated
Comment thread lib/events/athena/publisher_test.go Outdated
_, err := p.snsPublisher.Publish(ctx, &sns.PublishInput{
TopicArn: aws.String(p.topicARN),
Message: aws.String(b64Encoded),
MessageAttributes: map[string]snsTypes.MessageAttributeValue{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Don't these MessageAttributes get discarded when using RawMessageDelivery = true? I haven't tested this but am not sure: https://docs.aws.amazon.com/sns/latest/dg/sns-large-payload-raw-message-delivery.html.

Only noticed since your example integration tests show it enabled.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

When you enable raw message delivery for Amazon Kinesis Data Firehose or Amazon SQS endpoints, any Amazon SNS metadata is stripped from the published message and the message is sent as is.

For SQS, it strips only SNS metadata, TopicArn etc. MessageAttributes are preserved. I am using all time RawMessageDelivery and message attributes are present.

@public-teleport-github-review-bot
Copy link
Copy Markdown

@tobiaszheller - this PR will require admin approval to merge due to its size. Consider breaking it up into a series smaller changes.

@tobiaszheller tobiaszheller force-pushed the tobiaszheller/auditevents-athena-sns branch from d8ac8b9 to 7242c70 Compare April 13, 2023 08:21
@tobiaszheller tobiaszheller enabled auto-merge April 13, 2023 08:41
@tobiaszheller tobiaszheller added this pull request to the merge queue Apr 13, 2023
Merged via the queue into master with commit 88fb60c Apr 13, 2023
@tobiaszheller tobiaszheller deleted the tobiaszheller/auditevents-athena-sns branch April 13, 2023 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

audit-log Issues related to Teleports Audit Log size/md

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants