Skip to content

Commit a9c8f58

Browse files
Streams: advertise localhost to local clients
Note that there is a way to opt out just in case. Closes #9424.
1 parent 47e1ffd commit a9c8f58

File tree

5 files changed

+27
-7
lines changed

5 files changed

+27
-7
lines changed

deps/rabbitmq_stream/BUILD.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ APP_ENV = """[
3636
{frame_max, 1048576},
3737
{heartbeat, 60},
3838
{advertised_host, undefined},
39-
{advertised_port, undefined}
39+
{advertised_port, undefined},
40+
{advertise_localhost_to_localhost_clients, true}
4041
]"""
4142

4243
all_beam_files(name = "all_beam_files")

deps/rabbitmq_stream/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ define PROJECT_ENV
1616
{frame_max, 1048576},
1717
{heartbeat, 60},
1818
{advertised_host, undefined},
19-
{advertised_port, undefined}
19+
{advertised_port, undefined},
20+
{advertise_localhost_to_localhost_clients, true}
2021
]
2122
endef
2223

deps/rabbitmq_stream/priv/schema/rabbitmq_stream.schema

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ end}.
184184
{datatype, integer}
185185
]}.
186186

187+
{mapping, "stream.advertise_localhost_to_localhost_clients", "rabbitmq_stream.advertise_localhost_to_localhost_clients", [
188+
{datatype, {enum, [true, false]}}
189+
]}.
190+
187191
{mapping, "stream.advertised_host", "rabbitmq_stream.advertised_host", [
188192
{datatype, string}
189193
]}.

deps/rabbitmq_stream/src/rabbit_stream.erl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
tls_host/0,
2424
port/0,
2525
tls_port/0,
26+
advertise_localhost_to_localhost_clients/0,
2627
kill_connection/1]).
2728
-export([stop/1]).
2829
-export([emit_connection_info_local/3,
@@ -119,6 +120,9 @@ tls_port_from_listener() ->
119120
undefined, Listeners),
120121
Port.
121122

123+
advertise_localhost_to_localhost_clients() ->
124+
application:get_env(rabbitmq_stream, advertise_localhost_to_localhost_clients, true).
125+
122126
stop(_State) ->
123127
ok.
124128

deps/rabbitmq_stream/src/rabbit_stream_reader.erl

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,12 +1542,22 @@ handle_frame_pre_auth(Transport,
15421542
VirtualHost,
15431543
{socket, S},
15441544
#{}),
1545+
ClientUsesLoopback = rabbit_net:is_loopback(S),
1546+
ShouldAdvertiseLoopback = rabbit_stream:advertise_localhost_to_localhost_clients(),
15451547
AdvertisedHost =
1546-
case TransportLayer of
1547-
tcp ->
1548-
rabbit_stream:host();
1549-
ssl ->
1550-
rabbit_stream:tls_host()
1548+
case {ClientUsesLoopback, ShouldAdvertiseLoopback} of
1549+
%% if the user is connected from localhost, advertise localhost as the connection
1550+
%% hostname: connecting using a non-local hostname
1551+
%% will fail the loopback check. See rabbitmq/rabbitmq-server#9424
1552+
{true, true} ->
1553+
<<"localhost">>;
1554+
{_, _} ->
1555+
case TransportLayer of
1556+
tcp ->
1557+
rabbit_stream:host();
1558+
ssl ->
1559+
rabbit_stream:tls_host()
1560+
end
15511561
end,
15521562
AdvertisedPort =
15531563
case TransportLayer of

0 commit comments

Comments
 (0)