A logistics company runs a fleet tracking application on Amazon EC2 instances in AWS Account A. The application must write daily transaction logs to an Amazon S3 bucket located in AWS Account B. The S3 bucket is configured with default encryption using an AWS KMS customer managed key (CMK) owned by Account B. The solutions architect must implement a secure, cross-account access solution that adheres to the principle of least privilege and avoids long-term security credentials. Which combination of steps will meet these requirements?
- AEnable the AWS account root user of Account B to generate access keys. Store these root access keys as a plaintext String parameter in the AWS Systems Manager Parameter Store of Account A. Configure the application on the EC2 instances to retrieve these root credentials at startup to authenticate the cross-account write and KMS encryption operations.
- BCreate an IAM user in Account B with permissions to write to the S3 bucket and use the CMK. Generate long-term access keys for this user, and store them as a plaintext String parameter in the Systems Manager Parameter Store of Account A. Configure the EC2 instances to retrieve these access keys at runtime to perform the upload.
- Attach an IAM role to the EC2 instances in Account A. Grant the role permissions to perform s3:PutObject on the S3 bucket in Account B and kms:GenerateDataKey on the KMS CMK in Account B. In Account B, configure the S3 bucket policy to allow the IAM role to perform s3:PutObject, and configure the CMK key policy to allow the IAM role to perform kms:GenerateDataKey.Answer
- DAttach an IAM role to the EC2 instances in Account A. In Account B, configure the bucket policy and the CMK key policy to trust the entire AWS Account A. Enable automatic annual key rotation for the CMK in Account B, which will automatically decrypt and re-encrypt all existing log files in the S3 bucket using the new key version so that older key versions do not need to be preserved.
Answer
Attach an IAM role to the EC2 instances in Account A. Grant the role permissions to perform s3:PutObject on the S3 bucket in Account B and kms:GenerateDataKey on the KMS CMK in Account B. In Account B, configure the S3 bucket policy to allow the IAM role to perform s3:PutObject, and configure the CMK key policy to allow the IAM role to perform kms:GenerateDataKey.
The correct solution involves attaching an IAM role to the EC2 instances in Account A to provide temporary security credentials. The role is granted permission to write to Account B's bucket and generate data keys from Account B's customer managed key (CMK). In Account B, both the S3 bucket policy and the KMS key policy must trust the specific IAM role from Account A to allow the cross-account upload and encryption operations.
Step-by-Step Solution
Key Concept
Cross-account access to S3 buckets encrypted with a KMS Customer Managed Key requires IAM policies, S3 bucket policies, and KMS key policies to align and explicitly trust the calling IAM principal using temporary credentials.