Skip to content

Commit 13dae27

Browse files
lukebakkenmergify[bot]
authored andcommitted
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 2c8e313)
1 parent 8a38a2a commit 13dae27

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

deps/rabbitmq_aws/include/rabbitmq_aws.hrl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
-define(DEFAULT_PROFILE, "default").
1616

1717
-define(INSTANCE_AZ, "placement/availability-zone").
18+
19+
% https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html
1820
-define(INSTANCE_HOST, "169.254.169.254").
21+
-define(INSTANCE_HOST_6, "fd00:ec2::254").
1922

2023
% rabbitmq/rabbitmq-peer-discovery-aws#25
2124

deps/rabbitmq_aws/src/rabbitmq_aws_config.erl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,13 +420,22 @@ instance_availability_zone_url() ->
420420
instance_credentials_url(Role) ->
421421
instance_metadata_url(string:join([?INSTANCE_METADATA_BASE, ?INSTANCE_CREDENTIALS, Role], "/")).
422422

423+
-spec instance_metadata_host() -> string().
424+
%% @doc Return the appropriate instance metadata host based on IP family configuration
425+
%% @end
426+
instance_metadata_host() ->
427+
case proplists:get_value(inet6, inet:get_rc(), false) of
428+
true -> ?INSTANCE_HOST_6;
429+
false -> ?INSTANCE_HOST
430+
end.
431+
423432
-spec instance_metadata_url(string()) -> string().
424433
%% @doc Build the Instance Metadata service URL for the specified path
425434
%% @end
426435
instance_metadata_url(Path) ->
427436
rabbitmq_aws_urilib:build(#uri{
428437
scheme = http,
429-
authority = {undefined, ?INSTANCE_HOST, undefined},
438+
authority = {undefined, instance_metadata_host(), undefined},
430439
path = Path,
431440
query = []
432441
}).

0 commit comments

Comments
 (0)