Hi, I’m Agata.
Sorry for the long title.
This time I’d like to talk about AWS CloudTrail.
CloudTrail is an auditing mechanism in AWS that is designed to record activities on AWS. If you have multiple accounts, it is recommended as a best practice to create an audit account and aggregate CloudTrail logs into that account.
Under normal circumstances, it is very easy to set up CloudTrail by setting up an Organization, placing multiple accounts under the Organization, and setting up CloudTrail from the Organization’s administrative account.
However, I will try to set it up without depending on Organization.
Therefore, the target users are only those who have multiple AWS accounts but are not managing them by Organization (for some reason, this is not possible).
The specific settings are based on the following AWS help.
However, the documentation for each task was scattered and tedious to read, and some of the content was outdated, so I summarized it below.
As in the AWS help above, we will assume that you have the following AWS accounts. (The help shows four accounts, but except for the audit account, the rest are the same and redundant, so I’ll just use the following two)
Enable CloudTrail on the AWS account for auditing and create a trail.
You can use existing S3 buckets, KMS keys, etc., but we will create all new ones.
Set up the S3 bucket of the AWS account for auditing so that it can receive log files from multiple accounts.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AWSCloudTrailAclCheck20150319",
"Effect": "Allow",
"Principal": {
"Service": "cloudtrail.amazonaws.com"
},
"Action": "s3:GetBucketAcl",
"Resource": "arn:aws:s3:::myBucketName"
},
{
"Sid": "AWSCloudTrailWrite-111111111111",
"Effect": "Allow",
"Principal": {
"Service": "cloudtrail.amazonaws.com"
},
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::myBucketName/optionalLogFilePrefix/AWSLogs/111111111111/*",
"Condition": {
"StringEquals": {
"s3:x-amz-acl": "bucket-owner-full-control",
"AWS:SourceArn": "arn:aws:cloudtrail:region:111111111111:trail/trailName"
}
}
},
{
"Sid": "AWSCloudTrailWrite-interstellar-test",
"Effect": "Allow",
"Principal": {
"Service": "cloudtrail.amazonaws.com"
},
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::myBucketName/optionalLogFilePrefix/AWSLogs/222222222222/*",
"Condition": {
"StringEquals": {
"s3:x-amz-acl": "bucket-owner-full-control",
"AWS:SourceArn": "arn:aws:cloudtrail:region:222222222222:trail/trailName"
}
}
}
]
}
Edit the key policy of the KMS key you created so that it can be accessed by other accounts.
{
"Version": "2012-10-17",
"Id": "Key policy created by CloudTrail",
"Statement": [
{
"Sid": "Enable IAM User Permissions",
"Effect": "Allow",
"Principal": {
"AWS": [
"arn:aws:iam::111111111111:root"
]
},
"Action": "kms:*",
"Resource": "*"
},
{
"Sid": "Allow CloudTrail to encrypt logs",
"Effect": "Allow",
"Principal": {
"Service": "cloudtrail.amazonaws.com"
},
"Action": "kms:GenerateDataKey*",
"Resource": "*",
"Condition": {
"StringEquals": {
"AWS:SourceArn": [
"arn:aws:cloudtrail:region:111111111111:trail/trailName",
"arn:aws:cloudtrail:region:222222222222:trail/trailName"
]
},
"StringLike": {
"kms:EncryptionContext:aws:cloudtrail:arn": [
"arn:aws:cloudtrail:*:111111111111:trail/*",
"arn:aws:cloudtrail:*:222222222222:trail/*"
]
}
}
},
{
"Sid": "Allow CloudTrail to describe key",
"Effect": "Allow",
"Principal": {
"Service": "cloudtrail.amazonaws.com"
},
"Action": "kms:DescribeKey",
"Resource": "*"
},
{
"Sid": "Allow principals in the account to decrypt log files",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": [
"kms:Decrypt",
"kms:ReEncryptFrom"
],
"Resource": "*",
"Condition": {
"StringEquals": {
"kms:CallerAccount": "111111111111"
},
"StringLike": {
"kms:EncryptionContext:aws:cloudtrail:arn": "arn:aws:cloudtrail:*:111111111111:trail/*"
}
}
},
{
"Sid": "Allow alias creation during setup",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "kms:CreateAlias",
"Resource": "*",
"Condition": {
"StringEquals": {
"kms:CallerAccount": "111111111111",
"kms:ViaService": "ec2.ap-northeast-1.amazonaws.com"
}
}
},
{
"Sid": "Enable cross account log decryption",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": [
"kms:Decrypt",
"kms:ReEncryptFrom"
],
"Resource": "*",
"Condition": {
"StringEquals": {
"kms:CallerAccount": "111111111111"
},
"StringLike": {
"kms:EncryptionContext:aws:cloudtrail:arn": "arn:aws:cloudtrail:*:111111111111:trail/*"
}
}
}
]
}
Create a trail as in 1, but configure it as follows.
This completes the configuration.
After a while, the CloudTrail logs will start to be recorded in the S3 bucket you created.
If it does not log properly, check the S3 bucket’s policy.