|
|
17549d |
From 8f10d0eb1e33d38ab6e89015a903620c54edd7c1 Mon Sep 17 00:00:00 2001
|
|
|
17549d |
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
|
|
|
17549d |
Date: Fri, 13 Nov 2020 16:36:20 +0100
|
|
|
17549d |
Subject: [PATCH] AWS agents: add support for IMDSv2
|
|
|
17549d |
|
|
|
17549d |
---
|
|
|
17549d |
heartbeat/aws-vpc-move-ip | 5 +++--
|
|
|
17549d |
heartbeat/aws-vpc-route53.in | 3 ++-
|
|
|
17549d |
heartbeat/awseip | 9 +++++----
|
|
|
17549d |
heartbeat/awsvip | 7 ++++---
|
|
|
17549d |
4 files changed, 14 insertions(+), 10 deletions(-)
|
|
|
17549d |
|
|
|
17549d |
diff --git a/heartbeat/aws-vpc-move-ip b/heartbeat/aws-vpc-move-ip
|
|
|
17549d |
index 72a89ecb1..cbb629b00 100755
|
|
|
17549d |
--- a/heartbeat/aws-vpc-move-ip
|
|
|
17549d |
+++ b/heartbeat/aws-vpc-move-ip
|
|
|
17549d |
@@ -215,7 +215,8 @@ ec2ip_validate() {
|
|
|
17549d |
return $OCF_ERR_CONFIGURED
|
|
|
17549d |
fi
|
|
|
17549d |
|
|
|
17549d |
- EC2_INSTANCE_ID="$(curl -s http://169.254.169.254/latest/meta-data/instance-id)"
|
|
|
17549d |
+ TOKEN=$(curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600")
|
|
|
17549d |
+ EC2_INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id -H "X-aws-ec2-metadata-token: $TOKEN")
|
|
|
17549d |
|
|
|
17549d |
if [ -z "${EC2_INSTANCE_ID}" ]; then
|
|
|
17549d |
ocf_exit_reason "Instance ID not found. Is this a EC2 instance?"
|
|
|
17549d |
@@ -329,7 +330,7 @@ ec2ip_get_instance_eni() {
|
|
|
17549d |
fi
|
|
|
17549d |
ocf_log debug "MAC address associated with interface ${OCF_RESKEY_interface}: ${MAC_ADDR}"
|
|
|
17549d |
|
|
|
17549d |
- cmd="curl -s http://169.254.169.254/latest/meta-data/network/interfaces/macs/${MAC_ADDR}/interface-id"
|
|
|
17549d |
+ cmd="curl -s http://169.254.169.254/latest/meta-data/network/interfaces/macs/${MAC_ADDR}/interface-id -H \"X-aws-ec2-metadata-token: $TOKEN\""
|
|
|
17549d |
ocf_log debug "executing command: $cmd"
|
|
|
17549d |
EC2_NETWORK_INTERFACE_ID="$(eval $cmd)"
|
|
|
17549d |
rc=$?
|
|
|
17549d |
diff --git a/heartbeat/aws-vpc-route53.in b/heartbeat/aws-vpc-route53.in
|
|
|
17549d |
index b06b93726..4fb17019b 100644
|
|
|
17549d |
--- a/heartbeat/aws-vpc-route53.in
|
|
|
17549d |
+++ b/heartbeat/aws-vpc-route53.in
|
|
|
17549d |
@@ -347,7 +347,8 @@ r53_monitor() {
|
|
|
17549d |
_get_ip() {
|
|
|
17549d |
case $OCF_RESKEY_ip in
|
|
|
17549d |
local|public)
|
|
|
17549d |
- IPADDRESS="$(curl -s http://169.254.169.254/latest/meta-data/${OCF_RESKEY_ip}-ipv4)";;
|
|
|
17549d |
+ TOKEN=$(curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600")
|
|
|
17549d |
+ IPADDRESS=$(curl -s http://169.254.169.254/latest/meta-data/${OCF_RESKEY_ip}-ipv4 -H "X-aws-ec2-metadata-token: $TOKEN");;
|
|
|
17549d |
*.*.*.*)
|
|
|
17549d |
IPADDRESS="${OCF_RESKEY_ip}";;
|
|
|
17549d |
esac
|
|
|
17549d |
diff --git a/heartbeat/awseip b/heartbeat/awseip
|
|
|
17549d |
index 445a03666..de1967774 100755
|
|
|
17549d |
--- a/heartbeat/awseip
|
|
|
17549d |
+++ b/heartbeat/awseip
|
|
|
17549d |
@@ -149,12 +149,12 @@ awseip_start() {
|
|
|
17549d |
awseip_monitor && return $OCF_SUCCESS
|
|
|
17549d |
|
|
|
17549d |
if [ -n "${PRIVATE_IP_ADDRESS}" ]; then
|
|
|
17549d |
- NETWORK_INTERFACES_MACS="$(curl -s http://169.254.169.254/latest/meta-data/network/interfaces/macs/)"
|
|
|
17549d |
+ NETWORK_INTERFACES_MACS=$(curl -s http://169.254.169.254/latest/meta-data/network/interfaces/macs/ -H "X-aws-ec2-metadata-token: $TOKEN")
|
|
|
17549d |
for MAC in ${NETWORK_INTERFACES_MACS}; do
|
|
|
17549d |
- curl -s http://169.254.169.254/latest/meta-data/network/interfaces/macs/${MAC}/local-ipv4s |
|
|
|
17549d |
+ curl -s http://169.254.169.254/latest/meta-data/network/interfaces/macs/${MAC}/local-ipv4s -H "X-aws-ec2-metadata-token: $TOKEN" |
|
|
|
17549d |
grep -q "^${PRIVATE_IP_ADDRESS}$"
|
|
|
17549d |
if [ $? -eq 0 ]; then
|
|
|
17549d |
- NETWORK_ID="$(curl -s http://169.254.169.254/latest/meta-data/network/interfaces/macs/${MAC}/interface-id)"
|
|
|
17549d |
+ NETWORK_ID=$(curl -s http://169.254.169.254/latest/meta-data/network/interfaces/macs/${MAC}/interface-id -H "X-aws-ec2-metadata-token: $TOKEN")
|
|
|
17549d |
fi
|
|
|
17549d |
done
|
|
|
17549d |
$AWSCLI --profile $OCF_RESKEY_profile ec2 associate-address \
|
|
|
17549d |
@@ -244,7 +244,8 @@ AWSCLI="${OCF_RESKEY_awscli}"
|
|
|
17549d |
ELASTIC_IP="${OCF_RESKEY_elastic_ip}"
|
|
|
17549d |
ALLOCATION_ID="${OCF_RESKEY_allocation_id}"
|
|
|
17549d |
PRIVATE_IP_ADDRESS="${OCF_RESKEY_private_ip_address}"
|
|
|
17549d |
-INSTANCE_ID="$(curl -s http://169.254.169.254/latest/meta-data/instance-id)"
|
|
|
17549d |
+TOKEN=$(curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600")
|
|
|
17549d |
+INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id -H "X-aws-ec2-metadata-token: $TOKEN")
|
|
|
17549d |
|
|
|
17549d |
case $__OCF_ACTION in
|
|
|
17549d |
start)
|
|
|
17549d |
diff --git a/heartbeat/awsvip b/heartbeat/awsvip
|
|
|
17549d |
index 3eb31e6ae..8050107e8 100755
|
|
|
17549d |
--- a/heartbeat/awsvip
|
|
|
17549d |
+++ b/heartbeat/awsvip
|
|
|
17549d |
@@ -206,9 +206,10 @@ esac
|
|
|
17549d |
|
|
|
17549d |
AWSCLI="${OCF_RESKEY_awscli}"
|
|
|
17549d |
SECONDARY_PRIVATE_IP="${OCF_RESKEY_secondary_private_ip}"
|
|
|
17549d |
-INSTANCE_ID="$(curl -s http://169.254.169.254/latest/meta-data/instance-id)"
|
|
|
17549d |
-MAC_ADDRESS="$(curl -s http://169.254.169.254/latest/meta-data/mac)"
|
|
|
17549d |
-NETWORK_ID="$(curl -s http://169.254.169.254/latest/meta-data/network/interfaces/macs/${MAC_ADDRESS}/interface-id)"
|
|
|
17549d |
+TOKEN=$(curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600")
|
|
|
17549d |
+INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id -H "X-aws-ec2-metadata-token: $TOKEN")
|
|
|
17549d |
+MAC_ADDRESS=$(curl -s http://169.254.169.254/latest/meta-data/mac -H "X-aws-ec2-metadata-token: $TOKEN")
|
|
|
17549d |
+NETWORK_ID=$(curl -s http://169.254.169.254/latest/meta-data/network/interfaces/macs/${MAC_ADDRESS}/interface-id -H "X-aws-ec2-metadata-token: $TOKEN")
|
|
|
17549d |
|
|
|
17549d |
case $__OCF_ACTION in
|
|
|
17549d |
start)
|