An integration-test stage needs short-lived credentials to call AWS APIs in a separate test account during the run, and the security team forbids storing any long-lived access keys in the pipeline. The build runs in "AWS CodeBuild". What is the most secure way to grant the build access to the test account?
- AStore an IAM access key pair for a test-account user in "AWS Secrets Manager" and have the build retrieve and export the keys before running the integration tests.
- BBake a test-account access key and secret into the "CodeBuild" project environment variables so the build can authenticate to the test account during the run.
- CCreate a permanent IAM user in the test account, attach the needed policies, and place its credentials in an encrypted "Amazon S3" object the build downloads at start.
- DGive the "CodeBuild" service role permission to assume a cross-account IAM role in the test account, and have the build call "AWS Security Token Service" to get temporary credentials. Correct
Why A is wrong: Encrypting keys in Secrets Manager is better than plaintext but still relies on long-lived credentials, which the security team forbids, so it fails the stated constraint.
Why B is wrong: Plaintext keys in environment variables are long-lived and easily leaked through logs, directly violating the no-long-lived-keys rule, so this is the weakest option.
Why C is wrong: A permanent user with stored credentials in S3 is still long lived and adds rotation burden, so encryption at rest does not satisfy the short-lived-credential requirement.
Why D is correct: Assuming a cross-account role via STS yields short-lived credentials scoped by the role, with no stored keys, satisfying least privilege and the no-long-lived-keys requirement.