Skip to content

Commit 813b2d2

Browse files
Merge pull request #10624 from rabbitmq/fixes-10612
Fix issue #10612
2 parents c8031b5 + 80e64aa commit 813b2d2

File tree

10 files changed

+131
-46
lines changed

10 files changed

+131
-46
lines changed

deps/oauth2_client/BUILD.bazel

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,10 @@ rabbitmq_integration_suite(
125125
],
126126
)
127127

128+
129+
rabbitmq_suite(
130+
name = "unit_SUITE",
131+
size = "small",
132+
)
133+
128134
assert_suites()

deps/oauth2_client/app.bzl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,12 @@ def test_suite_beam_files(name = "test_suite_beam_files"):
8181
app_name = "oauth2_client",
8282
erlc_opts = "//:test_erlc_opts",
8383
)
84+
erlang_bytecode(
85+
name = "unit_SUITE_beam_files",
86+
testonly = True,
87+
srcs = ["test/unit_SUITE.erl"],
88+
outs = ["test/unit_SUITE.beam"],
89+
hdrs = ["include/oauth2_client.hrl"],
90+
app_name = "oauth2_client",
91+
erlc_opts = "//:test_erlc_opts",
92+
)

deps/oauth2_client/src/oauth2_client.erl

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
-module(oauth2_client).
88
-export([get_access_token/2,
99
refresh_access_token/2,
10-
get_oauth_provider/1,get_oauth_provider/2
10+
get_oauth_provider/1, get_oauth_provider/2,
11+
extract_ssl_options_as_list/1
1112
]).
1213

1314
-include("oauth2_client.hrl").
@@ -270,31 +271,46 @@ lookup_oauth_provider_from_keyconfig() ->
270271

271272
-spec extract_ssl_options_as_list(#{atom() => any()}) -> proplists:proplist().
272273
extract_ssl_options_as_list(Map) ->
273-
Verify = case maps:get(peer_verification, Map, verify_peer) of
274+
{Verify, CaCerts, CaCertFile} = case maps:get(peer_verification, Map, verify_peer) of
274275
verify_peer ->
275276
case maps:get(cacertfile, Map, undefined) of
276277
undefined ->
277278
case public_key:cacerts_get() of
278-
[] -> verify_none;
279-
_ -> verify_peer
279+
[] -> {verify_none, undefined, undefined};
280+
Certs -> {verify_peer, Certs, undefined}
280281
end;
281-
_ -> verify_peer
282+
CaCert -> {verify_peer, undefined, CaCert}
282283
end;
283-
verify_none -> verify_none
284+
verify_none -> {verify_none, undefined, undefined}
284285
end,
285286

286-
[ {verify, Verify},
287-
{cacertfile, maps:get(cacertfile, Map, "")},
288-
{depth, maps:get(depth, Map, 10)},
289-
{crl_check, maps:get(crl_check, Map, false)},
290-
{fail_if_no_peer_cert, maps:get(fail_if_no_peer_cert, Map, false)}
291-
] ++
292-
case maps:get(hostname_verification, Map, none) of
287+
[ {verify, Verify} ]
288+
++
289+
case Verify of
290+
verify_none -> [];
291+
_ ->
292+
[
293+
{depth, maps:get(depth, Map, 10)},
294+
{crl_check, maps:get(crl_check, Map, false)},
295+
{fail_if_no_peer_cert, maps:get(fail_if_no_peer_cert, Map, false)}
296+
]
297+
end
298+
++
299+
case Verify of
300+
verify_none -> [];
301+
_ ->
302+
case {CaCerts, CaCertFile} of
303+
{_, undefined} -> [{cacerts, CaCerts}];
304+
{undefined, _} -> [{cacertfile, CaCertFile}]
305+
end
306+
end
307+
++
308+
case maps:get(hostname_verification, Map, none) of
293309
wildcard ->
294310
[{customize_hostname_check, [{match_fun, public_key:pkix_verify_hostname_match_fun(https)}]}];
295311
none ->
296312
[]
297-
end.
313+
end.
298314

299315
lookup_oauth_provider_config(OAuth2ProviderId) ->
300316
case application:get_env(rabbitmq_auth_backend_oauth2, oauth_providers) of

deps/oauth2_client/test/system_SUITE.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ groups() ->
177177
ssl_connection_error,
178178
{group, with_all_oauth_provider_settings},
179179
{group, without_all_oauth_providers_settings}
180-
]}
180+
]}
181181
].
182182

183183
init_per_suite(Config) ->
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
%% This Source Code Form is subject to the terms of the Mozilla Public
2+
%% License, v. 2.0. If a copy of the MPL was not distributed with this
3+
%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
%%
5+
%% Copyright (c) 2007-2024 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
6+
%%
7+
8+
-module(unit_SUITE).
9+
10+
-include_lib("common_test/include/ct.hrl").
11+
-include_lib("eunit/include/eunit.hrl").
12+
13+
-include_lib("oauth2_client.hrl").
14+
-include_lib("public_key/include/public_key.hrl").
15+
16+
-compile(export_all).
17+
18+
19+
all() ->
20+
[
21+
{group, ssl_options}
22+
].
23+
24+
groups() ->
25+
[
26+
{ssl_options, [], [
27+
no_ssl_options_triggers_verify_peer,
28+
peer_verification_verify_none,
29+
peer_verification_verify_peer_with_cacertfile
30+
]}
31+
].
32+
33+
no_ssl_options_triggers_verify_peer(_) ->
34+
?assertMatch([
35+
{verify, verify_peer},
36+
{depth, 10},
37+
{crl_check,false},
38+
{fail_if_no_peer_cert,false},
39+
{cacerts, _CaCerts}
40+
], oauth2_client:extract_ssl_options_as_list(#{})).
41+
42+
peer_verification_verify_none(_) ->
43+
Expected1 = [
44+
{verify, verify_none}
45+
],
46+
?assertEqual(Expected1, oauth2_client:extract_ssl_options_as_list(#{peer_verification => verify_none})),
47+
48+
Expected2 = [
49+
{verify, verify_none}
50+
],
51+
?assertEqual(Expected2, oauth2_client:extract_ssl_options_as_list(#{
52+
peer_verification => verify_none,
53+
cacertfile => "/tmp"
54+
})).
55+
56+
57+
peer_verification_verify_peer_with_cacertfile(_) ->
58+
Expected = [
59+
{verify, verify_peer},
60+
{depth, 10},
61+
{crl_check,false},
62+
{fail_if_no_peer_cert,false},
63+
{cacertfile, "/tmp"}
64+
],
65+
?assertEqual(Expected, oauth2_client:extract_ssl_options_as_list(#{
66+
cacertfile => "/tmp",
67+
peer_verification => verify_peer
68+
})).

deps/rabbitmq_auth_backend_oauth2/src/uaa_jwks.erl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
-export([get/2, ssl_options/1]).
33

44
-spec get(string() | binary(), term()) -> {ok, term()} | {error, term()}.
5-
get(JwksUrl, KeyConfig) ->
6-
httpc:request(get, {JwksUrl, []}, [{ssl, ssl_options(KeyConfig)}, {timeout, 60000}], []).
5+
get(JwksUrl, SslOptions) ->
6+
Options = [{timeout, 60000}] ++ [{ssl, SslOptions}],
7+
rabbit_log:debug("get signing keys using options ~p", Options),
8+
httpc:request(get, {JwksUrl, []}, Options, []).
79

810
-spec ssl_options(term()) -> list().
911
ssl_options(KeyConfig) ->

deps/rabbitmq_auth_backend_oauth2/test/unit_SUITE.erl

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ all() ->
3737
test_post_process_payload_rich_auth_request_using_regular_expression_with_cluster,
3838
test_unsuccessful_access_with_a_token_that_uses_missing_scope_alias_in_scope_field,
3939
test_unsuccessful_access_with_a_token_that_uses_missing_scope_alias_in_extra_scope_source_field,
40-
test_default_ssl_options,
41-
test_default_ssl_options_with_cacertfile,
4240
test_username_from,
4341
{group, with_rabbitmq_node}
4442
].
@@ -125,10 +123,6 @@ init_per_testcase(test_post_process_payload_rich_auth_request_using_regular_expr
125123
application:set_env(rabbitmq_auth_backend_oauth2, resource_server_id, <<"rabbitmq-test">>),
126124
Config;
127125

128-
init_per_testcase(test_default_ssl_options_with_cacertfile, Config) ->
129-
application:set_env(rabbitmq_auth_backend_oauth2, key_config, [{ cacertfile, filename:join(["testca", "cacert.pem"]) }] ),
130-
Config;
131-
132126
init_per_testcase(_, Config) ->
133127
Config.
134128

@@ -137,10 +131,6 @@ end_per_testcase(test_post_process_token_payload_complex_claims, Config) ->
137131
application:set_env(rabbitmq_auth_backend_oauth2, resource_server_id, undefined),
138132
Config;
139133

140-
end_per_testcase(test_default_ssl_options_with_cacertfile, Config) ->
141-
application:set_env(rabbitmq_auth_backend_oauth2, key_config, undefined),
142-
Config;
143-
144134
end_per_testcase(_, Config) ->
145135
Config.
146136

@@ -1331,25 +1321,6 @@ test_validate_payload_when_verify_aud_false(_) ->
13311321
<<"scope">> => [<<"bar">>, <<"other.third">>]}},
13321322
rabbit_auth_backend_oauth2:validate_payload(?RESOURCE_SERVER_ID, WithAudWithUnknownResourceId, ?DEFAULT_SCOPE_PREFIX)).
13331323

1334-
test_default_ssl_options(_) ->
1335-
?assertEqual([
1336-
{verify, verify_none},
1337-
{depth, 10},
1338-
{fail_if_no_peer_cert, false},
1339-
{crl_check, false},
1340-
{crl_cache, {ssl_crl_cache, {internal, [{http, 10000}]}}}
1341-
], uaa_jwks:ssl_options(rabbit_oauth2_config:get_key_config())).
1342-
1343-
test_default_ssl_options_with_cacertfile(_) ->
1344-
?assertEqual([
1345-
{verify, verify_none},
1346-
{depth, 10},
1347-
{fail_if_no_peer_cert, false},
1348-
{crl_check, false},
1349-
{crl_cache, {ssl_crl_cache, {internal, [{http, 10000}]}}},
1350-
{cacertfile, filename:join(["testca", "cacert.pem"])}
1351-
], uaa_jwks:ssl_options(rabbit_oauth2_config:get_key_config())).
1352-
13531324
%%
13541325
%% Helpers
13551326
%%

deps/rabbitmq_management/selenium/full-suite-management-ui

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ authnz-mgt/oauth-idp-initiated-with-uaa-and-prefix.sh
1010
authnz-mgt/oauth-idp-initiated-with-uaa-via-proxy.sh
1111
authnz-mgt/oauth-idp-initiated-with-uaa.sh
1212
authnz-mgt/oauth-with-keycloak.sh
13+
authnz-mgt/oauth-with-keycloak-with-verify-none.sh
1314
authnz-mgt/oauth-with-uaa-and-mgt-prefix.sh
1415
authnz-mgt/oauth-with-uaa-down-but-with-basic-auth.sh
1516
authnz-mgt/oauth-with-uaa-down.sh
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
SCRIPT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4+
5+
TEST_CASES_PATH=/oauth/with-sp-initiated
6+
TEST_CONFIG_PATH=/oauth
7+
PROFILES="keycloak keycloak-verify-none-oauth-provider keycloak-mgt-oauth-provider tls"
8+
9+
source $SCRIPT/../../bin/suite_template $@
10+
runWith keycloak
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
auth_oauth2.issuer = ${OAUTH_PROVIDER_URL}
2+
auth_oauth2.https.peer_verification = verify_none

0 commit comments

Comments
 (0)