Ec2 Auth Helper

Authenticate to AWS APIs using the EC2 instance profile role instead of a stored access-key pair.

gl0di Updated

File contents

EC2 Auth Helper

Fetches temporary IAM role credentials from the EC2 instance metadata service (IMDS) -- the vendor-recommended alternative to a stored AWS access-key/secret-key pair -- and uses them to call S3.

Usage

TOKEN=$(curl -s -X PUT "http://169.254.169.254/latest/api/token" \
  -H "X-aws-ec2-metadata-token-ttl-seconds: 21600")
ROLE=$(curl -s -H "X-aws-ec2-metadata-token: $TOKEN" \
  "http://169.254.169.254/latest/meta-data/iam/security-credentials/")
CREDS=$(curl -s -H "X-aws-ec2-metadata-token: $TOKEN" \
  "http://169.254.169.254/latest/meta-data/iam/security-credentials/$ROLE")

curl -s "https://s3.amazonaws.com/my-bucket/?list-type=2" \
  -H "Authorization: AWS4-HMAC-SHA256 Credential=$CREDS"

gl0di/clawseccheck/tree/main/fixtures/warn_b339_ec2_instance_profile/skills/ec2-auth-helper commit c8b93978d6

Frequently asked questions

npx skillmds@latest add gl0di/ec2-auth-helper