Skip to content

Commit 536535f

Browse files
snoordnpalm
authored andcommitted
fix: use IMDSv2 url when setting PARENT_INSTANCE_ID (#497)
1 parent 34378e1 commit 536535f

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

template/gitlab-runner.tpl

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
# Install jq if not exists
2+
if ! [ -x "$(command -v jq)" ]; then
3+
yum install jq -y
4+
fi
5+
16
# Provide the parent instance id in the spawned runner tags
2-
PARENT_INSTANCE_ID=$(curl http://169.254.169.254/latest/meta-data/instance-id);
7+
PARENT_INSTANCE_ID=$(curl -s -H "X-aws-ec2-metadata-token: $token" http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r .instanceId)
38
PARENT_TAG="gitlab-runner-parent-id,$${PARENT_INSTANCE_ID}"
49

510
mkdir -p /etc/gitlab-runner
@@ -62,11 +67,6 @@ docker-machine rm -y dummy-machine
6267
unset HOME
6368
unset USER
6469

65-
# Install jq if not exists
66-
if ! [ -x "$(command -v jq)" ]; then
67-
yum install jq -y
68-
fi
69-
7070
# fetch Runner token from SSM and validate it
7171
token=$(aws ssm get-parameters --names "${secure_parameter_store_runner_token_key}" --with-decryption --region "${secure_parameter_store_region}" | jq -r ".Parameters | .[0] | .Value")
7272

0 commit comments

Comments
 (0)