01 Sign in to your Cloud Conformity console, access Attach Policy to IAM Roles Associated with App-Tier EC2 Instances conformity rule settings and copy the tags defined for AWS resources available in your app tier (e.g. <app_tier_tag>:<app_tier_tag_value>).
02 Run describe-instances command (OSX/Linux/UNIX) using custom query filters to list the IDs of all EC2 instances currently available in the selected region:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
aws ec2 describe-instances
--region us-east-1
--output table
--query 'Reservations[*].Instances[*].InstanceId'
03 The command output should return a table with the requested instance identifiers:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
-------------------------
| DescribeInstances |
+-----------------------+
| i-01234567890bacbac |
| i-01234567890abcabc |
+-----------------------+
04 Run describe-tags command (OSX/Linux/UNIX) using the ID of the EC2 instance that you want to examine as identifier and custom query filters to describe the tags defined for the selected EC2 resource:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
aws ec2 describe-tags
--region us-east-1
--filters "Name=resource-id,Values=i-01234567890bacbac"
--query 'Tags[*].{Value:Value, Key:Key}'
05 The command request should return one of the following outputs:
- If the describe-tags command output returns an empty array (i.e. []), as shown in the example below, the verified instance is not tagged, therefore the audit process for the selected resource ends here:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
[]
- If the command output returns a set of tags that is different than the one copied at step no. 1, as shown in the example below, the verified EC2 instance does not belong to your app tier, therefore the audit process for the selected resource ends here:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
[
{
"Value": "Type",
"Key": "Internet-Facing"
}
]
- If the describe-tags command output returns a set of tags that match the one copied at step no. 1 (e.g. <app_tier_tag>:<app_tier_tag_value>), as shown in the example below, the verified AWS EC2 instance is tagged as an app-tier resource, therefore the audit process continues with the next step:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
[
{
"Key": "<app_tier_tag>",
"Value": "<app_tier_tag_value>"
}
]
06 Run describe-instances command (OSX/Linux/UNIX) using the ID of the app-tier instance that you want to examine as identifier and custom filtering to determine whether the selected EC2 instance is associated with any IAM roles:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
aws ec2 describe-instances
--region us-east-1
--instance-ids i-01234567890bacbac
--query 'Reservations[*].Instances[*].IamInstanceProfile[]'
07 The command request should return one of the following outputs:
- If the describe-instances command output returns an empty array (i.e. []), as shown in the example below, there are no IAM roles associated with the selected app-tier EC2 instance, therefore you need to follow the instructions provided by this conformity rule to create and attach an IAM role.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
[]
- If the command output returns the metadata (unique ID and ARN) for the IAM role associated with the selected app-tier instance, as shown in the example below, the verified EC2 instance does have an IAM role attached and the audit process continues with the next step:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
[
{
"Id": "AAAABBBBCCCCDDDDEEEEF",
"Arn": "arn:aws:iam::123456789012:instance-profile/cc-app-tier-iam-role"
}
]
08 To check for any access policies attached to the IAM role returned at the previous step, based on the policy type used (managed or inline), perform one of the following set of commands:
- For managed IAM policies:
- Run list-attached-role-policies command (OSX/Linux/UNIX) using the name of the IAM service role as identifier (extracted from the resource ARN) to list the managed policies attached to the selected IAM role:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
aws iam list-attached-role-policies
--role-name cc-app-tier-iam-role
- The command output should return the IAM policies metadata:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
{
"AttachedPolicies": []
}
- If the value set for the "AttachedPolicies" attribute is an empty array, as shown in the example above, the selected app-tier IAM role does not have any managed policies attached, therefore the applications running on the app-tier EC2 instance cannot access the necessary AWS services.
- For inline IAM policies:
- Run list-role-policies command (OSX/Linux/UNIX) using the name of the service role as identifier (extracted from the IAM resource ARN) to list the inline policies defined for the selected IAM role:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
aws iam list-role-policies
--role-name cc-app-tier-iam-role
- The command output should return the inline IAM policies metadata:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
{
"PolicyNames": []
}
If the value of the "PolicyNames" attribute is set to an empty array, as shown in the example above, there are no inline policies defined for the selected app-tier IAM role, therefore the applications installed on the app-tier EC2 instance can’t access the necessary AWS services.
09 Repeat steps no. 6 – 8 to check other IAM roles associated with your app-tier EC2 instances, for IAM access policies.
10 Change the AWS region by updating the --region command parameter value and repeat steps no. 2 – 9 to perform the audit process for other regions.