This rule ensures IAM instance roles are used for AWS resource access from instances.
Rule | Ensure IAM instance roles are used for AWS resource access from instances |
Framework | cis_v130 |
Severity | ✔ High |
Ensure IAM Instance Roles are Used for AWS Resource Access from Instances (CIS_v1.3.0)
Using IAM instance roles for AWS resource access from instances ensures that you are following the principle of least privilege and not using individual user credentials or hard-coded keys on EC2 instances, which can be a security risk. This is aligned with the recommendation from the Center for Internet Security (CIS) AWS Foundations Benchmark.
Understanding IAM Instance Roles
IAM instance roles are a secure and efficient way to grant EC2 instances the necessary permissions to access other AWS resources. Instance roles are attached to the EC2 instances and contain policies that define the permissions.
Benefits of Using Instance Roles
Troubleshooting Steps
If an instance role is not working as expected, follow these troubleshooting steps:
Necessary AWS CLI Commands
To audit and remediate non-compliance with this rule, use the following AWS CLI commands:
List EC2 Instances Without an IAM Role
aws ec2 describe-instances --query 'Reservations[*].Instances[*].{ID:InstanceId,IAMRole:IamInstanceProfile}' --output text
Attach an IAM Role to an Instance
aws iam create-instance-profile --instance-profile-name my-instance-profile
aws iam add-role-to-instance-profile --instance-profile-name my-instance-profile --role-name my-iam-role
aws ec2 associate-iam-instance-profile --instance-id i-1234567890abcdef0 --iam-instance-profile Name=my-instance-profile
Updating an IAM Policy
If the instance role does not have the right permissions, update the policy:
aws iam put-role-policy --role-name my-iam-role --policy-name my-policy-name --policy-document file://my-policy.json
Step by Step Guide for Remediation
By following this detailed description, you will bolster your cloud security posture, adhere to the CIS AWS Foundations Benchmark, and avoid common security issues related to hard-coded or statically assigned credentials. Implementing these best practices will contribute positively to your SEO by showing your organization's commitment to security and compliance.