CLF-C02 Practice Question 34: IAM Role for EC2
AWS Certified Cloud Practitioner (CLF-C02) · Test 4 · question 4 of 10
A security review finds that an application on an Amazon EC2 instance reads objects from an Amazon S3 bucket using an IAM user's access key ID and secret access key, stored in a configuration file on the instance. What is the MOST secure way for the application to get the permissions it needs?
Show answer and explanation
Answer:
An IAM role attached to the instance (through an instance profile) gives the application *temporary* credentials that it retrieves from the instance metadata. AWS rotates them automatically before they expire. There are no long-term access keys to distribute, store, leak or rotate by hand, and AWS says you "can and should" use a role for applications running on EC2.
Option A protects the file on disk, but the long-term keys still exist. Anyone or anything that can read the decrypted file gets permanent credentials that work from anywhere. Option C only moves the long-term keys to another place on the instance, which any process that can query the instance metadata can read. Option D is better than sharing a person's keys, and rotation limits the damage from a leak, but it still relies on long-term credentials that someone has to manage. Temporary role credentials remove that risk.
Reference: Use an IAM role to grant permissions to applications running on Amazon EC2 instances