Integrating AWS CloudTrail in Wazuh | Wazuh | The Open Source Security Platform (2024)

This post focuses on setting up Wazuh to collect events delivered by AWS CloudTrail which provides useful information about the AWS infrastructure, such as the instance configuration, unauthorized behavior, API usage and more.

What is AWS CloudTrail

AWS CloudTrailis a service that enables governance, compliance, operational and risk auditing of your AWS infrastructure. It provides event history of your AWS account activity, including actions taken through the AWS Management Console, AWS SDKs, command-line tools, and other AWS services.

How it works

CloudTrail typically delivers log files within 15 minutes of account activity by using trails. A trail is a configuration that enables the delivery of events to a specified Amazon S3 bucket to record changes in AWS resources. Log file objects are stored by trails in the S3 bucket in the following name format:

bucket_name/prefix_name/AWSLogs/Account ID/CloudTrail/region/YYYY/MM/DD/file_name.json.gz

This name format includes the following elements:

  • The bucket name specified when creating the trail.
  • The prefix specified when creating the trail. This is optional.
  • The stringAWSLogs.
  • The account ID.
  • The stringCloudTrail.
  • A region identifier such asus-west-1.
  • The year the log file was published inYYYYformat.
  • The month the log file was published inMMformat.
  • The day the log file was published inDDformat.
  • A random alphanumeric string to differentiate files from the same time period.

More information about CloudTrail concepts can be foundhere.

Setting it up

The following diagram shows what we plan to accomplish:

Integrating AWS CloudTrail in Wazuh | Wazuh | The Open Source Security Platform (1)

Note

If you already have a Trail set up for saving CloudTrail logs you can skipStep 1.

Step 1: Enable AWS CloudTrail

To enable CloudTrail we need to define a bucket for saving the logs. To do so, log in to the AWS Management Console and look for “CloudTrail” using the “Find Services” search option. Click on “Trails” on the left panel, and then click on “Create trail” button, as shown in the following screenshot:

Integrating AWS CloudTrail in Wazuh | Wazuh | The Open Source Security Platform (2)

Lastly, provide the name for the new S3 bucket that will be created and used to store CloudTrail logs:

Integrating AWS CloudTrail in Wazuh | Wazuh | The Open Source Security Platform (3)

Step 2: Create AWS credentials

Once we have created a trail, we need to set up credentials so that Wazuh is able to connect and extract the logs from the S3 bucket. We recommend doing this instead of hardcoding the user and password for the AWS account in theossec.conf. More information about how to configure AWS credentials can be found in theWazuh documentation.

For testing purposes, we are going to create a file located at ~/.aws/credentials with the following content to grant us access to the previously created S3 Bucket:

[default]aws_access_key_id=<YOUR_AWS_ACCESS_KEY>aws_secret_access_key=<YOUR_AWS_SECRET_KEY>

This way we will be able to connect to our AWS account if we specifydefaultas our AWS profile in the next step.

Step 3: Configure Wazuh

The only thing left to do is to indicate in our <WAZUH_HOME>/etc/ossec.conf file that we want to collect logs from CloudTrail by adding the following module. This step is performed on the Wazuh Manager or Agent. For this example we are going to configure it on a Wazuh Manager:

<wodle name="aws-s3"> <disabled>no</disabled> <interval>10m</interval> <run_on_start>yes</run_on_start> <skip_on_error>yes</skip_on_error> <bucket type="cloudtrail"> <name>wazuh-cloudtrail</name> <aws_profile>default</aws_profile> </bucket></wodle>

From this module two options stand out:

  • name: The name of the bucket where CloudTrail is saving the logs, previously defined. In our case, we named it “wazuh-cloudtrail”.
  • aws_profile: The name of the profile defined for granting Wazuh access to the bucket. This allows us to log in with our AWS account. It must match with the profile specified in the credentials file created in step 2.

Note

To monitor logs for multiple AWS accounts, you must configure multiple options within theaws-s3module. Bucket tags must have a type attribute which depends on the service being monitored. More informationhere.

Finally, restart Wazuh to apply the changes, and the CloudTrail alerts will start to appear on the Wazuh UI.

Other useful options for AWS-S3 module

The AWS-S3 module has several options available aside from the ones shown in the previous example. Here are some configuration options that can be useful when the S3 bucket contains a long history of logs. They will filter which logs will be read by Wazuh:

  • only_logs_after: Allows filtering of logs produced after a given date. The date format must beYYYY-MMM-DD. For example,2020-JUN-01would filter logs produced after the 1st of June 2020, not including that day. It requires the directory structure to be organized by dates.
  • aws_account_id: If you have logs from multiple accounts, you can filter which ones will be read by Wazuh. You can specify multiple IDs by separating them with commas.
  • regions: If you have logs from multiple regions, you can filter which ones will be read by Wazuh. You can specify multiple regions separating them with commas.
  • path: If you have your logs stored in a given path, it can be specified using this option. This must match with theprefix_nameof the log object files to be read.

Usage examples of those available options can be found in our officialdocumentation.

Note

The AWS-S3 Wazuh module only looks for new logs based upon the key for the last processed log object which includes the date timestamp. If older logs are loaded into the S3 bucket or theonly_logs_afteroption date is set to a date/time earlier than previous executions of the module, the older log files will be ignored and not ingested into Wazuh.

Step 4: Ensure everything is running fine

After restarting you can ensure everything is fine by checking the <WAZUH_HOME>/logs/ossec.log. If the following message appears in the log and there are no warnings related to AWS then everything is ready:

INFO: Module AWS startedINFO: Starting fetching of logs.INFO: Executing Bucket Analysis: (Bucket: wazuh-cloudtrail, Type: cloudtrail, Profile: default)

You can also verify the integration is working as expected by accessing the Wazuh App. The AWS CloudTrail dashboard can be found here:

Integrating AWS CloudTrail in Wazuh | Wazuh | The Open Source Security Platform (4)

Troubleshooting

This section covers possible errors that may occur if we have made any mistakes during the configuration process. Those errors will be found in the<WAZUH_HOME>/logs/ossec.log.

To increase the verbosity of the messages found inossec.logdebug mode for the AWS module can be enabled by adding the linewazuh_modules.debug=2to the<WAZUH_HOME>/etc/local_internal_options.conffile and restarting Wazuh.

The config profile could not be found

INFO: Module AWS startedINFO: Starting fetching of logs.INFO: Executing Bucket Analysis: (Bucket: wazuh-cloudtrail, Type: cloudtrail, Profile: default)WARNING: Bucket: - Returned exit code 12WARNING: Bucket: - The config profile (default) could not be foundINFO: Fetching logs finished.

If the AWS credentials cannot be found you will receive this error. Make sure the AWS credentials have been correctly set up as indicated inStep 2: Configure AWS credentials.

Access error: Forbidden

INFO: Module AWS startedINFO: Starting fetching of logs.INFO: Executing Bucket Analysis: (Bucket: wazuh-cloudtrail, Type: cloudtrail, Profile: default)WARNING: Bucket: - Returned exit code 3WARNING: Bucket: - Access error: An error occurred (403) when calling the HeadBucket operation: Forbidden

This error means the credentials specified during theStep 2: Configure AWS credentialsare wrong and they don’t grant access to AWS. Ensure you are using the right credentials.

Access error: Not Found

INFO: Module AWS startedINFO: Starting fetching of logs.INFO: Executing Bucket Analysis: (Bucket: wazuh-cloudnottrail, Type: cloudtrail, Profile: default)WARNING: Bucket: - Returned exit code 3WARNING: Bucket: - Access error: An error occurred (404) when calling the HeadBucket operation: Not FoundINFO: Fetching logs finished.

This error appear when a wrong S3 Bucket name is specified. Ensure the same bucket name defined inStep 1: Enable AWS CloudTrailis used in<WAZUH_HOME>/etc/ossec.confwhen following the instructions ofStep 3: Configure Wazuh.

Use case: Detecting intrusion attempts

One of the most common use cases for the CloudTrail integration with Wazuh is to monitor intrusion attempts into our cloud infrastructure. Every time a user tries to log in, an event will be generated regardless if it was successful or not.

In addition, it’s possible to configure Wazuh tosend email alertswhen this kind of behavior is detected, making it possible to immediately perform the necessary actions to avoid the effects of these attacks. You could alsoenable Amazon SNSto send SMS notifications.

As an example, the following alert will be shown in the Wazuh UI if a user tries to log in with an invalid password:

Integrating AWS CloudTrail in Wazuh | Wazuh | The Open Source Security Platform (5)

When more than 4 authentication failures occur in a 360 second time window, an alert will be raised:

Use Case: Monitoring API Calls

Another useful example of what we can achieve by integrating CloudTrail with Wazuh is through monitoring any API calls. Any time an API call is performed, a log will be created by AWS and collected by Wazuh. It will be visible in the Wazuh UI and provide useful information. Some of the fields that the alert will have are:

  • Caller’s identity (user, country, ip…)
  • API call’s timestamp
  • Requested parameters and the resulting response

Here is an example of an event raised when someone tried to run a EC2 instance:

Integrating AWS CloudTrail in Wazuh | Wazuh | The Open Source Security Platform (7)

And here is another example of an event when a user tries to terminate an EC2 instance:

Integrating AWS CloudTrail in Wazuh | Wazuh | The Open Source Security Platform (8)

Conclusion

Thanks to CloudTrail and Wazuh, we can be aware of misconfigurations, attempted and/or successful malicious activities, policy violations and a variety of other security and operational issues. We can also be notified when some of those alerts are triggered.

Wazuh is ready to analyze AWS events of high relevance making it a powerful visualization tool to keep track of everything that happens in your AWS infrastructure.

References

If you have any questions about this, don’t hesitate to check out our documentation to learn more about Wazuh. You can also join our Slack #community channel and our mailing list where our team and other users will help you with your questions.

Integrating AWS CloudTrail in Wazuh | Wazuh | The Open Source Security Platform (2024)

FAQs

Which other AWS service can you use to enable greater security of your CloudTrail log files? ›

By default, CloudTrail log files are encrypted using S3 server-side encryption (SSE) and placed into your S3 bucket. You can control access to log files by applying IAM or S3 bucket policies. You can add an additional layer of security by enabling S3 multi-factor authentication (MFA) Delete on your S3 bucket.

Which of the following AWS services can provide an audit trail of all the API activity taking place in your AWS account? ›

You can use AWS CloudTrail data to view and track API calls made to your account using the following: CloudTrail Event history. CloudTrail Lake. Amazon CloudWatch Logs.

Which AWS service offers insights to automatically detect unusual API activities in AWS accounts? ›

AWS CloudTrail Insights helps AWS users identify and respond to unusual volumes of API calls or errors logged on API calls by continuously analyzing CloudTrail management events.

Which AWS service allows you to adhere to security best practices? ›

With AWS Identity and Access Management (IAM), you can specify who can access which AWS services and resources, and under which conditions. To help secure your AWS resources, follow these IAM best practices.

How do I secure CloudTrail logs? ›

CloudTrail logs are encrypted by default using S3-managed encryption keys. To gain greater control over log security, you can instead use encryption with customer-created master keys (CMK) managed in AWS Key Management Services.

Does CloudTrail log failed API calls? ›

CloudTrail will log the API calls (including request id) at the bucket level by default. If the request was for a specific object, you need to enable S3 data events when you create the trail.

Which statements are best practices for working with AWS CloudTrail? ›

Best practice rules for AWS CloudTrail

Ensure that your CloudTrail trails are using active Amazon SNS topics. Ensure CloudTrail trails are configured to log Data events. Ensure Amazon CloudTrail trail log files are delivered as expected. Ensure CloudTrail is enabled in all regions.

Does CloudTrail log all API calls? ›

For every API request that is captured by CloudTrail it is recorded as an event in a CloudTrail log file. API Activity Filters. These are search filters that can be applied against your API activity history in the management console for create, modify and delete API calls.

How to detect unauthorized activity on AWS using CloudTrail? ›

Detecting anomalies in CloudTrail with CloudWatch

You can create alerts for individual CloudTrail events that you consider an anomaly by creating CloudWatch filters and alarms. A filter defines the events that you want to monitor and an alarm defines the threshold when you want to be notified.

What are the key benefits of AWS CloudTrail select two? ›

  • Always on. CloudTrail is enabled on all AWS accounts and records management events across AWS services without the need for any manual setup. ...
  • Storage and monitoring. ...
  • Immutable and encrypted activity logs. ...
  • Insights and analytics. ...
  • Multi-source. ...
  • Multi-region. ...
  • Multi-account.

What is the main difference between AWS CloudTrail and Amazon CloudWatch? ›

CloudWatch is a monitoring service for AWS resources and applications. CloudTrail is a web service that records API activity in your AWS account. CloudWatch monitors applications and infrastructure performance in the AWS environment. CloudTrail monitors actions in the AWS environment.

What gives security and safeguards applications that are running on AWS? ›

AWS Shield is a managed Distributed Denial of Service (DDoS) protection service that safeguards web applications running on AWS.

Which security requirements are managed by AWS? ›

You get access to hundreds of tools and features to help you to meet your security objectives. AWS provides security-specific tools and features across network security, configuration management, access control, and data encryption.

Which AWS online tool can assist in security compliance? ›

Get on-demand access to more than 2,500 security controls by using AWS Artifact, our automated compliance reporting tool available in the AWS Management Console.

Are CloudTrail logs automatically encrypted? ›

By default, the log files delivered by CloudTrail to your bucket are encrypted by Amazon server-side encryption with Amazon S3-managed encryption keys (SSE-S3).

What is the default encryption for CloudTrail? ›

By default, the log files that CloudTrail puts in your S3 bucket are encrypted using server-side encryption with Amazon S3–managed encryption keys (SSE-S3). But you can choose instead to use server-side encryption with a KMS key (SSE-KMS).

Which information does AWS CloudTrail not capture? ›

Amazon CloudTrail will only show the results of the CloudTrail Event History for the current region you are viewing for the last 90 days and support the Amazon Web Services services found here. These events are limited to Management Events with create, modify, and delete API calls and account activity.

What is the maximum number of CloudTrail? ›

You can create up to five trails per region. A trail that logs activity from all regions counts as one trail per region. You can use resource-level permissions to manage a user's ability to perform specific operations on CloudTrail.

Does AWS CloudTrail enable compliance? ›

AWS CloudTrail is a service that enables governance, compliance, operational auditing, and risk auditing of AWS accounts.

Does GuardDuty use CloudTrail? ›

Amazon GuardDuty is integrated with AWS CloudTrail, a service that provides a record of actions taken by a user, role, or an AWS service in GuardDuty. CloudTrail captures all API calls for GuardDuty as events, including calls from the GuardDuty console and from code calls to the GuardDuty APIs.

Where is CloudTrail logs stored? ›

CloudTrail generates encrypted log files and stores them in Amazon S3.

What is the difference between CloudTrail and cloud config? ›

AWS Config offers a more focused history of events that are based on updates that affect resource configurations. While CloudTrail logs the majority of AWS API activity, AWS Config keeps track of specific updates that are relevant to configurations.

What is the difference between AWS CloudTrail and AWS config? ›

Config is focused on the configuration of your AWS resources and reports with detailed snapshots on how your resources have changed. CloudTrail focuses on the events, or API calls, that drive those changes. It focuses on the user, application, and activity performed on the system.

What is the difference between CloudTrail and CloudTrail logs? ›

CloudTrail helps you ensure compliance and regulatory standards. CloudWatch Logs reports on application logs, while CloudTrail Logs provide you specific information on what occurred in your AWS account. CloudWatch Events is a near real time stream of system events describing changes to your AWS resources.

What is the easiest way to log API calls in AWS? ›

Choose Create.
  1. Step 1: Create an AWS Lambda Function. Create a Lambda function to log the API call events. ...
  2. Step 2: Create a Rule. Create a rule to run your Lambda function whenever you stop an Amazon EC2 instance. ...
  3. Step 3: Test the Rule. You can test your rule by stopping an Amazon EC2 instance using the Amazon EC2 console.

What fields does CloudTrail track? ›

CloudTrail provides event history of your Amazon Web Services account activity, including actions taken through the Amazon Management Console, Amazon SDKs, command line tools, and other Amazon Web Services services. This event history simplifies security analysis, resource change tracking, and troubleshooting.

What is the easiest way to ensure your CloudTrail logs haven t been tampered with? ›

Use server-side encryption with AWS KMS managed keys

By default, the log files delivered by CloudTrail to your bucket are encrypted by Amazon server-side encryption with Amazon S3-managed encryption keys (SSE-S3).

How do I validate log integrity in CloudTrail? ›

The CloudTrail log file integrity validation process also lets you know if a log file has been deleted or changed, or assert positively that no log files were delivered to your account during a given period of time.

Are CloudTrail logs enabled by default? ›

CloudTrail is enabled by default for your AWS account. You can use Event history in the CloudTrail console to view, search, download, archive, analyze, and respond to account activity across your AWS infrastructure.

Is CloudTrail a global service? ›

By default, CloudTrail trails created via the AWS Management Console will have global service events enabled. It is recommended that you only have one trail allocated to global service events per account in order to reduce duplicate events.

What can a user accomplish using AWS CloudTrail? ›

You can use CloudTrail to view, search, download, archive, analyze, and respond to account activity across your AWS infrastructure. You can identify who or what took which action, what resources were acted upon, when the event occurred, and other details to help you analyze and respond to activity in your AWS account.

Which of the following is a benefit of integrating CloudTrail with CloudWatch logs? ›

With CloudTrail – CloudWatch integration enabled, you will be able to better manage your AWS cloud infrastructure. For example, you can receive an SNS notification whenever an authorization failure occurs for your AWS account so you can have finer control over the user access to your cloud account.

What is the purpose of AWS CloudTrail? ›

AWS CloudTrail monitors and records account activity across your AWS infrastructure, giving you control over storage, analysis, and remediation actions.

Does CloudTrail send logs to CloudWatch? ›

CloudTrail supports sending data, Insights, and management events to CloudWatch Logs. For more information, see Working with CloudTrail log files. To send events to a CloudWatch Logs log group: Make sure you have sufficient permissions to create or specify an IAM role.

What is equivalent of CloudTrail in Azure? ›

AWS CloudTrail can be classified as a tool in the "Log Management" category, while Azure Search is grouped under "Search as a Service". Some of the features offered by AWS CloudTrail are: Increased Visibility- CloudTrail provides increased visibility into your user activity by recording AWS API calls.

Which AWS service can be utilized to store these logs securely? ›

You can use Amazon CloudWatch Logs to monitor, store, and access your log files from Amazon Elastic Compute Cloud (Amazon EC2) instances, AWS CloudTrail, Route 53, and other sources.

Which AWS tool can be enabled to maintain an audit log of access? ›

AWS CloudTrail monitors and records account activity across your AWS infrastructure, giving you control over storage, analysis, and remediation actions.

What service is used to store the log files generated by CloudTrail? ›

CloudTrail publishes log files to your S3 bucket in a gzip archive. In the S3 bucket, the log file has a formatted name that includes the following elements: The bucket name that you specified when you created trail (found on the Trails page of the CloudTrail console)

Which AWS service or feature can the is used to securely provide access to its application? ›

AWS Identity and Access Management (IAM) is a web service that helps you securely control access to AWS resources. With IAM, you can centrally manage permissions that control which AWS resources users can access.

Which AWS service is best suited to storing archival data? ›

S3 Glacier Flexible Retrieval (formerly S3 Glacier) is the ideal storage class for archive data that does not require immediate access but needs the flexibility to retrieve large sets of data at no cost, such as backup or disaster recovery use cases.

Which AWS service uses a highly secure hardware storage device to store encryption keys? ›

AWS CloudHSM is a cryptographic service for creating and maintaining hardware security modules (HSMs) in your AWS environment. HSMs are computing devices that process cryptographic operations and provide secure storage for cryptographic keys.

Which AWS feature can a security manager use to secure their logs? ›

AWS Secrets Manager encrypts secrets at rest using encryption keys that you own and store in AWS Key Management Service (AWS KMS).

What are three AWS security monitoring and logging evaluation tools? ›

Logging & Monitoring
  • Centralized Logging on AWS. Deploy a centralized logging solution for collecting, analyzing, and displaying logs on AWS across multiple accounts and AWS Regions.
  • DevOps Monitoring Dashboard on AWS. ...
  • Centralized Logging with OpenSearch. ...
  • Application Monitoring with Amazon CloudWatch.

What is the difference between audit log and activity log? ›

The activity log includes information like when a resource is modified or a virtual machine is started. Audit Logs - All resource logs that record customer interactions with data or the settings of the service. Next time, do not forget to include a link to the documentation you are referring to.

Why is CloudTrail so expensive? ›

Short description. Unexpected CloudTrail cost increases usually occur when multiple trails in the same AWS Region record the same management events. To prevent CloudTrail from logging duplicate management events, verify that your trails' Read and Write events settings are configured correctly.

What is the difference between AWS CloudTrail and cloud logs? ›

CloudTrail helps you ensure compliance and regulatory standards. CloudWatch Logs reports on application logs, while CloudTrail Logs provide you specific information on what occurred in your AWS account. CloudWatch Events is a near real time stream of system events describing changes to your AWS resources.

Which methods are used in Amazon AWS to provide infrastructure security? ›

  • Logging, Monitoring, Threat Detection, and Analytics. Centralized logging, reporting, and analysis of logs to provide visibility and security insights. ...
  • Identity and Access Control. Help define and manage user identity, access policies and entitlements. ...
  • Vulnerability and Configuration Analysis. ...
  • Application Security.

Which security measures is used to protect AWS account? ›

Here are some best practices to consider when securing your account and its resources: Safeguard your passwords and access keys. Activate multi-factor authentication (MFA) on the AWS account root user and any users with interactive access to AWS Identity and Access Management (IAM)

Which one would be the most secure approach for AWS console access? ›

MFA is the best way to protect accounts from inappropriate access. Always set up MFA on your Root user and AWS Identity and Access Management (IAM) users.

Top Articles
Latest Posts
Article information

Author: Tuan Roob DDS

Last Updated:

Views: 6523

Rating: 4.1 / 5 (42 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Tuan Roob DDS

Birthday: 1999-11-20

Address: Suite 592 642 Pfannerstill Island, South Keila, LA 74970-3076

Phone: +9617721773649

Job: Marketing Producer

Hobby: Skydiving, Flag Football, Knitting, Running, Lego building, Hunting, Juggling

Introduction: My name is Tuan Roob DDS, I am a friendly, good, energetic, faithful, fantastic, gentle, enchanting person who loves writing and wants to share my knowledge and understanding with you.