From 0cb263e3321f6e96a9a88fa9a03215240f99a198 Mon Sep 17 00:00:00 2001 From: reginaldalfret Date: Tue, 6 Oct 2026 10:42:55 +0530 Subject: [PATCH] ec2-metadata: bypass proxy for IMDS requests When http_proxy or HTTP_PROXY is configured in the environment, curl attempts to route instance metadata requests through the proxy server. Add --noproxy '*' to curl invocations in ec2-metadata so that local metadata requests are always sent directly to IMDS. Fixes #52 Signed-off-by: reginaldalfret --- ec2-metadata | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ec2-metadata b/ec2-metadata index 0dea7cf..8b4ffde 100755 --- a/ec2-metadata +++ b/ec2-metadata @@ -53,7 +53,7 @@ QUIET="" function set_imds_token() { if [ -z "${IMDS_TOKEN}" ];then - IMDS_TOKEN=$(curl -s -f -X PUT -H "X-aws-ec2-metadata-token-ttl-seconds: 900" "${METADATA_BASEURL}/${METADATA_TOKEN_PATH}") + IMDS_TOKEN=$(curl --noproxy '*' -s -f -X PUT -H "X-aws-ec2-metadata-token-ttl-seconds: 900" "${METADATA_BASEURL}/${METADATA_TOKEN_PATH}") if [ "${?}" -gt 0 ] || [ -z "${IMDS_TOKEN}" ]; then echo '[ERROR] Could not get IMDSv2 token. Instance Metadata might have been disabled or this is not an EC2 instance.' >&2 exit 1 @@ -65,7 +65,7 @@ function set_imds_token() function get_meta() { local imds_out - imds_out=$(curl -s -q -H "X-aws-ec2-metadata-token:${IMDS_TOKEN}" -f "${METADATA_BASEURL}/${METADATA_VERSION}/${1}") + imds_out=$(curl --noproxy '*' -s -q -H "X-aws-ec2-metadata-token:${IMDS_TOKEN}" -f "${METADATA_BASEURL}/${METADATA_VERSION}/${1}") echo -n "${imds_out}" }