Back to Wazuh

AWS CloudTrail

docs/ref/modules/integrations/aws-cloudtrail.md

4.14.44.6 KB
Original Source

AWS CloudTrail

Introduction

The Wazuh AWS module can collect and analyze AWS CloudTrail logs stored in S3 buckets. CloudTrail records API calls and account activity across an AWS infrastructure, providing audit logs for governance, compliance, and security monitoring.

Wazuh retrieves CloudTrail logs from S3, analyzes them using the Wazuh rule engine, and generates alerts for events such as unauthorized API calls, IAM changes, security group modifications, and other suspicious activity.

Prerequisites

  • An AWS account with CloudTrail enabled and configured to deliver logs to an S3 bucket.
  • AWS credentials (access key and secret key) or an IAM role with permissions to read from the S3 bucket.
  • Python 3 and the boto3 library installed on the Wazuh agent.

Configuration

Configure the AWS module in the Wazuh agent ossec.conf file:

xml
  <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>my-cloudtrail-bucket</name>
      <access_key>YOUR_ACCESS_KEY</access_key>
      <secret_key>YOUR_SECRET_KEY</secret_key>
      <regions>us-east-1</regions>
      <path>AWSLogs/</path>
      <only_logs_after>2024-01-01</only_logs_after>
      <remove_from_bucket>no</remove_from_bucket>
    </bucket>
  </wodle>

Configuration options

OptionRequiredDefaultDescription
disabledNonoDisables the AWS module when set to yes.
intervalNo5sTime interval between S3 bucket scans.
run_on_startNoyesProcess logs immediately when the module starts.
skip_on_errorNoyesContinue processing on error instead of stopping.
bucketYesDefines an S3 bucket to monitor. Set type="cloudtrail" for CloudTrail logs.
nameYesName of the S3 bucket.
access_keyNoAWS access key ID. Not required if using IAM roles.
secret_keyNoAWS secret access key. Not required if using IAM roles.
aws_profileNoAWS CLI profile name for authentication.
iam_role_arnNoARN of an IAM role to assume for cross-account access.
iam_role_durationNoDuration in seconds for the assumed IAM role session.
aws_organization_idNoAWS organization ID to filter logs by.
aws_account_idNoSpecific AWS account ID to filter logs by.
aws_account_aliasNoAlias for the AWS account (used in alert enrichment).
regionsNoComma-separated list of AWS regions to monitor.
pathNoS3 key prefix filter for CloudTrail log files.
path_suffixNoS3 key suffix filter.
only_logs_afterNoOnly process logs created after this date (YYYY-MM-DD).
remove_from_bucketNonoDelete log files from the bucket after processing.
discard_fieldNoJSON field name to evaluate for discarding events.
discard_regexNoRegular expression applied to discard_field to filter out matching events.
sts_endpointNoCustom AWS STS endpoint URL.
service_endpointNoCustom AWS S3 endpoint URL.

Authentication using IAM role

Instead of using access keys, you can authenticate using an IAM role:

xml
<bucket type="cloudtrail">
  <name>my-cloudtrail-bucket</name>
  <aws_profile>default</aws_profile>
  <iam_role_arn>arn:aws:iam::123456789012:role/WazuhRole</iam_role_arn>
  <regions>us-east-1,eu-west-1</regions>
</bucket>

AWS setup

Enable CloudTrail

  1. In the AWS Management Console, navigate to CloudTrail.
  2. Create a trail and configure it to deliver logs to an S3 bucket.
  3. Ensure the trail is enabled for all regions if multi-region monitoring is needed.

IAM permissions

The IAM user or role used by Wazuh needs the following permissions on the S3 bucket:

json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "s3:GetObject",
        "s3:ListBucket"
      ],
      "Resource": [
        "arn:aws:s3:::my-cloudtrail-bucket",
        "arn:aws:s3:::my-cloudtrail-bucket/*"
      ]
    }
  ]
}

If using remove_from_bucket, add the s3:DeleteObject permission.

Verify the integration

Restart the Wazuh agent after applying the configuration:

bash
systemctl restart wazuh-agent

Check the module logs:

bash
grep "aws-s3" /var/ossec/logs/ossec.log

CloudTrail events generate alerts with the aws data field containing the original event information.