-
Improvement
-
Resolution: Unresolved
-
Major
-
None
In our AWS environment we avoid using static AWS credentials (i.e. AWS Access Key ID and AWS Secret Access Key) - instead we use ephemeral credentials that are supplied using the Amazon IAM/STS system.
i.e. The use of static AWS credentials is not possible in our environment - we need to dynamically acquire credentials on the master / slave to. These credentials are then used to switch roles per our IAM configuration.
Once the credentials are acquired, we use those credentials (Access Key ID, Secret Access Key, Session Token) to perform AWS actions as normal.
An example
As a brief example (from a pipeline script)
env.AWS_ACCESS_KEY_ID = "" env.AWS_SECRET_ACCESS_KEY = "" env.AWS_SESSION_TOKEN = "" roleArn = "arn:aws:iam::<13 character AWS ID>:role/my-custom-role" externalParam = "--external-id ABCDEFG" // security parameter - optional json = sh(returnStdout: true, script: "aws sts assume-role --duration-seconds 3600 --role-arn ${roleARN} --role-session-name rsn ${externalParam}" def jsonSlurper = new groovy.json.JsonSlurperClassic() def object = jsonSlurper.parseText(json) return object.Credentials
Important points
- external-id support required
- credentials must be acquired on the correct instance (you can't always acquire on master as the security configuration is locked down per instance type)
- credentials expire after an hour (maximum)
- Access Key ID can be logged, but the other parameters should not be
most (all?) modern AWS SDKs will provide some sort of credentials chain that should include, as a final step, checking the metadata service on 169.254.169.254. That will in turn expose temporary credentials for the instance profile. If you can set the profile to use the correct role when the instance boots, it can really simplify this logic, because all the SDKs will just use them by default.