Skip to content

Commit 85f59ff

Browse files
committed
fix: Pass token to metadata service requests.
close: #476
1 parent c2f51b2 commit 85f59ff

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

template/eip.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ python3 get-pip.py --user
66
export PATH=~/.local/bin:$PATH
77

88
pip install aws-ec2-assign-elastic-ip
9-
export AWS_DEFAULT_REGION=$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document | grep region | awk -F\" '{print $4}')
9+
export AWS_DEFAULT_REGION=$(curl -s -H "X-aws-ec2-metadata-token: $token" http://169.254.169.254/latest/dynamic/instance-identity/document | grep region | awk -F\" '{print $4}')
1010
/usr/local/bin/aws-ec2-assign-elastic-ip --valid-ips ${eip}

template/logging.tpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ initial_position = start_of_file
3333
EOF
3434

3535
# Set the region to send CloudWatch Logs data to (the region where the instance is located)
36-
region=$(curl -s 169.254.169.254/latest/dynamic/instance-identity/document | jq -r .region)
36+
region=$(curl -s -H "X-aws-ec2-metadata-token: $token" http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r .region)
3737
sed -i -e "s/region = us-east-1/region = $region/g" /etc/awslogs/awscli.conf
3838

3939
# Replace instance id.
40-
instanceId=$(curl -s 169.254.169.254/latest/dynamic/instance-identity/document | jq -r .instanceId)
40+
instanceId=$(curl -s -H "X-aws-ec2-metadata-token: $token" http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r .instanceId)
4141
sed -i -e "s/{instanceId}/$instanceId/g" /etc/awslogs/awslogs.conf
4242

4343
if grep -q ':2$' /etc/system-release-cpe ; then

template/user-data.tpl

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ tee /etc/hosts <<EOL
1010
127.0.0.1 localhost localhost.localdomain $(hostname)
1111
EOL
1212

13+
token=$(curl -f -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 300")
14+
1315
${eip}
1416

1517
for i in {1..7}; do

0 commit comments

Comments
 (0)