From 00a62f95b56e1696cd6360d2959ff7244263be02 Mon Sep 17 00:00:00 2001 From: Alexander Tarasov Date: Fri, 31 Jul 2020 07:52:27 +0200 Subject: [PATCH] Add support for AWS IMDSv2 (#158) Co-authored-by: Alexander Tarasov --- import_users.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/import_users.sh b/import_users.sh index f55dca7..b5a711f 100755 --- a/import_users.sh +++ b/import_users.sh @@ -61,8 +61,9 @@ fi : ${USERDEL_ARGS:="--force --remove"} # Initizalize INSTANCE variable -INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id) -REGION=$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document | grep region | awk -F\" '{print $4}') +METADATA_TOKEN=$(curl -s -X PUT -H 'x-aws-ec2-metadata-token-ttl-seconds: 60' http://169.254.169.254/latest/api/token) +INSTANCE_ID=$(curl -s -H "x-aws-ec2-metadata-token: ${METADATA_TOKEN}" http://169.254.169.254/latest/meta-data/instance-id) +REGION=$(curl -s -H "x-aws-ec2-metadata-token: ${METADATA_TOKEN}" http://169.254.169.254/latest/dynamic/instance-identity/document | grep region | awk -F\" '{print $4}') function setup_aws_credentials() { local stscredentials