Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle cloudtrail message where the message is not json #249

Open
hamstah opened this issue Sep 24, 2019 · 4 comments
Open

Handle cloudtrail message where the message is not json #249

hamstah opened this issue Sep 24, 2019 · 4 comments

Comments

@hamstah
Copy link

hamstah commented Sep 24, 2019

Stacktrace

2019-09-24T15:42:47.206Z ERROR [CloudtrailSNSNotificationParser] Parsing exception.
com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'CloudTrail': was expecting ('true', 'false' or 'null')
 at [Source: CloudTrail validation message.; line: 1, column: 11]
        at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1702) ~[graylog.jar:?]
        at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:558) ~[graylog.jar:?]
        at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._reportInvalidToken(ReaderBasedJsonParser.java:2839) ~[graylog.jar:?]
        at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._handleOddValue(ReaderBasedJsonParser.java:1903) ~[graylog.jar:?]
        at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:749) ~[graylog.jar:?]
        at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:3850) ~[graylog.jar:?]
        at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3799) ~[graylog.jar:?]
        at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2858) ~[graylog.jar:?]
        at org.graylog.aws.inputs.cloudtrail.notifications.CloudtrailSNSNotificationParser.parse(CloudtrailSNSNotificationParser.java:36) [graylog-plugin-aws-3.1.2.jar:?]
        at org.graylog.aws.inputs.cloudtrail.notifications.CloudtrailSQSClient.getNotifications(CloudtrailSQSClient.java:55) [graylog-plugin-aws-3.1.2.jar:?]
        at org.graylog.aws.inputs.cloudtrail.CloudTrailSubscriber.run(CloudTrailSubscriber.java:89) [graylog-plugin-aws-3.1.2.jar:?]

This is caused by those messages being put in the SQS queue by SNS sometimes (not sure what causes it). The Message field is not JSON so it fails to be parsed and the message stays in the queue and gets refetched forever in a loop, polluting the graylog logs with the stacktrace.

{
  "Type" : "Notification",
  "MessageId" : "xxxxxx",
  "TopicArn" : "arn:aws:sns:us-east-1:xxxxxxxx:cloudtrail-logs-delivery-logs",
  "Message" : "CloudTrail validation message.",
  "Timestamp" : "2019-09-24T14:51:30.832Z",
  "SignatureVersion" : "1",
  "Signature" : "xxxxxx",
  "SigningCertURL" : "https://sns.us-east-1.amazonaws.com/SimpleNotificationService-6aad65c2f9911b05cd53efda11f913f9.pem",
  "UnsubscribeURL" : "https://sns.us-east-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-1:xxxxx:cloudtrail-logs-delivery-logs:xxxx"
}
@hamstah
Copy link
Author

hamstah commented Sep 25, 2019

Just found #117 but I checked and we have raw delivery disabled.

@danotorrey
Copy link
Contributor

@hamstah Thanks for the info. I will do some investigation to see if I can figure out why these messages are intermittently appearing in the queue.

@danotorrey danotorrey added bug and removed to-verify labels Sep 30, 2019
@danotorrey
Copy link
Contributor

Hi @hamstah,
I really appreciate you bringing this to our attention. These "CloudTrail validation message" SNS notifications get created when the SNS topic for a trail is updated or created. We will need to change the Graylog SNS processing logic to safely ignore them.

Once you have everything set up, these messages should not continue to be generated.

The workaround is to manually delete the validation messages on the SQS queue. There is a View/Delete Messages option in the menu on the main SQS page.

image

@hamstah
Copy link
Author

hamstah commented Sep 30, 2019 via email

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

No branches or pull requests

3 participants