Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion deps/rabbitmq_stream/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ APP_ENV = """[
{frame_max, 1048576},
{heartbeat, 60},
{advertised_host, undefined},
{advertised_port, undefined}
{advertised_port, undefined},
{advertise_localhost_to_localhost_clients, true}
]"""

all_beam_files(name = "all_beam_files")
Expand Down
3 changes: 2 additions & 1 deletion deps/rabbitmq_stream/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ define PROJECT_ENV
{frame_max, 1048576},
{heartbeat, 60},
{advertised_host, undefined},
{advertised_port, undefined}
{advertised_port, undefined},
{advertise_localhost_to_localhost_clients, true}
]
endef

Expand Down
4 changes: 4 additions & 0 deletions deps/rabbitmq_stream/priv/schema/rabbitmq_stream.schema
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ end}.
{datatype, integer}
]}.

{mapping, "stream.advertise_localhost_to_localhost_clients", "rabbitmq_stream.advertise_localhost_to_localhost_clients", [
{datatype, {enum, [true, false]}}
]}.

{mapping, "stream.advertised_host", "rabbitmq_stream.advertised_host", [
{datatype, string}
]}.
Expand Down
4 changes: 4 additions & 0 deletions deps/rabbitmq_stream/src/rabbit_stream.erl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
tls_host/0,
port/0,
tls_port/0,
advertise_localhost_to_localhost_clients/0,
kill_connection/1]).
-export([stop/1]).
-export([emit_connection_info_local/3,
Expand Down Expand Up @@ -119,6 +120,9 @@ tls_port_from_listener() ->
undefined, Listeners),
Port.

advertise_localhost_to_localhost_clients() ->
application:get_env(rabbitmq_stream, advertise_localhost_to_localhost_clients, true).

stop(_State) ->
ok.

Expand Down
20 changes: 15 additions & 5 deletions deps/rabbitmq_stream/src/rabbit_stream_reader.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1542,12 +1542,22 @@ handle_frame_pre_auth(Transport,
VirtualHost,
{socket, S},
#{}),
ClientUsesLoopback = rabbit_net:is_loopback(S),
ShouldAdvertiseLoopback = rabbit_stream:advertise_localhost_to_localhost_clients(),
AdvertisedHost =
case TransportLayer of
tcp ->
rabbit_stream:host();
ssl ->
rabbit_stream:tls_host()
case {ClientUsesLoopback, ShouldAdvertiseLoopback} of
%% if the user originally connects from localhost, advertise localhost as the connection
%% hostname: connecting using a non-local hostname
%% will fail the loopback check. See rabbitmq/rabbitmq-server#9424
{true, true} ->
<<"localhost">>;
{_, _} ->
case TransportLayer of
tcp ->
rabbit_stream:host();
ssl ->
rabbit_stream:tls_host()
end
end,
AdvertisedPort =
case TransportLayer of
Expand Down