An application deployed on an Amazon EC2 instance uses the AWS SDK to retrieve secrets from AWS Secrets Manager. The EC2 instance has an IAM instance profile attached with the required permissions. However, when the application runs, it fails to authenticate and throws an AccessDenied exception, attempting to use credentials belonging to a different IAM user. Which of the following is the most likely cause of this credential conflict based on the AWS SDK default credential provider chain order of precedence?
- Active environment variables for AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are present on the EC2 instance, overriding the EC2 instance profile credentials.Answer
- BThe SDK retrieves credentials from the EC2 Instance Metadata Service (IMDS) which prioritizes the shared credentials file located at ~/.aws/credentials over instance profile roles.
- CThe EC2 instance is trying to use an ECS Task Execution Role that was specified in the application's environment configuration.
- DThe IAM trust policy of the instance profile's role is misconfigured, causing the default credential provider chain to fall back to the IAM user's credentials stored in AWS Systems Manager Parameter Store.
Answer
Active environment variables for AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are present on the EC2 instance, overriding the EC2 instance profile credentials.
The default credential provider chain evaluates environment variables (such as AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY) before checking the EC2 Instance Metadata Service (IMDS). If environment variables from another user are active on the instance, the SDK will use those credentials, ignoring the instance profile.
Step-by-Step Solution
Key Concept
AWS SDK Default Credential Provider Chain Resolution Order