Skip to content

Commit 1675b2e

Browse files
Fix schema issues
And fix selenium script to run rabbitrmq locally
1 parent 135f6aa commit 1675b2e

File tree

13 files changed

+122
-90
lines changed

13 files changed

+122
-90
lines changed

deps/rabbitmq_auth_backend_oauth2/src/oauth2_schema.erl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ translate_list_of_signing_keys(ListOfKidPath) ->
6969
-spec translate_endpoint_params(list(), [{list(), binary()}]) -> map().
7070
translate_endpoint_params(Variable, Conf) ->
7171
Params0 = cuttlefish_variable:filter_by_prefix("auth_oauth2." ++ Variable, Conf),
72-
Params = [{list_to_binary(Param), list_to_binary(V)} ||
73-
{["auth_oauth2", _, Param], V} <- Params0],
72+
Params = [{Param, V} || {["auth_oauth2", _, Param], V} <- Params0],
7473
maps:from_list(Params).
7574

7675
validator_file_exists(Attr, Filename) ->
@@ -120,7 +119,7 @@ mapOauthProviderProperty({Key, Value}) ->
120119
token_endpoint -> validator_https_uri(Key, Value);
121120
jwks_uri -> validator_https_uri(Key, Value);
122121
end_session_endpoint -> validator_https_uri(Key, Value);
123-
authorization_endpoint -> validator_https_uri(Key, Value);
122+
authorization_endpoint -> validator_https_uri(Key, Value);
124123
discovery_endpoint_params ->
125124
cuttlefish:invalid(io_lib:format(
126125
"Invalid attribute (~p) value: should be a map of Key,Value pairs", [Key]));

deps/rabbitmq_auth_backend_oauth2/test/config_schema_SUITE_data/rabbitmq_auth_backend_oauth2.snippets

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
auth_oauth2.https.depth = 5
1919
auth_oauth2.https.fail_if_no_peer_cert = false
2020
auth_oauth2.https.hostname_verification = wildcard
21+
auth_oauth2.discovery_endpoint_path = /.well-known/openid-configuration
22+
auth_oauth2.discovery_endpoint_params.param1 = value1
2123
auth_oauth2.https.crl_check = true
2224
auth_oauth2.algorithms.1 = HS256
2325
auth_oauth2.algorithms.2 = RS256",
@@ -30,6 +32,10 @@
3032
{preferred_username_claims, [<<"user_name">>, <<"username">>, <<"email">>]},
3133
{verify_aud, true},
3234
{issuer, "https://my-jwt-issuer"},
35+
{discovery_endpoint_path, "/.well-known/openid-configuration"},
36+
{discovery_endpoint_params, #{
37+
"param1" => "value1"
38+
}},
3339
{key_config, [
3440
{default_key, <<"id1">>},
3541
{signing_keys,

deps/rabbitmq_auth_backend_oauth2/test/oauth2_schema_SUITE.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ test_with_endpoint_params(_) ->
6060
{["auth_oauth2","discovery_endpoint_params","param1"], "some-value1"},
6161
{["auth_oauth2","discovery_endpoint_params","param2"], "some-value2"}
6262
],
63-
#{ <<"param1">> := <<"some-value1">>, <<"param2">> := <<"some-value2">> } =
63+
#{ "param1" := "some-value1", "param2" := "some-value2" } =
6464
translate_endpoint_params("discovery_endpoint_params", Conf).
6565

6666
test_invalid_oauth_providers_endpoint_params(_) ->
@@ -103,7 +103,7 @@ test_with_many_oauth_providers(_) ->
103103
{["auth_oauth2","oauth_providers","uaa","issuer"],"https://uaa"},
104104
{["auth_oauth2","oauth_providers","uaa","discovery_endpoint_path"],"/some-path"}
105105
],
106-
#{<<"keycloak">> := [{issuer, <<"https://keycloak">>}
106+
#{<<"keycloak">> := [{issuer, <<"https://keycloak">>}
107107
],
108108
<<"uaa">> := [{issuer, <<"https://uaa">>},
109109
{discovery_endpoint_path, <<"/some-path">>}

deps/rabbitmq_management/priv/schema/rabbitmq_management.schema

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ end}.
473473
[{datatype, string}]}.
474474

475475
%% Configure OAuth2 authorization_endpoint additional request parameters
476-
{mapping, "management.oauth_authorization_endpoint_params.$name",
476+
{mapping, "management.oauth_authorization_endpoint_params.$name",
477477
"rabbitmq_management.oauth_authorization_endpoint_params",
478478
[{datatype, string}]}.
479479

@@ -483,7 +483,7 @@ end}.
483483
end}.
484484

485485
%% Configure OAuth2 token_endpoint additional request parameters
486-
{mapping, "management.oauth_token_endpoint_params.$name",
486+
{mapping, "management.oauth_token_endpoint_params.$name",
487487
"rabbitmq_management.oauth_token_endpoint_params",
488488
[{datatype, string}]}.
489489

@@ -568,17 +568,17 @@ end}.
568568
"rabbitmq_management.oauth_resource_servers",
569569
[{datatype, {enum, [sp_initiated, idp_initiated]}}]}.
570570

571-
{mapping, "management.oauth_resource_servers.$name.oauth_authorization_endpoint_params.$name",
572-
""rabbitmq_management.oauth_resource_servers",
571+
{mapping, "management.oauth_resource_servers.$name.oauth_authorization_endpoint_params.$name",
572+
"rabbitmq_management.oauth_resource_servers",
573573
[{datatype, string}]}.
574574

575-
{mapping, "management.oauth_resource_servers.$name.oauth_token_endpoint_params.$name",
576-
""rabbitmq_management.oauth_resource_servers",
575+
{mapping, "management.oauth_resource_servers.$name.oauth_token_endpoint_params.$name",
576+
"rabbitmq_management.oauth_resource_servers",
577577
[{datatype, string}]}.
578578

579579
{translation, "rabbitmq_management.oauth_resource_servers",
580580
fun(Conf) ->
581-
rabbit_mgmt_schema:translate_resource_servers(Conf)
581+
rabbit_mgmt_schema:translate_oauth_resource_servers(Conf)
582582
end}.
583583

584584
%% ===========================================================================

deps/rabbitmq_management/src/rabbit_mgmt_schema.erl

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
translate_endpoint_params/2
1414
]).
1515

16+
extract_key({Name,_}) -> Name.
1617
extract_key_as_binary({Name,_}) -> list_to_binary(Name).
1718
extract_value({_Name,V}) -> V.
1819

1920
-spec translate_oauth_resource_servers([{list(), binary()}]) -> map().
2021
translate_oauth_resource_servers(Conf) ->
2122
Settings = cuttlefish_variable:filter_by_prefix(
2223
"management.oauth_resource_servers", Conf),
24+
rabbit_log:debug("Settings: ~p", [Settings]),
2325
Map = merge_list_of_maps([
2426
extract_resource_server_properties(Settings),
2527
extract_resource_server_endpoint_params(oauth_authorization_endpoint_params, Settings),
@@ -37,28 +39,31 @@ translate_oauth_resource_servers(Conf) ->
3739
-spec translate_endpoint_params(list(), [{list(), binary()}]) -> map().
3840
translate_endpoint_params(Variable, Conf) ->
3941
Params0 = cuttlefish_variable:filter_by_prefix("management." ++ Variable, Conf),
40-
Params = [{list_to_binary(Param), list_to_binary(V)} ||
41-
{["management", _, Param], V} <- Params0],
42-
maps:from_list(Params).
42+
Params = [{Param, list_to_binary(V)} || {["management", _, Param], V} <- Params0].
4343

4444
merge_list_of_maps(ListOfMaps) ->
4545
lists:foldl(fun(Elem, AccIn) -> maps:merge_with(fun(_K,V1,V2) -> V1 ++ V2 end,
4646
Elem, AccIn) end, #{}, ListOfMaps).
4747

4848

4949
extract_resource_server_properties(Settings) ->
50-
KeyFun = fun extract_key_as_binary/1,
50+
KeyFun = fun extract_key/1,
5151
ValueFun = fun extract_value/1,
5252

53-
OAuthProviders = [{Name, {list_to_atom(Key), list_to_binary(V)}}
53+
OAuthProviders = [{Name, {list_to_atom(Key), V}}
5454
|| {["management","oauth_resource_servers", Name, Key], V} <- Settings ],
55-
maps:groups_from_list(KeyFun, ValueFun, OAuthProviders).
55+
rabbit_log:debug("extract_resource_server_properties ~p", [Settings]),
56+
Result = maps:groups_from_list(KeyFun, ValueFun, OAuthProviders),
57+
rabbit_log:debug("extract_resource_server_properties -> ~p", [Result]),
58+
59+
Result.
5660

5761
extract_resource_server_endpoint_params(Variable, Settings) ->
58-
KeyFun = fun extract_key_as_binary/1,
62+
KeyFun = fun extract_key/1,
5963

60-
IndexedParams = [{Name, {list_to_binary(ParamName), list_to_binary(V)}} ||
64+
rabbit_log:debug("extract_resource_server_endpoint_params ~p ~p", [Variable, Settings]),
65+
IndexedParams = [{Name, {ParamName, list_to_binary(V)}} ||
6166
{["management","oauth_resource_servers", Name, EndpointVar, ParamName], V}
6267
<- Settings, EndpointVar == atom_to_list(Variable) ],
63-
maps:map(fun(_K,V)-> [{Variable, maps:from_list(V)}] end,
64-
maps:groups_from_list(KeyFun, fun({_, V}) -> V end, IndexedParams)).
68+
maps:map(fun(_K,V)-> [{Variable, V}] end,
69+
maps:groups_from_list(KeyFun, fun({_, V}) -> V end, IndexedParams)).

deps/rabbitmq_management/src/rabbit_mgmt_wm_auth.erl

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ variances(Req, Context) ->
2525
content_types_provided(ReqData, Context) ->
2626
{rabbit_mgmt_util:responder_map(to_json), ReqData, Context}.
2727

28-
merge_property(Key, List, MapIn) ->
29-
case proplists:get_value(Key, List) of
28+
merge_property(Key, List, MapIn) ->
29+
case proplists:get_value(Key, List) of
3030
undefined -> MapIn;
3131
V0 -> MapIn#{Key => V0}
3232
end.
3333

3434
extract_oauth_provider_info_props_as_map(ManagementProps) ->
35-
lists:foldl(fun(K, Acc) ->
36-
merge_property(K, ManagementProps, Acc) end, #{}, [oauth_provider_url,
37-
oauth_metadata_url, oauth_authorization_endpoint_params,
35+
lists:foldl(fun(K, Acc) ->
36+
merge_property(K, ManagementProps, Acc) end, #{}, [oauth_provider_url,
37+
oauth_metadata_url, oauth_authorization_endpoint_params,
3838
oauth_token_endpoint_params]).
3939

4040
merge_oauth_provider_info(OAuthResourceServer, MgtResourceServer, ManagementProps) ->
@@ -46,19 +46,19 @@ merge_oauth_provider_info(OAuthResourceServer, MgtResourceServer, ManagementProp
4646
{ok, OAuthProvider} -> oauth_provider_to_map(OAuthProvider);
4747
{error, _} -> #{}
4848
end,
49-
OAuthProviderInfo1 = maps:merge(OAuthProviderInfo0,
49+
OAuthProviderInfo1 = maps:merge(OAuthProviderInfo0,
5050
extract_oauth_provider_info_props_as_map(ManagementProps)),
5151
maps:merge(OAuthProviderInfo1, proplists:to_map(MgtResourceServer)).
5252

5353
oauth_provider_to_map(OAuthProvider) ->
5454
% only include issuer and end_session_endpoint for now. The other endpoints are resolved by oidc-client library
55-
Map0 = case OAuthProvider#oauth_provider.issuer of
55+
Map0 = case OAuthProvider#oauth_provider.issuer of
5656
undefined -> #{};
5757
Issuer -> #{ oauth_provider_url => Issuer,
58-
oauth_metadata_url => OAuthProvider#oauth_provider.discovery_endpoint
58+
oauth_metadata_url => OAuthProvider#oauth_provider.discovery_endpoint
5959
}
6060
end,
61-
case OAuthProvider#oauth_provider.end_session_endpoint of
61+
case OAuthProvider#oauth_provider.end_session_endpoint of
6262
undefined -> Map0;
6363
V -> maps:put(end_session_endpoint, V, Map0)
6464
end.
@@ -80,7 +80,7 @@ extract_oauth2_and_mgt_resources(OAuth2BackendProps, ManagementProps) ->
8080
MgtResources = maps:map(
8181
fun(K,V) -> merge_oauth_provider_info(maps:get(K, OAuth2Resources, #{}), V, ManagementProps) end,
8282
skip_disabled_mgt_resource_servers(MgtResources1)),
83-
case maps:size(MgtResources) of
83+
case maps:size(MgtResources) of
8484
0 -> {};
8585
_ -> {MgtResources}
8686
end.
@@ -89,21 +89,21 @@ getAllDeclaredOauth2Resources(OAuth2BackendProps) ->
8989
OAuth2Resources = proplists:get_value(resource_servers, OAuth2BackendProps, #{}),
9090
case proplists:get_value(resource_server_id, OAuth2BackendProps) of
9191
undefined -> OAuth2Resources;
92-
Id -> maps:put(Id, buildRootResourceServerIfAny(Id, OAuth2BackendProps),
92+
Id -> maps:put(Id, buildRootResourceServerIfAny(Id, OAuth2BackendProps),
9393
OAuth2Resources)
9494
end.
9595
buildRootResourceServerIfAny(Id, Props) ->
96-
[ {id, Id},
97-
{oauth_client_id,
98-
proplists:get_value(oauth_client_id, Props)},
96+
[ {id, Id},
97+
{oauth_client_id,
98+
proplists:get_value(oauth_client_id, Props)},
9999
{oauth_client_secret,
100100
proplists:get_value(oauth_client_secret, Props)},
101-
{oauth_response_type,
101+
{oauth_response_type,
102102
proplists:get_value(oauth_response_type, Props)},
103-
{authorization_endpoint_params,
103+
{authorization_endpoint_params,
104104
proplists:get_value(authorization_endpoint_params, Props)},
105-
{token_endpoint_params,
106-
proplists:get_value(token_endpoint_params, Props)}
105+
{token_endpoint_params,
106+
proplists:get_value(token_endpoint_params, Props)}
107107
].
108108

109109
authSettings() ->
@@ -114,7 +114,10 @@ authSettings() ->
114114
false -> [{oauth_enabled, false}];
115115
true ->
116116
case extract_oauth2_and_mgt_resources(OAuth2BackendProps, ManagementProps) of
117-
{MgtResources} -> produce_auth_settings(MgtResources, ManagementProps);
117+
{MgtResources} ->
118+
Settings = produce_auth_settings(MgtResources, ManagementProps),
119+
rabbit_log:debug("authSettings: ~p", [Settings]),
120+
Settings;
118121
{} -> [{oauth_enabled, false}]
119122
end
120123
end.
@@ -137,18 +140,18 @@ filter_mgt_resource_servers_without_oauth_client_id_for_sp_initiated(MgtResource
137140
end.
138141

139142
filter_mgt_resource_servers_without_oauth_provider_url(MgtResourceServers) ->
140-
maps:filter(fun(_K1,V1) -> maps:is_key(oauth_provider_url, V1) end, MgtResourceServers).
143+
maps:filter(fun(_K1,V1) -> maps:is_key(oauth_provider_url, V1) end, MgtResourceServers).
141144

142145
ensure_oauth_resource_server_properties_are_binaries(Key, Value) ->
143-
case Key of
146+
case Key of
144147
oauth_authorization_endpoint_params -> Value;
145148
oauth_token_endpoint_params -> Value;
146149
_ -> to_binary(Value)
147150
end.
148151

149152
produce_auth_settings(MgtResourceServers, ManagementProps) ->
150-
ConvertValuesToBinary = fun(_K,V) -> [
151-
{K1, ensure_oauth_resource_server_properties_are_binaries(K1, V1)} || {K1,V1}
153+
ConvertValuesToBinary = fun(_K,V) -> [
154+
{K1, ensure_oauth_resource_server_properties_are_binaries(K1, V1)} || {K1,V1}
152155
<- maps:to_list(V)] end,
153156
FilteredMgtResourceServers = filter_mgt_resource_servers_without_oauth_provider_url(
154157
filter_mgt_resource_servers_without_oauth_client_id_for_sp_initiated(MgtResourceServers, ManagementProps)),
@@ -202,14 +205,14 @@ to_tuple(Key, Proplist) ->
202205

203206
to_tuple(Key, Proplist, ConvertFun, DefaultValue) ->
204207
case proplists:is_defined(Key, Proplist) of
205-
true ->
206-
{Key, case ConvertFun of
208+
true ->
209+
{Key, case ConvertFun of
207210
undefined -> proplists:get_value(Key, Proplist);
208211
_ -> ConvertFun(proplists:get_value(Key, Proplist))
209212
end
210213
};
211-
false ->
212-
case DefaultValue of
214+
false ->
215+
case DefaultValue of
213216
undefined -> {};
214217
_ -> {Key, proplists:get_value(Key, Proplist, DefaultValue)}
215218
end

deps/rabbitmq_management/test/config_schema_SUITE_data/rabbitmq_management.snippets

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -621,15 +621,23 @@
621621
management.oauth_client_id = rabbitmq_client_code
622622
management.oauth_client_secret = rabbitmq_client_secret
623623
management.oauth_scopes = openid profile rabbitmq.*
624+
management.oauth_authorization_endpoint_params.param1 = value1
625+
management.oauth_token_endpoint_params.param2 = value2
624626
management.oauth_initiated_logon_type = idp_initiated",
625627
[
626628
{rabbitmq_management, [
629+
{oauth_authorization_endpoint_params, [
630+
{"param1", <<"value1">>}
631+
]},
627632
{oauth_enabled, true},
628633
{oauth_provider_url, "http://localhost:8080"},
629634
{oauth_client_id, "rabbitmq_client_code"},
630635
{oauth_client_secret, "rabbitmq_client_secret"},
631636
{oauth_scopes, "openid profile rabbitmq.*"},
632-
{oauth_initiated_logon_type, idp_initiated}
637+
{oauth_initiated_logon_type, idp_initiated},
638+
{oauth_token_endpoint_params, [
639+
{"param2", <<"value2">>}
640+
]}
633641
]}
634642
], [rabbitmq_management]
635643
},
@@ -640,7 +648,9 @@
640648
management.oauth_resource_servers.1.label = One
641649
management.oauth_resource_servers.1.oauth_client_id = one
642650
management.oauth_resource_servers.1.oauth_scopes = openid profile rabbitmq.*
651+
management.oauth_resource_servers.1.oauth_token_endpoint_params.param2 = value2
643652
management.oauth_resource_servers.2.oauth_provider_url = http://two
653+
management.oauth_resource_servers.2.oauth_authorization_endpoint_params.param1 = value1
644654
management.oauth_resource_servers.2.id = resource-two
645655
management.oauth_resource_servers.2.oauth_client_id = two
646656
management.oauth_resource_servers.3.oauth_initiated_logon_type = idp_initiated
@@ -650,21 +660,28 @@
650660
{oauth_enabled, true},
651661
{oauth_resource_servers,
652662
#{
653-
<<"resource-one">> => [
663+
"3" => [
664+
{oauth_provider_url, "http://three"},
665+
{oauth_initiated_logon_type, idp_initiated},
666+
{id, "3"}
667+
],
668+
"resource-one" => [
669+
{oauth_token_endpoint_params, [
670+
{"param2", <<"value2">>}
671+
]},
654672
{oauth_scopes, "openid profile rabbitmq.*"},
655673
{oauth_client_id, "one"},
656-
{id, "resource-one"},
657674
{label, "One"},
675+
{id, "resource-one"},
658676
{oauth_provider_url, "http://one:8080"}
659677
],
660-
<<"resource-two">> => [
678+
"resource-two" => [
679+
{oauth_authorization_endpoint_params, [
680+
{"param1", <<"value1">>}
681+
]},
661682
{oauth_client_id, "two"},
662683
{id, "resource-two"},
663684
{oauth_provider_url, "http://two"}
664-
],
665-
<<"3">> => [
666-
{oauth_initiated_logon_type, idp_initiated},
667-
{oauth_provider_url, "http://three"}
668685
]
669686
}
670687
}

0 commit comments

Comments
 (0)