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

fix(cloudtrail): fix path and extract more fields from the s3 notification event #412

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/cloudtrail/pkg/cloudtrail/cloudtrail.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const (
PluginName = "cloudtrail"
PluginDescription = "reads cloudtrail JSON data saved to file in the directory specified in the settings"
PluginContact = "github.com/falcosecurity/plugins/"
PluginVersion = "0.11.0"
PluginVersion = "0.12.0"
PluginEventSource = "aws_cloudtrail"
)

Expand Down
30 changes: 21 additions & 9 deletions plugins/cloudtrail/pkg/cloudtrail/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ func getfieldStr(jdata *fastjson.Value, field string) (bool, string) {
switch field {
case "ct.id":
val := jdata.GetStringBytes("eventID")
if val == nil {
val = jdata.GetStringBytes("request-id")
}
Comment on lines +217 to +219
Copy link
Member

Choose a reason for hiding this comment

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

This situation should never happen, eventID is a mandatory field. Moreover, it seems the path is requestID:
image

Copy link
Contributor Author

@matteopasa matteopasa Feb 12, 2024

Choose a reason for hiding this comment

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

the thing is that the s3 notification event that we are receiving is this one: https://docs.aws.amazon.com/AmazonS3/latest/userguide/ev-events.html
The part inside the "detail" field
I've tried to map some of the fields to the ct fields but I can remove them

Copy link
Member

Choose a reason for hiding this comment

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

The plugin is from collecting the audit logs from cloudtrail, we should never receive a direct S3 event. Maybe I'm wrong or there's something I don't get.

Copy link
Contributor Author

@matteopasa matteopasa Feb 12, 2024

Choose a reason for hiding this comment

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

We want to extract fields also from s3 notification events, that is the reason of the change
The fields we are interested in are the s3 ones, so I can remove the ct ones if they can cause issues


if val == nil {
return false, ""
} else {
Expand All @@ -228,6 +232,7 @@ func getfieldStr(jdata *fastjson.Value, field string) (bool, string) {
}
case "ct.time":
val := jdata.GetStringBytes("eventTime")

if val == nil {
return false, ""
} else {
Expand Down Expand Up @@ -258,6 +263,9 @@ func getfieldStr(jdata *fastjson.Value, field string) (bool, string) {
}
case "ct.name":
val := jdata.GetStringBytes("eventName")
if val == nil {
val = jdata.GetStringBytes("reason")
}
if val == nil {
return false, ""
} else {
Expand All @@ -271,13 +279,14 @@ func getfieldStr(jdata *fastjson.Value, field string) (bool, string) {
return true, res
case "ct.user.accountid":
val := jdata.GetStringBytes("userIdentity", "accountId")
if val == nil {
val = jdata.GetStringBytes("recipientAccountId")
}
if val == nil {
val = jdata.GetStringBytes("requester")
}
if val != nil {
res = string(val)
} else {
val := jdata.GetStringBytes("recipientAccountId")
if val != nil {
res = string(val)
}
}
case "ct.user.identitytype":
val := jdata.GetStringBytes("userIdentity", "type")
Expand Down Expand Up @@ -407,6 +416,9 @@ func getfieldStr(jdata *fastjson.Value, field string) (bool, string) {
}
case "ct.srcip":
val := jdata.GetStringBytes("sourceIPAddress")
if val == nil {
val = jdata.GetStringBytes("source-ip-address")
}
if val == nil {
return false, ""
} else {
Expand Down Expand Up @@ -468,7 +480,7 @@ func getfieldStr(jdata *fastjson.Value, field string) (bool, string) {
case "s3.bucket":
val := jdata.GetStringBytes("requestParameters", "bucketName")
if val == nil {
val = jdata.GetStringBytes("detail", "bucket", "name")
val = jdata.GetStringBytes("bucket", "name")
}

if val == nil {
Expand All @@ -479,7 +491,7 @@ func getfieldStr(jdata *fastjson.Value, field string) (bool, string) {
case "s3.key":
val := jdata.GetStringBytes("requestParameters", "key")
if val == nil {
val = jdata.GetStringBytes("detail", "object", "key")
val = jdata.GetStringBytes("object", "key")
}

if val == nil {
Expand All @@ -490,15 +502,15 @@ func getfieldStr(jdata *fastjson.Value, field string) (bool, string) {
case "s3.uri":
sbucket := jdata.GetStringBytes("requestParameters", "bucketName")
if sbucket == nil {
sbucket = jdata.GetStringBytes("detail", "bucket", "name")
sbucket = jdata.GetStringBytes("bucket", "name")
}
if sbucket == nil {
return false, ""
}

skey := jdata.GetStringBytes("requestParameters", "key")
if skey == nil {
skey = jdata.GetStringBytes("detail", "object", "key")
skey = jdata.GetStringBytes("object", "key")
}
if skey == nil {
return false, ""
Expand Down
Loading