Skip to content
This repository was archived by the owner on Jan 16, 2025. It is now read-only.

Commit ef16287

Browse files
authored
fix: Update launch template to use metadata service v2 (#1278)
* Update launch template to use metadata service v2, Update bootstrap script to generate v2 token * add -f flag to curl commands to better deal with failures
1 parent 99ed5a1 commit ef16287

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

Diff for: modules/runners/main.tf

+6
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ resource "aws_launch_template" "runner" {
5757
}
5858
}
5959

60+
metadata_options {
61+
http_endpoint = "enabled"
62+
http_tokens = "required"
63+
http_put_response_hop_limit = 1
64+
}
65+
6066
iam_instance_profile {
6167
name = aws_iam_instance_profile.runner.name
6268
}

Diff for: modules/runners/templates/install-config-runner.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
cd /home/$USER_NAME
22
mkdir actions-runner && cd actions-runner
33

4-
REGION=$(curl -s 169.254.169.254/latest/dynamic/instance-identity/document | jq -r .region)
4+
TOKEN=$(curl -f -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 180")
5+
REGION=$(curl -f -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r .region)
56

67
aws s3 cp ${s3_location_runner_distribution} actions-runner.tar.gz --region $REGION
78
tar xzf ./actions-runner.tar.gz
89
rm -rf actions-runner.tar.gz
910

1011
${arm_patch}
1112

12-
INSTANCE_ID=$(wget -q -O - http://169.254.169.254/latest/meta-data/instance-id)
13-
13+
INSTANCE_ID=$(curl -f -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/meta-data/instance-id)
1414

1515
echo wait for configuration
1616
while [[ $(aws ssm get-parameters --names ${environment}-$INSTANCE_ID --with-decryption --region $REGION | jq -r ".Parameters | .[0] | .Value") == null ]]; do

0 commit comments

Comments
 (0)