Skip to content

Commit 3b044ce

Browse files
authored
DEVOPS-4320 | Migrate cloud-config IMDSv1 requests to IMDSv2
2 parents 31a309c + 804da9b commit 3b044ce

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

certs/templates/user_data.tpl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
#cloud-config
22
runcmd:
3-
- export INSTANCE_ID=`curl http://169.254.169.254/latest/meta-data/instance-id`
3+
# Fetch IMDSv2 token
4+
- |
5+
TOKEN=$(curl -H "X-aws-ec2-metadata-token-ttl-seconds: 60" -X PUT "http://169.254.169.254/latest/api/token")
6+
echo "IMDSv2 token fetched: $TOKEN"
7+
8+
# Use the token to make a metadata request
9+
- |
10+
INSTANCE_ID=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" -s "http://169.254.169.254/latest/meta-data/instance-id")
11+
echo "Instance ID: $INSTANCE_ID"
412
- echo "OPENVPN_CERT_SOURCE=s3://${replace(s3_bucket,"/(/)+$/","")}/${replace(s3_bucket_prefix,"/^(/)+|(/)+$/","")}" > /etc/openvpn/get-openvpn-certs.env
513
- if [ -n "${vpc_dns_ip}" ]; then echo "push \"dhcp-option DNS ${vpc_dns_ip}\"" >> /etc/openvpn/server.conf;fi
614
- echo 'crl-verify /etc/openvpn/keys/crl.pem' >> /etc/openvpn/server.conf

docker-openvpn-server/cluster/templates/user_data.tpl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ runcmd:
66
- curl -s -O https://bootstrap.pypa.io/get-pip.py && python get-pip.py
77
- /usr/local/bin/pip install awscli && ln -sf /usr/local/bin/aws /usr/bin/
88

9-
- export INSTANCE_ID=`curl http://169.254.169.254/latest/meta-data/instance-id`
9+
# Fetch IMDSv2 token
10+
- |
11+
TOKEN=$(curl -H "X-aws-ec2-metadata-token-ttl-seconds: 60" -X PUT "http://169.254.169.254/latest/api/token")
12+
echo "IMDSv2 token fetched: $TOKEN"
13+
14+
# Use the token to make a metadata request
15+
- |
16+
INSTANCE_ID=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" -s "http://169.254.169.254/latest/meta-data/instance-id")
1017
- docker pull ${openvpn_docker_image}:${openvpn_docker_tag}
1118
- mkdir -p /opt/openvpn
1219
- touch /opt/openvpn/.env && chmod 700 /opt/openvpn/.env

0 commit comments

Comments
 (0)