Skip to content

Commit 95c2ba7

Browse files
lhoguinmergify[bot]
authored andcommitted
Add new option require_auth_for_api_desc_page to mgmt
This allows restricting access to the /api/index.html and the /cli/index.html page to authenticated users should the user really want to. This can be enabled via advanced.config. (cherry picked from commit 400e800)
1 parent 6b3d699 commit 95c2ba7

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

deps/rabbitmq_management/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ define PROJECT_ENV
1414
{cors_max_age, 1800},
1515
{content_security_policy, "script-src 'self' 'unsafe-eval' 'unsafe-inline'; object-src 'self'"},
1616
{max_http_body_size, 10000000},
17-
{delegate_count, 5}
17+
{delegate_count, 5},
18+
{require_auth_for_api_desc_page, false}
1819
]
1920
endef
2021

deps/rabbitmq_management/src/rabbit_mgmt_wm_static.erl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
-module(rabbit_mgmt_wm_static).
1212

1313
-include_lib("kernel/include/file.hrl").
14+
-include_lib("rabbitmq_web_dispatch/include/rabbitmq_web_dispatch_records.hrl").
1415

1516
-export([init/2]).
1617
-export([malformed_request/2]).
18+
-export([is_authorized/2]).
1719
-export([forbidden/2]).
1820
-export([content_types_provided/2]).
1921
-export([resource_exists/2]).
@@ -46,6 +48,21 @@ do_init(Req, App, Path) ->
4648
malformed_request(Req, State) ->
4749
cowboy_static:malformed_request(Req, State).
4850

51+
is_authorized(Req0=#{path := Path}, State)
52+
when Path =:= <<"/api/index.html">>; Path =:= <<"/cli/index.html">> ->
53+
case application:get_env(rabbitmq_management, require_auth_for_api_desc_page) of
54+
{ok, true} ->
55+
%% We temporarily use #context{} here to make authorization work,
56+
%% and discard it immediately after since we only want to check
57+
%% whether the user authenticates successfully.
58+
{Res, Req, _} = rabbit_mgmt_util:is_authorized(Req0, #context{}),
59+
{Res, Req, State};
60+
_ ->
61+
{true, Req0, State}
62+
end;
63+
is_authorized(Req, State) ->
64+
{true, Req, State}.
65+
4966
forbidden(Req, State) ->
5067
cowboy_static:forbidden(Req, State).
5168

0 commit comments

Comments
 (0)