This post is written by Pawan Puthran, Principal Specialist TAM, Serverless and Heeki Park, Principal Solutions Architect, Serverless
Today, AWS is announcing support for read-only management events in Amazon EventBridge. This feature enables customers to build rich event-driven responses from any action taken on AWS infrastructure to detect security vulnerabilities or identify suspicious activity in near real-time. You can now gain insight into all activity across all your AWS accounts and respond to those events as is appropriate.
Overview
EventBridge is a serverless event bus used to decouple event producers and consumers. Event producers publish events onto an event bus, which then uses rules to determine where to send those events. The rules determine the downstream targets that receive and process the events, and EventBridge routes the events accordingly.
EventBridge allows customers to monitor, audit, and react, in near real-time, to changes in their AWS environments through events generated by AWS CloudTrail for AWS API calls. CloudTrail records actions taken by a user, role, or an AWS service as events in a trail. Events include actions taken in the AWS Management Console, AWS Command Line Interface (CLI), and AWS SDKs and APIs.
Previously, only mutating API calls are published from CloudTrail to EventBridge for control plane changes. Events for mutating API calls include those that create, update, or delete resources. Control plane changes are also referred to as management events. EventBridge now supports non-mutating or read-only API calls for management events at no additional cost. These include those that list, get, or describe resources.
CloudTrail events in EventBridge enable you to build rich event-driven responses from any action taken on AWS infrastructure in real time. Previously, customers and partners often used a polling model to iterate over a batch of CloudTrail logs from Amazon S3 buckets to detect issues, making it slower to respond. The launch of read-only management events enables you to detect and remediate issues in near real-time and thus improve the overall security posture.
Enabling read-only management events
You can start receiving read-only management events if a CloudTrail is configured in your account and if the event selector for that CloudTrail is configured with ReadWriteType of either All or ReadOnly. This ensures that the read-only management events are logged in the CloudTrail and are then passed to EventBridge.
For example, you can receive an alert if a production account lists resources from an IP address outside of your VPC. Another example could be if an entity, such as a principal (AWS account root user, IAM role, or IAM user), calls the ListInstanceProfilesForRole or DescribeInstances APIs without any prior record of doing so. A malicious actor could use stolen credentials for conducting this reconnaissance to find more valuable credentials or determine the capabilities of the credentials they have.
To enable read-only management events with an EventBridge rule, in addition to the existing mutating events, use the new ENABLED_WITH_ALL_CLOUDTRAIL_MANAGEMENT_EVENTS state when creating the rule.
Resources: SampleMgmtRule: Type: 'AWS::Events::Rule' Properties: Description: 'Example for enabling read-only management events' State: ENABLED_WITH_ALL_CLOUDTRAIL_MANAGEMENT_EVENTS EventPattern: source: - aws.s3 detail: - AWS API Call via CloudTrail Targets: - Arn: 'arn:aws:sns:us-east-1:123456789012:notificationTopic' Id: 'NotificationTarget'You can also create a rule on an event bus to specify a particular API action by using the eventName attribute under the detail key:
aws events put-rule --name "SampleTestRule" \ --event-pattern '{"detail": {"eventName": ["ListBuckets"]}}' \ --state ENABLED_WITH_ALL_CLOUDTRAIL_MANAGEMENT_EVENTS --region us-east-1Common scenarios and use-cases
The following section describes a couple of the scenarios where you can set up EventBridge rules and take actions on non-mutating or read-only management events.
Detecting anomalous Secrets Manager GetSecretValue API Calls
Consider the security team of your organization that wants a notification whenever GetSecretValue API calls for AWS Secrets Manager are made through the CLI. They can then investigate if these calls are made by entities outside their organization or by an unauthorized user and take corrective actions to deny such requests.
When the application calls the GetSecretValue API to retrieve the secrets via a CLI, it generates an event like this:
{ "version": "0", "id": "d3368cc1-e6d6-e4bf-e58e-030f03b6eae3", "detail-type": "AWS API Call via CloudTrail", "source": "aws.secretsmanager", "account": "111111111111", "time": "2023-11-08T19:58:38Z", "region": "us-east-1", "resources": [], "detail": { "eventVersion": "1.08", "userIdentity": { "type": "IAMUser", "principalId": "AAAAAAAAAAAAA", "arn": "arn:aws:iam:: 111111111111:user/USERNAME" // ... additional detail fields }, "eventTime": "2023-11-08T19:58:38Z", "eventSource": "secretsmanager.amazonaws.com", "eventName": "GetSecretValue", "awsRegion": "us-east-1", "userAgent": "aws-cli/2.13.15 Python/3.11.4 Darwin/22.6.0 exe/x86_64 prompt/off command/secretsmanager.get-secret-value" // ... additional detail fields } }You set the following event pattern on the rule to filter incoming events to specific consumers. This example also uses the recently launched wildcard filter for event matching.
{ "source": [ "aws.secretsmanager" ], "detail-type": [ "AWS API Call via CloudTrail" ], "detail": { "eventName": [ "GetSecretValue" ], "userAgent": [ { "wildcard": "aws-cli/*" } ] } }You can create a rule matching a combination of these event properties. In this case, you are matching for aws.secretsmanager as source, AWS API Call via CloudTrail as detail-type, GetSecretValue as detail.eventName and wildcard pattern on detail.userAgent for aws-cli/*. You can filter detail.userAgent with a wildcard to catch events that come from a particular application or user.
You can then route these events to a target like an Amazon CloudWatch Logs stream to record the change. You can also route them to Amazon SNS to get notified via email subscription. You can alternatively route them to an AWS Lambda function in which you perform custom business logic.
Creating an EventBridge rule for read-only management events
- Create a rule on the default event bus using the new state ENABLED_WITH_ALL_CLOUDTRAIL_MANAGEMENT_EVENTS. aws events put-rule --name "monitor-secretsmanager" \ --event-pattern '{"source": ["aws.secretsmanager"], "detail-type": ["AWS API Call via CloudTrail"], "detail": {"eventName": ["GetSecretValue"], "userAgent": [{ "wildcard": "aws-cli/*"} ]}}' \ --state ENABLED_WITH_ALL_CLOUDTRAIL_MANAGEMENT_EVENTS --region us-east-1
- Configure a target. In this case, the target service is CloudWatch Logs but you can configure any of the supported targets. aws events put-targets --rule monitor-secretsmanager --targets Id=1,Arn=arn:aws:logs:us-east-1:ACCOUNT_ID:log-group:/aws/events/getsecretvaluelogs --region us-east-1
You can then use CloudWatch Log Insights to search and analyze log data using the CloudWatch Log Insights query syntax where you can retrieve the user who performed these calls.
Identifying suspicious data exfiltration behavior
Consider the security or data perimeter team who wants to secure data residing in Amazon S3 buckets. The team requires notifications whenever API calls to list S3 buckets or to list S3 objects are made.
When a user or application calls the ListBuckets API to discover the available buckets, it generates the following CloudTrail event:
{ "version": "0", "id": "345ca690-6510-85b2-ff02-090493a33cf1", "detail-type": "AWS API Call via CloudTrail", "source": "aws.s3", "account": "111111111111", "time": "2023-11-14T17:25:30Z", "region": "us-east-1", "resources": [], "detail": { "eventVersion": "1.09", "userIdentity": { "type": "IAMUser", "principalId": "principal-identity-uuid", "arn": "arn:aws:iam::111111111111:user/exploited-user", "accountId": "111111111111", "accessKeyId": "AAAABBBBCCCCDDDDEEEE", "userName": "exploited-user" }, "eventTime": "2023-11-14T17:25:30Z", "eventSource": "s3.amazonaws.com", "eventName": "ListBuckets", "awsRegion": "us-east-1", "sourceIPAddress": "11.22.33.44", "userAgent": "[aws-cli/2.13.29 Python/3.11.6 Darwin/22.6.0 exe/x86_64 prompt/off command/s3api.list-buckets]", "requestParameters": { "Host": "s3.us-east-1.amazonaws.com" }, "readOnly": true, "eventType": "AwsApiCall", "managementEvent": true // additional detail fields } }In this scenario, you can create an EventBridge rule matching for aws.s3 for the source field, and ListBuckets for the eventName.
{ "source": [ "aws.s3" ], "detail-type": [ "AWS API Call via CloudTrail" ], "detail": { "eventName": [ "ListBuckets " ] } }However, listing objects alone might only be the beginning of a potential data exfiltration attempt. You may also want to check for ListObjects or ListObjectsV2 as the next action, followed by a large number of GetObject API calls. You can create the following rule to match those actions.
{ "source": [ "aws.s3" ], "detail-type": [ "AWS API Call via CloudTrail" ], "detail": { "eventName": [ "ListObjects", "ListObjectsV2", "GetObject" ] } }You could potentially forward this log information to your central security logging solution or use anomaly detection machine learning models to evaluate these events to determine the appropriate response to these events.
Configuring cross-account and cross-Region event routing
You can also create rules to receive the read-only events to cross account or cross-Region to centralize your AWS events into one Region or one AWS account for auditing and monitoring purposes. For example, capture all workload events from multiple Regions in eu-west-1 for compliance reporting.
To do this, create a rule using the new ENABLED_WITH_ALL_CLOUDTRAIL_MANAGEMENT_EVENTS state on the default bus of the source account or the Region, targeting either default event bus or a custom event bus of the target account or Region. You must also ensure you have a rule configured with ENABLED_WITH_ALL_CLOUDTRAIL_MANAGEMENT_EVENTS to be able to invoke the targets in the destination account or Region.
Conclusion
This blog shows how customers can build rich event-driven responses with the newly launched support for read-only events. You can now observe events as potential signals of reconnaissance and data exfiltration activities from any action taken on AWS infrastructure in near real time. You can also use the cross-Region and cross-account functionality to deliver the read-only events to a centralized AWS account or Region, enhancing the capability for auditing and monitoring across all your AWS environments.
For more serverless learning resources, visit Serverless Land.