From f1bd5c03967eacfc3e6e2d8cb493cc4fdf7d6111 Mon Sep 17 00:00:00 2001 From: Sean O'Brien <60306702+stobrien89@users.noreply.github.com> Date: Mon, 20 Nov 2023 13:59:14 -0500 Subject: [PATCH] enhancement: hostname resolution (#2831) --- .../nextrelease/update-http-credentials.json | 7 +++++ src/Credentials/EcsCredentialProvider.php | 2 +- .../fixtures/ecs/uri-token-resolution.json | 28 +++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 .changes/nextrelease/update-http-credentials.json diff --git a/.changes/nextrelease/update-http-credentials.json b/.changes/nextrelease/update-http-credentials.json new file mode 100644 index 0000000000..9518133aef --- /dev/null +++ b/.changes/nextrelease/update-http-credentials.json @@ -0,0 +1,7 @@ +[ + { + "type": "enhancement", + "category": "Credentials", + "description": "Adds hostname resolution for the EcsCredentialProvider." + } +] diff --git a/src/Credentials/EcsCredentialProvider.php b/src/Credentials/EcsCredentialProvider.php index fc6c8fbd69..18c210547c 100644 --- a/src/Credentials/EcsCredentialProvider.php +++ b/src/Credentials/EcsCredentialProvider.php @@ -192,7 +192,7 @@ private function isCompatibleUri($uri) if ($host !== $ecsHost && $host !== $eksHost && $host !== self::EKS_SERVER_HOST_IPV6 - && !$this->isLoopbackAddress($host) + && !$this->isLoopbackAddress(gethostbyname($host)) ) { return false; } diff --git a/tests/Credentials/fixtures/ecs/uri-token-resolution.json b/tests/Credentials/fixtures/ecs/uri-token-resolution.json index 2f82066060..8617db694f 100644 --- a/tests/Credentials/fixtures/ecs/uri-token-resolution.json +++ b/tests/Credentials/fixtures/ecs/uri-token-resolution.json @@ -62,6 +62,34 @@ } } }, + { + "description": "http loopback(v4) with host resolution (no port)", + "env": { + "AWS_CONTAINER_CREDENTIALS_FULL_URI": "http://localhost/credentials" + }, + "expect": { + "type": "success", + "request": { + "method": "GET", + "uri": "http://localhost/credentials", + "headers": {} + } + } + }, + { + "description": "http loopback(v4) with host resolution (port)", + "env": { + "AWS_CONTAINER_CREDENTIALS_FULL_URI": "http://localhost:8080/credentials" + }, + "expect": { + "type": "success", + "request": { + "method": "GET", + "uri": "http://localhost:8080/credentials", + "headers": {} + } + } + }, { "description": "http loopback(v6) URI", "env": {