Last active
June 27, 2024 10:52
-
-
Save JGalego/252f2008ef7cb2ee79d7000df7220cd3 to your computer and use it in GitHub Desktop.
Harvest AWS Credentials from IMDSv2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Adapted from https://rhynorater.github.io/AWS-Metadata-Identity-Credentials | |
token=`curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` \ | |
export AWS_DEFAULT_REGION=`curl -s -H "X-aws-ec2-metadata-token: $token" http://169.254.169.254/latest/meta-data/placement/region` | |
creds=`curl -s -H "X-aws-ec2-metadata-token: $token" http://169.254.169.254/latest/meta-data/identity-credentials/ec2/security-credentials/ec2-instance/` | |
export AWS_ACCESS_KEY_ID=`echo ${creds} | jq -r .AccessKeyId` | |
export AWS_SECRET_ACCESS_KEY=`echo ${creds} | jq -r .SecretAccessKey` | |
export AWS_SESSION_TOKEN=`echo ${creds} | jq -r .Token` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment