-
Notifications
You must be signed in to change notification settings - Fork 4k
Optionally allow separate configuration of auth_backends for all HTTP-based plugins (protocols, APIs) #13464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
aaron-seo
wants to merge
4
commits into
rabbitmq:main
from
aaron-seo:as/web-dispatch-auth-backend-config
Closed
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b048ed5
Add new configuration for rabbitmq_web_dispatch.auth_backends with a …
aaron-seo b619e66
Explicitly handle undefined case for getting web_dispatch.auth_backends
aaron-seo 8c09e6c
Rename web_dispatch config prefix to http_dispatch
aaron-seo 4b09415
Cleanup leftover code and comments, and multiline log message
aaron-seo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
deps/rabbitmq_web_dispatch/priv/schema/rabbitmq_web_dispatch.schema
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| % vim:ft=erlang: | ||
| %% ---------------------------------------------------------------------------- | ||
| %% RabbitMQ Web Dispatch | ||
| %% | ||
| %% ---------------------------------------------------------------------------- | ||
|
|
||
| %% =========================================================================== | ||
| %% Auth Backends | ||
|
|
||
| %% Select an authentication backend to use for the management plugin. RabbitMQ provides an | ||
| %% internal backend in the core. | ||
| %% | ||
| %% {web_dispatch.auth_backends, [rabbit_auth_backend_internal]}, | ||
|
|
||
| {translation, "rabbitmq_web_dispatch.auth_backends", | ||
| fun(Conf) -> | ||
| Settings = cuttlefish_variable:filter_by_prefix("web_dispatch.auth_backends", Conf), | ||
| BackendModule = fun | ||
| (internal) -> rabbit_auth_backend_internal; | ||
| (ldap) -> rabbit_auth_backend_ldap; | ||
| (http) -> rabbit_auth_backend_http; | ||
| (oauth) -> rabbit_auth_backend_oauth2; | ||
| (oauth2) -> rabbit_auth_backend_oauth2; | ||
| (cache) -> rabbit_auth_backend_cache; | ||
| (amqp) -> rabbit_auth_backend_amqp; | ||
| (dummy) -> rabbit_auth_backend_dummy; | ||
| (Other) when is_atom(Other) -> Other; | ||
| (_) -> cuttlefish:invalid("Unknown/unsupported auth backend") | ||
| end, | ||
| AuthBackends = [{Num, {default, BackendModule(V)}} || {["web_dispatch", "auth_backends", Num], V} <- Settings], | ||
| AuthNBackends = [{Num, {authn, BackendModule(V)}} || {["web_dispatch", "auth_backends", Num, "authn"], V} <- Settings], | ||
| AuthZBackends = [{Num, {authz, BackendModule(V)}} || {["web_dispatch", "auth_backends", Num, "authz"], V} <- Settings], | ||
| Backends = lists:foldl( | ||
| fun({NumStr, {Type, V}}, Acc) -> | ||
| Num = case catch list_to_integer(NumStr) of | ||
| N when is_integer(N) -> N; | ||
| Err -> | ||
| cuttlefish:invalid( | ||
| iolist_to_binary(io_lib:format( | ||
| "Auth backend position in the chain should be an integer ~p", [Err]))) | ||
| end, | ||
| NewVal = case dict:find(Num, Acc) of | ||
| {ok, {AuthN, AuthZ}} -> | ||
| case {Type, AuthN, AuthZ} of | ||
| {authn, undefined, _} -> | ||
| {V, AuthZ}; | ||
| {authz, _, undefined} -> | ||
| {AuthN, V}; | ||
| _ -> | ||
| cuttlefish:invalid( | ||
| iolist_to_binary( | ||
| io_lib:format( | ||
| "Auth backend already defined for the ~pth ~p backend", | ||
| [Num, Type]))) | ||
| end; | ||
| error -> | ||
| case Type of | ||
| authn -> {V, undefined}; | ||
| authz -> {undefined, V}; | ||
| default -> {V, V} | ||
| end | ||
| end, | ||
| dict:store(Num, NewVal, Acc) | ||
| end, | ||
| dict:new(), | ||
| AuthBackends ++ AuthNBackends ++ AuthZBackends), | ||
| lists:map( | ||
| fun | ||
| ({Num, {undefined, AuthZ}}) -> | ||
| cuttlefish:warn( | ||
| io_lib:format( | ||
| "Auth backend undefined for the ~pth authz backend. Using ~p", | ||
| [Num, AuthZ])), | ||
| {AuthZ, AuthZ}; | ||
| ({Num, {AuthN, undefined}}) -> | ||
| cuttlefish:warn( | ||
| io_lib:format( | ||
| "Authz backend undefined for the ~pth authn backend. Using ~p", | ||
| [Num, AuthN])), | ||
| {AuthN, AuthN}; | ||
| ({_Num, {Auth, Auth}}) -> Auth; | ||
| ({_Num, {AuthN, AuthZ}}) -> {AuthN, AuthZ} | ||
| end, | ||
| lists:keysort(1, dict:to_list(Backends))) | ||
| end}. | ||
|
|
||
| {mapping, "web_dispatch.auth_backends.$num", "rabbitmq_web_dispatch.auth_backends", [ | ||
| {datatype, atom} | ||
| ]}. | ||
|
|
||
| {mapping, "web_dispatch.auth_backends.$num.authn", "rabbitmq_web_dispatch.auth_backends",[ | ||
| {datatype, atom} | ||
| ]}. | ||
|
|
||
| {mapping, "web_dispatch.auth_backends.$num.authz", "rabbitmq_web_dispatch.auth_backends",[ | ||
| {datatype, atom} | ||
| ]}. | ||
|
|
||
| %{mapping, "management.test_config", "rabbitmq_management.test_config", | ||
| % [{datatype, {enum, [true, false]}}]}. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| %% This Source Code Form is subject to the terms of the Mozilla Public | ||
| %% License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| %% file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
| %% | ||
| %% Copyright (c) 2007-2025 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved. | ||
| %% | ||
|
|
||
| -module(config_schema_SUITE). | ||
|
|
||
| -compile(export_all). | ||
|
|
||
| all() -> | ||
| [ | ||
| run_snippets | ||
| ]. | ||
|
|
||
| %% ------------------------------------------------------------------- | ||
| %% Testsuite setup/teardown. | ||
| %% ------------------------------------------------------------------- | ||
|
|
||
| init_per_suite(Config) -> | ||
| rabbit_ct_helpers:log_environment(), | ||
| Config1 = rabbit_ct_helpers:run_setup_steps(Config), | ||
| rabbit_ct_config_schema:init_schemas(rabbitmq_web_dispatch, Config1). | ||
|
|
||
|
|
||
| end_per_suite(Config) -> | ||
| rabbit_ct_helpers:run_teardown_steps(Config). | ||
|
|
||
| init_per_testcase(Testcase, Config) -> | ||
| rabbit_ct_helpers:testcase_started(Config, Testcase), | ||
| Config1 = rabbit_ct_helpers:set_config(Config, [ | ||
| {rmq_nodename_suffix, Testcase} | ||
| ]), | ||
| rabbit_ct_helpers:run_steps(Config1, | ||
| rabbit_ct_broker_helpers:setup_steps() ++ | ||
| rabbit_ct_client_helpers:setup_steps()). | ||
|
|
||
| end_per_testcase(Testcase, Config) -> | ||
| Config1 = rabbit_ct_helpers:run_steps(Config, | ||
| rabbit_ct_client_helpers:teardown_steps() ++ | ||
| rabbit_ct_broker_helpers:teardown_steps()), | ||
| rabbit_ct_helpers:testcase_finished(Config1, Testcase). | ||
|
|
||
| %% ------------------------------------------------------------------- | ||
| %% Testcases. | ||
| %% ------------------------------------------------------------------- | ||
|
|
||
| run_snippets(Config) -> | ||
| ok = rabbit_ct_broker_helpers:rpc(Config, 0, | ||
| ?MODULE, run_snippets1, [Config]). | ||
|
|
||
| run_snippets1(Config) -> | ||
| rabbit_ct_config_schema:run_snippets(Config). |
64 changes: 64 additions & 0 deletions
64
deps/rabbitmq_web_dispatch/test/config_schema_SUITE_data/rabbitmq_web_dispatch.snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| % vim:ft=erlang: | ||
| % | ||
|
|
||
| [{internal_auth_backend, | ||
| "web_dispatch.auth_backends.1 = internal", | ||
| [{rabbitmq_web_dispatch,[{auth_backends,[rabbit_auth_backend_internal]}]}], | ||
| []}, | ||
| {ldap_auth_backend, | ||
| "web_dispatch.auth_backends.1 = ldap", | ||
| [{rabbitmq_web_dispatch,[{auth_backends,[rabbit_auth_backend_ldap]}]}], | ||
| []}, | ||
| {http_auth_backend, | ||
| "web_dispatch.auth_backends.1 = http", | ||
| [{rabbitmq_web_dispatch,[{auth_backends,[rabbit_auth_backend_http]}]}], | ||
| []}, | ||
| {oauth2_auth_backend, | ||
| "web_dispatch.auth_backends.1 = oauth2", | ||
| [{rabbitmq_web_dispatch,[{auth_backends,[rabbit_auth_backend_oauth2]}]}], | ||
| []}, | ||
| {multiple_auth_backends, | ||
| "web_dispatch.auth_backends.1 = ldap | ||
| web_dispatch.auth_backends.2 = internal", | ||
| [{rabbitmq_web_dispatch, | ||
| [{auth_backends, | ||
| [rabbit_auth_backend_ldap,rabbit_auth_backend_internal]}]}], | ||
| []}, | ||
| {full_name_auth_backend, | ||
| "web_dispatch.auth_backends.1 = ldap | ||
| # uses module name instead of a short alias, \"http\" | ||
| web_dispatch.auth_backends.2 = rabbit_auth_backend_http", | ||
| [{rabbitmq_web_dispatch, | ||
| [{auth_backends,[rabbit_auth_backend_ldap,rabbit_auth_backend_http]}]}], | ||
| []}, | ||
| {third_party_auth_backend, | ||
| "web_dispatch.auth_backends.1.authn = internal | ||
| # uses module name because this backend is from a 3rd party | ||
| web_dispatch.auth_backends.1.authz = rabbit_auth_backend_ip_range", | ||
| [{rabbitmq_web_dispatch, | ||
| [{auth_backends, | ||
| [{rabbit_auth_backend_internal,rabbit_auth_backend_ip_range}]}]}], | ||
| []}, | ||
| {authn_authz_backend, | ||
| "web_dispatch.auth_backends.1.authn = ldap | ||
| web_dispatch.auth_backends.1.authz = internal", | ||
| [{rabbitmq_web_dispatch, | ||
| [{auth_backends, | ||
| [{rabbit_auth_backend_ldap,rabbit_auth_backend_internal}]}]}], | ||
| []}, | ||
| {authn_authz_multiple_backends, | ||
| "web_dispatch.auth_backends.1.authn = ldap | ||
| web_dispatch.auth_backends.1.authz = internal | ||
| web_dispatch.auth_backends.2 = internal", | ||
| [{rabbitmq_web_dispatch, | ||
| [{auth_backends, | ||
| [{rabbit_auth_backend_ldap,rabbit_auth_backend_internal}, | ||
| rabbit_auth_backend_internal]}]}], | ||
| []}, | ||
| {authn_backend_only, | ||
| "web_dispatch.auth_backends.1.authn = ldap", | ||
| [{rabbitmq_web_dispatch, | ||
| [{auth_backends, | ||
| [{rabbit_auth_backend_ldap,rabbit_auth_backend_ldap}]}]}], | ||
| []} | ||
| ]. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.