Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 017354a

Browse files
Verify Azure AD does not require client_secret
remove oauth_client_secret add tls generation for azure mode
1 parent 5b2ccb2 commit 017354a

File tree

10 files changed

+71
-39
lines changed

10 files changed

+71
-39
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ conf/asymmetric_key/uaa.yml
44
conf/symmetric_key/uaa.yml
55
conf/azure/*
66
bin/azure/.srl
7+
bin/tls-gen
78
!conf/azure/rabbitmq.config
89
plugin
910
rabbitmq-auth-backend-oauth2-*

README.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,18 @@ If you want to understand the details of how to configure RabbitMQ with Oauth2 g
5656

5757
## OAuth2 plugin in action
5858

59-
In order see the OAuth2 plugin in action we need an OAuth2 **Authorization server** running and RabbitMQ server configured accordingly. To get up and running quickly, we are going to use UAA as Authorization Server. In the next section, we
60-
will see how to set up UAA and RabbitMQ. If you are new to OAuth2, it is a good starting point. If you already know OAuth2
61-
and you want to learn how to configure RabbitMQ to talk to one of Oauth2 server tested on this tutorial, you can jump
62-
straight to them. They are [KeyCloak](use-cases/keycloak.md), [https://auth0.com/](use-cases/auth0.md) and [Azure Active Directory](use-cases/azure.md) in addition to UAA which we will use it in the next sections.
59+
In order see the [rabbitmq-auth-backend-oauth2](https://github.com/rabbitmq/rabbitmq-server/tree/main/deps/rabbitmq_auth_backend_oauth2) plugin in action we need an OAuth 2.0 **Authorization server** running and RabbitMQ server configured accordingly. To get up and running quickly, we are going to use UAA as Authorization Server. In the next section, we will see how to set up UAA and RabbitMQ. If you are new to OAuth 2.0, it is a good starting point. If you already know OAuth 2.0 and you want to learn how to configure RabbitMQ to talk to one of OAuth 2.0 server tested on this tutorial, you can jump straight to them. They are [KeyCloak](use-cases/keycloak.md), [https://auth0.com/](use-cases/auth0.md) and [Azure Active Directory](use-cases/azure.md) in addition to UAA which we will use it in the next sections.
6360

6461

6562
### Set up UAA and RabbitMQ
6663

67-
There are two ways to set up OAuth2 in RabbitMQ. One uses symmetrical signing keys. And the other uses
68-
asymmetrical signing keys. The Authorization server is who digitally signs the JWT tokens and RabbitMQ
69-
has to be configured to validate any of the two types of digital signatures.
64+
RabbitMQ support two types of two signing keys used to digitally sign the JWT tokens.
65+
The two types are **symmetrical** and **asymmetrical** signing keys. The Authorization server is who digitally signs the JWT tokens and RabbitMQ has to be configured to validate any of the two types of digital signatures.
7066

71-
Given that asymmetrical keys is the most widely used option, we are going to focus on how to
67+
Given that asymmetrical keys are the most widely used option, we are going to focus on how to
7268
configure RabbitMQ with them.
7369

74-
#### Use Asymmetrical digital singing keys
70+
#### Use Asymmetrical digital signing keys
7571

7672
Run the following 2 commands to get the environment ready to see Oauth2 plugin in action:
7773

@@ -86,6 +82,16 @@ The Management UI can be configured with one of these two login modes:
8682
* [Service-Provider initiated logon](#service-provider-initiated-logon) - This is the default and traditional OAuth 2.0 logon mode. The user comes to the Management UI and clicks on the button "Click here to logon" which initiates the logon. The logon process starts in RabbitMQ, the Service Provider.
8783
* [Identity-Provider initiated logon](#identity-provider-initiated-logon) - This is a logon mode meant for web portals. Users navigate to RabbitMQ with a token already obtained by the web portal on behalf of the user.
8884

85+
### Supported OAuth 2.0 flow
86+
87+
Since RabbitMQ 3.10 the Management UI uses *Authorization Code flow with PKCE**. Because RabbitMQ is a single-page
88+
web application, it cannot safely store credentials such as the `client_id` and `client_secret` required by
89+
RabbitMQ to authenticate with the Authorization Server in order to get a token for the end-user. Therefore, we
90+
should configure the RabbitMQ OAuth client in the Authorization Server so that it does not require `client_secret`.
91+
This type of OAuth clients/applications are known as **public** or **non-confidential**. In UAA they are configured as `allowpublic: true`.
92+
93+
Nevertheless, should your Authorization Server require a `client_secret` , we can configure it via `management.oauth_client_secret`.
94+
8995
### Service-Provider initiated logon
9096

9197
The first time an end user arrives to the management ui (`1`), The user clicks on the button `Click here to login` and it is redirected (`2`) to UAA to authenticate. Once they successfully authenticate with UAA, the user is redirected back (`3.`) to RabbitMQ with a valid JWT token. RabbitMQ validates it and identifies the user and extracts its permissions from the JWT token.
@@ -119,14 +125,16 @@ To configure RabbitMQ Management UI with OAuth 2.0 we need the following configu
119125
{rabbitmq_management, [
120126
{oauth_enabled, true},
121127
{oauth_client_id, "rabbit_client_code"},
122-
{oauth_client_secret, "rabbit_client_code"},
123128
{oauth_provider_url, "http://localhost:8080"},
124129
...
125130
]},
126131
```
127132

128133
### Identity-Provider initiated logon
129134

135+
**Note**: **This feature has not been released yet. It is only available in the development docker image
136+
pivotalrabbitmq/rabbitmq:oidc_idp_initiated_login-otp-max-bazel **
137+
130138
When RabbitMQ is offered as a service from a web portal, it is more convenient to navigate to RabbitMQ Management UI with a single click. The web portal is responsible for getting a token before taking the user to the RabbitMQ Management UI web page.
131139

132140
```
@@ -145,7 +153,6 @@ By default, RabbitMQ Management UI is configured with service-provider initiated
145153
{rabbitmq_management, [
146154
{oauth_enabled, true},
147155
{oauth_client_id, "rabbit_client_code"},
148-
{oauth_client_secret, "rabbit_client_code"},
149156
{oauth_provider_url, "http://localhost:8080"},
150157
{oauth_initiated_logon_type, idp_initiated},
151158
...
@@ -649,7 +656,6 @@ authenticate users with UAA and the URL of UAA (`http://localhost:8080/uaa`)
649656
{enable_uaa, true},
650657
{oauth_enabled, true},
651658
{oauth_client_id, "rabbit_client_code"},
652-
{oauth_client_secret, "rabbit_client_code"},
653659
{oauth_provider_url, "http://uaa:8080/uaa"}
654660
]},
655661
].

bin/deploy-rabbit

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,48 @@ CONFIG=${CONFIG:-rabbitmq.config}
88
IMAGE_TAG=${IMAGE_TAG:-3.11}
99
IMAGE=${IMAGE:-rabbitmq}
1010

11-
if [ "${MODE}" == "azure" ]; then
12-
EXTRA_PORTS="-p 15671:15671"
13-
EXTRA_MOUNTS="-v $SCRIPT/../conf/${MODE}/rabbitmq-ca.crt:/etc/rabbitmq/rabbitmq-ca.crt \
14-
-v $SCRIPT/../conf/${MODE}/rabbitmq.key:/etc/rabbitmq/rabbitmq.key \
15-
-v $SCRIPT/../conf/${MODE}/rabbitmq.crt:/etc/rabbitmq/rabbitmq.crt"
16-
fi
17-
18-
docker network inspect rabbitmq_net >/dev/null 2>&1 || docker network create rabbitmq_net
19-
docker rm -f rabbitmq 2>/dev/null || echo "rabbitmq was not running"
20-
echo "running RabbitMQ with Idp $MODE and configuration file conf/$MODE/$CONFIG"
21-
docker run -d --name rabbitmq --net rabbitmq_net \
22-
-p 15672:15672 -p 5672:5672 ${EXTRA_PORTS}\
23-
-v ${SCRIPT}/../conf/${MODE}/${CONFIG}:/etc/rabbitmq/rabbitmq.config:ro \
24-
-v ${SCRIPT}/../conf/enabled_plugins:/etc/rabbitmq/enabled_plugins \
25-
-v ${SCRIPT}/../conf:/conf ${EXTRA_MOUNTS} ${IMAGE}:${IMAGE_TAG}
11+
function generate-ca-server-client-kpi {
12+
NAME=$1
13+
14+
if [ -d "$NAME" ]; then
15+
echo "SSL Certificates already present under $NAME. Skip SSL generation"
16+
return
17+
fi
18+
19+
if [ ! -d "$SCRIPT/tls-gen" ]; then
20+
git clone https://github.com/michaelklishin/tls-gen $SCRIPT/tls-gen
21+
fi
22+
23+
echo "Generating CA and Server PKI under $NAMER ..."
24+
mkdir -p $NAME
25+
cp -r $SCRIPT/tls-gen/* $NAME
26+
27+
CUR_DIR=$(pwd)
28+
cd $NAME/basic
29+
make CN=localhost
30+
make PASSWORD=$PASSWORD
31+
make verify
32+
make info
33+
cd $CUR_DIR
34+
}
35+
36+
function deploy {
37+
if [ "${MODE}" == "azure" ]; then
38+
generate-ca-server-client-kpi $SCRIPT/../conf/${MODE}/certs
39+
EXTRA_PORTS="-p 15671:15671"
40+
EXTRA_MOUNTS="-v $SCRIPT/../conf/${MODE}/certs/basic/testca/cacert.pem:/etc/rabbitmq/rabbitmq-ca.crt \
41+
-v $SCRIPT/../conf/${MODE}/certs/basic/server_localhost/key.pem:/etc/rabbitmq/rabbitmq.key \
42+
-v $SCRIPT/../conf/${MODE}/certs/basic/server_localhost/cert.pem:/etc/rabbitmq/rabbitmq.crt"
43+
fi
44+
45+
docker network inspect rabbitmq_net >/dev/null 2>&1 || docker network create rabbitmq_net
46+
docker rm -f rabbitmq 2>/dev/null || echo "rabbitmq was not running"
47+
echo "running RabbitMQ with Idp $MODE and configuration file conf/$MODE/$CONFIG"
48+
docker run -d --name rabbitmq --net rabbitmq_net \
49+
-p 15672:15672 -p 5672:5672 ${EXTRA_PORTS}\
50+
-v ${SCRIPT}/../conf/${MODE}/${CONFIG}:/etc/rabbitmq/rabbitmq.config:ro \
51+
-v ${SCRIPT}/../conf/enabled_plugins:/etc/rabbitmq/enabled_plugins \
52+
-v ${SCRIPT}/../conf:/conf ${EXTRA_MOUNTS} ${IMAGE}:${IMAGE_TAG}
53+
}
54+
55+
deploy

conf/auth0/rabbitmq.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{rabbitmq_management, [
66
{oauth_enabled, true},
77
{oauth_client_id, "REPLACE"},
8-
{oauth_client_secret, "REPLACE"},
8+
% {oauth_client_secret, "REPLACE"},
99
{oauth_scopes, "openid profile rabbitmq.tag:administrator"},
1010
{oauth_provider_url, "https://dev-prbc0gw4.us.auth0.com"}
1111
]},

conf/azure/rabbitmq.config

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@
2020
]}
2121
]},
2222
{oauth_enabled, true},
23-
{oauth_client_id, "PUT YOUR AZURE AD APPLICATION ID"},
24-
{oauth_client_secret, "PUT YOUR AZURE AD APPLICATION SECRET"},
25-
{oauth_provider_url, "https://login.microsoftonline.com/AZURE_AD_TENANT_ID"}
23+
{oauth_client_id, "0e4305ff-3df1-4695-b2c7-ef804cf9c105"},
24+
%{oauth_client_secret, "PUT YOUR AZURE AD APPLICATION SECRET"},
25+
{oauth_provider_url, "https://login.microsoftonline.com/b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0"}
2626

2727
]},
2828
{rabbitmq_auth_backend_oauth2, [
29-
{resource_server_id, <<"PUT YOUR AZURE AD APPLICATION ID">>},
29+
{resource_server_id, <<"0e4305ff-3df1-4695-b2c7-ef804cf9c105">>},
3030
{extra_scopes_source, <<"roles">>},
3131
{key_config, [
32-
{jwks_url, <<"PUT YOUR AZURE AD JWKS URI VALUE">>}
32+
{jwks_url, <<"https://login.microsoftonline.com/b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0/discovery/v2.0/keys">>}
3333
]}
3434
]}
3535
].

conf/uaa/rabbitmq-for-rar-tokens.config

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
{enable_uaa, true},
88
{oauth_enabled, true},
99
{oauth_client_id, "rabbit_client_code"},
10-
{oauth_client_secret, "rabbit_client_code"},
1110
{oauth_provider_url, "http://uaa:8080/uaa"}
1211
]},
1312
{rabbitmq_auth_backend_oauth2, [

conf/uaa/rabbitmq-scope-aliases-and-extra-scope.config

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
{rabbitmq_management, [
66
{oauth_enabled, true},
77
{oauth_client_id, "rabbit_client_code"},
8-
{oauth_client_secret, "rabbit_client_code"},
98
{oauth_provider_url, "http://localhost:8080/uaa"}
109
]},
1110
{rabbitmq_auth_backend_oauth2, [

conf/uaa/rabbitmq-scope-aliases.config

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
{rabbitmq_management, [
66
{oauth_enabled, true},
77
{oauth_client_id, "rabbit_client_code"},
8-
{oauth_client_secret, "rabbit_client_code"},
98
{oauth_provider_url, "http://localhost:8080/uaa"}
109
]},
1110
{rabbitmq_auth_backend_oauth2, [

conf/uaa/rabbitmq.config

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
{auth_backends, [rabbit_auth_backend_oauth2]}
44
]},
55
{rabbitmq_management, [
6-
%% {login_session_timeout, 3},
76
{enable_uaa, true},
87
{oauth_enabled, true},
98
{oauth_client_id, "rabbit_client_code"},
10-
{oauth_client_secret, "rabbit_client_code"},
119
{oauth_provider_url, "http://localhost:8080/"}
1210
]},
1311
{rabbitmq_auth_backend_oauth2, [

conf/uaa/uaa.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ oauth:
133133
scope: rabbitmq.*,openid,profile
134134
authorities: uaa.resource,rabbitmq
135135
redirect-uri: http://localhost:15672
136-
136+
allowpublic: true
137137
mgt_api_client_2:
138138
id: mgt_api_client_2
139139
secret: mgt_api_client_2

0 commit comments

Comments
 (0)