CloudWatch + Lambda Case 1- Avoid malicious CloudTrail action in your AWS Account
Share This Page
As many of you know AWS CloudTrail provides visibility into API activity in your AWS account, Cloud Trail Logging lets you see which actions users have taken and which resources have been used, along with details such as the time and date of actions and the actions that have failed because of inadequate permissions. It enables you to answer important questions such as which user made an API call or which resources were acted upon in an API call. If a user disables CloudTrail logs accidentally or with malicious intent then audit logging events will not captured and hence you fail to have proper governance in place. The situation will get complex, If the user disables- enables back CloudTrail for a brief period of time where some important activities can go unlogged and unaudited. In short once CloudTrail logging is enabled it should not be disabled and this action needs to be defended in depth.
Our Cloud operations team had earlier written a program that periodically scans the Cloud Trail logs entries, if any log activity was missing after an X period of time it alerts the operations. Overall reaction time on our cloud operations was >15-20 mins to mitigate this CloudTrail disable action.
Now after the introduction of CloudWatch Events we have configured a rule that points to an AWS Lambda function as target. This function gets triggered in near real time when CloudWatch is disabled and automatically enables it back without any manual interaction from Cloud operations. The advanced version of the program triggers workflow which logs entries into ticket system as well. This event model has helped us reduce the mitigation to less than a minute.
We have illustrated below the detailed steps on how to configure this event. Also we given the link for GIT with basic AWS Lambda Python code that can be used by your cloud operations.
In this use case, Amazon CloudWatch Event will identify whether an AWS account has got CloudTrail enabled or not, if not enabled, Amazon CloudWatch Events will take corrective actions by enabling the same.
As a first step, we will be creating a rule in Amazon CloudWatch Events dashboard. We have chosen AWS API Call as an Event to be processed by an AWSCloudTrail Lambda function as a target.
The next step would be configuring rule details with Rule definition
Finally, we will review the Rules Summary
Amazon Lambda Function Code Snippet (Python)
“”” Function to define Lambda Handler “””
def lambda_handler(event, context):
client = boto3.client(‘cloudtrail’)
if event[‘detail’][‘eventName’] == ‘StopLogging’:
response = client.start_logging(Name=event[‘detail’][‘requestParameters’][‘name’])
except Exception, e:
This article was originally published in: http://harish11g.blogspot.in/
Our SolutionsCloud Management Solutions
Cloud MFA Solution
Data lake management platform
Our ServicesCloud Consulting Services
Cloud Cost Optimization
Cloud Managed Services
Cloud DevOps Services
Cloud Engineering Services
Identity Access Management
Cloud Data Analytics