From 5eb4a37265c6aa6bbf68435eb08cecfe7f9ba451 Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Wed, 19 Nov 2025 11:04:26 -0800 Subject: [PATCH] Make `rabbitmq_aws` IPv6-aware This PR follows the same pattern as `rabbit_peer_discovery_httpc:maybe_configure_inet6/0`, where `inet:get_rc/0` is used to determine if we're running in an IPv6-only environment. If so, the correct IPv6 address will be used for EC2 IMDS HTTP API requests. Fixes #14974 (cherry picked from commit 2c8e313a438b41331074e56bce26cf60141c1cf4) (cherry picked from commit 13dae27d9db510400c24f8c690ea930e309681b7) --- deps/rabbitmq_aws/include/rabbitmq_aws.hrl | 3 +++ deps/rabbitmq_aws/src/rabbitmq_aws_config.erl | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/deps/rabbitmq_aws/include/rabbitmq_aws.hrl b/deps/rabbitmq_aws/include/rabbitmq_aws.hrl index 6a0cacd81131..f75b06610745 100644 --- a/deps/rabbitmq_aws/include/rabbitmq_aws.hrl +++ b/deps/rabbitmq_aws/include/rabbitmq_aws.hrl @@ -15,7 +15,10 @@ -define(DEFAULT_PROFILE, "default"). -define(INSTANCE_AZ, "placement/availability-zone"). + +% https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html -define(INSTANCE_HOST, "169.254.169.254"). +-define(INSTANCE_HOST_6, "fd00:ec2::254"). % rabbitmq/rabbitmq-peer-discovery-aws#25 diff --git a/deps/rabbitmq_aws/src/rabbitmq_aws_config.erl b/deps/rabbitmq_aws/src/rabbitmq_aws_config.erl index 3d2ae89fe918..f27dbdd27e12 100644 --- a/deps/rabbitmq_aws/src/rabbitmq_aws_config.erl +++ b/deps/rabbitmq_aws/src/rabbitmq_aws_config.erl @@ -419,13 +419,22 @@ instance_availability_zone_url() -> instance_credentials_url(Role) -> instance_metadata_url(string:join([?INSTANCE_METADATA_BASE, ?INSTANCE_CREDENTIALS, Role], "/")). +-spec instance_metadata_host() -> string(). +%% @doc Return the appropriate instance metadata host based on IP family configuration +%% @end +instance_metadata_host() -> + case proplists:get_value(inet6, inet:get_rc(), false) of + true -> ?INSTANCE_HOST_6; + false -> ?INSTANCE_HOST + end. + -spec instance_metadata_url(string()) -> string(). %% @doc Build the Instance Metadata service URL for the specified path %% @end instance_metadata_url(Path) -> rabbitmq_aws_urilib:build(#uri{ scheme = http, - authority = {undefined, ?INSTANCE_HOST, undefined}, + authority = {undefined, instance_metadata_host(), undefined}, path = Path, query = [] }).