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

[Filebeat] Add support for events triggered by S3 uploads from the AWS console in S3 input #14077

Merged

Conversation

darupedk
Copy link
Contributor

  • Add support for the ObjectCreated:CompleteMultipartUpload event in S3 input

@elasticmachine
Copy link
Collaborator

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

1 similar comment
@elasticmachine
Copy link
Collaborator

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

@kaiyan-sheng kaiyan-sheng added Team:Integrations Label for the Integrations team Filebeat Filebeat labels Oct 15, 2019
@kaiyan-sheng
Copy link
Contributor

jenkins, test this please

@kaiyan-sheng
Copy link
Contributor

@darupedk Thanks for adding this 👍 We are working on adding elb fileset in Filebeat aws module and ran into this same problem.

Looks like this PR might need a rebase to make CI happy. Could you do that please?

@darupedk darupedk force-pushed the feature-s3-input-additional-event branch from e88cca8 to ff69d88 Compare October 16, 2019 17:50
@darupedk
Copy link
Contributor Author

@darupedk Thanks for adding this 👍 We are working on adding elb fileset in Filebeat aws module and ran into this same problem.

Looks like this PR might need a rebase to make CI happy. Could you do that please?

There we go.

In case we want full support for create events, we need to support the complete list of events:

  • s3:ObjectCreated:Put
  • s3:ObjectCreated:Post
  • s3:ObjectCreated:Copy
  • s3:ObjectCreated:CompleteMultipartUpload

I haven't inspected the Post and Copy events (JSON) which is why I haven't added them. However, we could do strings.HasPrefix('s3:ObjectCreated:') and check if the Post and Copy events are based on the same JSON structure. I wouldn't mind checking up on that.

@darupedk
Copy link
Contributor Author

darupedk commented Oct 16, 2019

@darupedk Thanks for adding this 👍 We are working on adding elb fileset in Filebeat aws module and ran into this same problem.
Looks like this PR might need a rebase to make CI happy. Could you do that please?

There we go.

In case we want full support for create events, we need to support the complete list of events:

  • s3:ObjectCreated:Put
  • s3:ObjectCreated:Post
  • s3:ObjectCreated:Copy
  • s3:ObjectCreated:CompleteMultipartUpload

I haven't inspected the Post and Copy events (JSON) which is why I haven't added them. However, we could do strings.HasPrefix('s3:ObjectCreated:') and check if the Post and Copy events are based on the same JSON structure. I wouldn't mind checking up on that.

I have just inspected them and they do follow the same structure. I recommend changing the code to use strings.HasPrefix(record.EventName, "ObjectCreated:").

@kaiyan-sheng
Copy link
Contributor

jenkins, test this please

@darupedk
Copy link
Contributor Author

TestHandleMessage is failing due to the following invalid S3 event:

		{
			"sqs message with event source aws:s3 and event name ObjectCreated:Delete",
			sqs.Message{
				Body: awssdk.String("{\"Records\":[{\"eventSource\":\"aws:s3\",\"awsRegion\":\"ap-southeast-1\",\"eventTime\":\"2019-06-21T16:16:54.629Z\",\"eventName\":\"ObjectCreated:Delete\",\"s3\":{\"configurationId\":\"object-created-event\",\"bucket\":{\"name\":\"test-s3-ks-2\",\"arn\":\"arn:aws:s3:::test-s3-ks-2\"},\"object\":{\"key\":\"server-access-logging2019-06-21-16-16-54-E68E4316CEB285AA\"}}}]}"),
			},
			[]s3Info{},
		},

We can go ahead and validate the events a bit more in the code but AWS would never send a message like this. We could instead replace the test message with ObjectRemoved:Delete which is a valid S3 event though not one that should be handled by the plugin.

@kaiyan-sheng
Copy link
Contributor

TestHandleMessage is failing due to the following invalid S3 event:

		{
			"sqs message with event source aws:s3 and event name ObjectCreated:Delete",
			sqs.Message{
				Body: awssdk.String("{\"Records\":[{\"eventSource\":\"aws:s3\",\"awsRegion\":\"ap-southeast-1\",\"eventTime\":\"2019-06-21T16:16:54.629Z\",\"eventName\":\"ObjectCreated:Delete\",\"s3\":{\"configurationId\":\"object-created-event\",\"bucket\":{\"name\":\"test-s3-ks-2\",\"arn\":\"arn:aws:s3:::test-s3-ks-2\"},\"object\":{\"key\":\"server-access-logging2019-06-21-16-16-54-E68E4316CEB285AA\"}}}]}"),
			},
			[]s3Info{},
		},

We can go ahead and validate the events a bit more in the code but AWS would never send a message like this. We could instead replace the test message with ObjectRemoved:Delete which is a valid S3 event though not one that should be handled by the plugin.

Changing to ObjectRemoved:Delete sounds good. Sorry I made this up just for pure testing purpose originally.

@jsoriano
Copy link
Member

ok to test

Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

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

LGTM, we will need to backport this

@jsoriano jsoriano added needs_backport PR is waiting to be backported to other branches. review v7.5.0 labels Oct 17, 2019
@kaiyan-sheng
Copy link
Contributor

LGTM, we will need to backport this

Thanks! I will merge it now and backport it.

@kaiyan-sheng kaiyan-sheng removed the needs_backport PR is waiting to be backported to other branches. label Oct 17, 2019
kaiyan-sheng added a commit that referenced this pull request Oct 17, 2019
…d by S3 uploads from the AWS console in S3 input (#14109)

* [Filebeat] Add support for events triggered by S3 uploads from the AWS console in S3 input (#14077)

* Added support for events triggered by S3 uploads from the AWS console
* Changed code to match any ObjectCreated events

(cherry picked from commit 00bd5b6)
jorgemarey pushed a commit to jorgemarey/beats that referenced this pull request Jun 8, 2020
…S console in S3 input (elastic#14077)

* Added support for events triggered by S3 uploads from the AWS console
* Changed code to match any ObjectCreated events
leweafan pushed a commit to leweafan/beats that referenced this pull request Apr 28, 2023
…riggered by S3 uploads from the AWS console in S3 input (elastic#14109)

* [Filebeat] Add support for events triggered by S3 uploads from the AWS console in S3 input (elastic#14077)

* Added support for events triggered by S3 uploads from the AWS console
* Changed code to match any ObjectCreated events

(cherry picked from commit d233c6d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Filebeat Filebeat review Team:Integrations Label for the Integrations team v7.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants