01 Run describe-trails command (OSX/Linux/UNIX) to list the names of all CloudTrail trails currently available within the selected AWS region:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
aws cloudtrail describe-trails
--region us-east-1
--output table
--query 'trailList[*].Name'
02 The command output should return a table with the requested trail name(s):
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
---------------------------
| DescribeTrails |
+-------------------------+
| cc-env-cloud-trail |
+-------------------------+
03 Run again describe-trails command (OSX/Linux/UNIX) using the name of the trail returned at the previous step and custom query filters to get the name of the S3 bucket utilized to store the log files for the selected AWS CloudTrail trail:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
aws cloudtrail describe-trails
--region us-east-1
--trail-name-list cc-env-cloud-trail
--query 'trailList[*].S3BucketName'
04 The command output should return the name of the requested S3 bucket:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
[
"cc-env-trail-logs"
]
05 Now run list-objects command (OSX/Linux/UNIX) to list the names of all S3 objects available in the selected S3 bucket:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
aws s3api list-objects
--region us-east-1
--bucket cc-env-trail-logs
--query 'Contents[].Key'
06 The command output should expose the name of each S3 object (i.e. CloudTrail log file) currently available within the selected S3 bucket:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
[
"AWSLogs/123456789012/CloudTrail/us-east-1/2017/03/17/123456789012_
CloudTrail_us-east-1_20170317T1012Z_11tQnvmb05cuBxKd6.json.gz",
"AWSLogs/123456789012/CloudTrail/us-east-1/2017/03/17/123456789012_
CloudTrail_us-east-1_20170317T1012Z_65ZWtvmCqOcuwXIo.json.gz",
"AWSLogs/123456789012/CloudTrail/us-east-1/2017/03/17/123456789012_
CloudTrail_us-east-1_20170317T1012Z_ntG0rPDvTVMKJdLe.json.gz",
"AWSLogs/123456789012/CloudTrail/us-east-1/2017/03/17/123456789012_
CloudTrail_us-east-1_20170317T1012Z_00euohtdKFqkNjPH.json.gz"
]
07 Run get-object command (OSX/Linux/UNIX) to get the right CloudTrail log file (e.g. 20170317T1012Z_11tQnvmb05cuBxKd6.json.gz) from the specified S3 bucket and download it to your machine:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
aws s3api get-object
--region us-east-1
--bucket env-cloudtrail-logs
--key AWSLogs/123456789012/CloudTrail/us-east-1/2017/03/17/123456789012_CloudTrail_us-east-1_20170317T1012Z_11tQnvmb05cuBxKd6.json.gz 20170317T1012Z_11tQnvmb05cuBxKd6.json.gz
08 The command output should return the GET request metadata:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
{
"AcceptRanges": "bytes",
"ContentType": "application/json",
"LastModified": "Sat, 17 Mar 2017 10:12:39 GMT",
"ContentLength": 5980,
"ContentEncoding": "gzip",
"ETag": "\"fca6fa01349b8713ec69e0e4cf6971b8\"",
"ServerSideEncryption": "AES256",
"Metadata": {}
}
09 Now extract and open the required CloudTrail log file, downloaded at the previous step (e.g. 20170317T1012Z_11tQnvmb05cuBxKd6.json.gz), in your preferred text editor.
10 Once the log file is opened, search for the following attributes in order to identify the necessary log record:
- "eventSource":"redshift.amazonaws.com" – for the name of the AWS service used to place the RN purchase request.
- "eventName":"PurchaseReservedNodeOffering" – for the name of the AWS API action/command used to place the RN purchase request.
- "eventTime":"2017-03-17T10:12:39.112Z" – for the time when the Redshift RN purchase request was placed.
11 Identify the right CloudTrail log record based on the attributes listed at the previous step and verify the "userIdentity" attribute value to determine your unwanted Redshift RN purchase request origin and context.
12 Repeat steps no. 7 – 11 to verify the request origin and context for other unwanted Redshift Reserved Node (RN) purchases available within the selected region.
13 Change the AWS region by updating the --region command parameter value and perform the entire remediation process for other regions.