From bfdf41374ba145fb18a5cd5c814b98182afd1f7f Mon Sep 17 00:00:00 2001 From: inovindasari Date: Fri, 26 Apr 2024 15:26:21 +0200 Subject: [PATCH] Switch to IMDSv2 --- etcd.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/etcd.py b/etcd.py index a5fff27..d56abde 100755 --- a/etcd.py +++ b/etcd.py @@ -379,8 +379,13 @@ def __init__(self): self._access_granted = False def load_my_identities(self): + response_token = requests.put( + url='http://169.254.169.254/latest/api/token', + headers={'X-aws-ec2-metadata-token-ttl-seconds': '60'} + ) + token = response_token.text url = 'http://169.254.169.254/latest/dynamic/instance-identity/document' - response = requests.get(url) + response = requests.get(url, headers={'X-aws-ec2-metadata-token': token}) if response.status_code != 200: raise EtcdClusterException('GET %s: code=%s content=%s', url, response.status_code, response.content) json = response.json()