From 5ea3967a23608c7ffe0ab6e404c0ec4187510651 Mon Sep 17 00:00:00 2001 From: BenCodeOcean <109240650+BenCodeOcean@users.noreply.github.com> Date: Mon, 31 Oct 2022 14:47:27 +0200 Subject: [PATCH 1/2] imdsv2 support added --- install.sh | 7 +++++++ shared/utils.sh | 10 +++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index 0674c33..ad3f5c5 100644 --- a/install.sh +++ b/install.sh @@ -59,6 +59,9 @@ Options -s, --initial-size SIZE Initial size of the volume in GB. (Default: 200) Only used if --initial-device is NOT specified. + + -i, --imdsv2 + Enable imdsv2 for instance metadata API requests. EOF ) @@ -99,6 +102,10 @@ while (( "$#" )); do MOUNTPOINT=$2 shift 2 ;; + -i|--imdsv2) + IMDSV2="true" + shift 1 + ;; -h|--help) echo "$USAGE" exit diff --git a/shared/utils.sh b/shared/utils.sh index 85f8a4e..631ac81 100644 --- a/shared/utils.sh +++ b/shared/utils.sh @@ -30,10 +30,14 @@ function get_metadata() { local key=$1 - local metdata_ip='169.254.169.254' - local token=$(curl -s -X PUT "http://$metdata_ip/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 60") + local metadata_ip='169.254.169.254' + + if [ ! -z "$IMDSV2" ]; then + local token=$(curl -s -X PUT "http://$metadata_ip/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 60") + local token_wrapper=`-H "X-aws-ec2-metadata-token: $token"` + fi - echo `curl -s -H "X-aws-ec2-metadata-token: $token" http://$metdata_ip/latest/meta-data/$key` + echo `curl -s $token_wrapper http://$metadata_ip/latest/meta-data/$key` } function initialize() { From 06e1f1be002cbb9b6eddc40998d2b22a6c664ed2 Mon Sep 17 00:00:00 2001 From: BenCodeOcean <109240650+BenCodeOcean@users.noreply.github.com> Date: Mon, 31 Oct 2022 16:34:28 +0200 Subject: [PATCH 2/2] initialize call moved --- install.sh | 4 ++-- shared/utils.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index ad3f5c5..3d37a9e 100644 --- a/install.sh +++ b/install.sh @@ -76,8 +76,6 @@ BASEDIR=$(dirname $0) . ${BASEDIR}/shared/utils.sh -initialize - # parse options PARAMS="" while (( "$#" )); do @@ -126,6 +124,8 @@ done eval set -- "$PARAMS" +initialize + # for backwards compatibility evaluate positional parameters like previous 2.0.x and 2.1.x releases # this will be removed in the future if [ ! -z "$PARAMS" ]; then diff --git a/shared/utils.sh b/shared/utils.sh index 631ac81..d1a216e 100644 --- a/shared/utils.sh +++ b/shared/utils.sh @@ -34,7 +34,7 @@ function get_metadata() { if [ ! -z "$IMDSV2" ]; then local token=$(curl -s -X PUT "http://$metadata_ip/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 60") - local token_wrapper=`-H "X-aws-ec2-metadata-token: $token"` + local token_wrapper='-H "X-aws-ec2-metadata-token: $token"' fi echo `curl -s $token_wrapper http://$metadata_ip/latest/meta-data/$key`