Skip to content

Commit d622524

Browse files
Merge pull request #2056 from rabbitmq/switch-to-entra-id-v2
(Mostly) 4.1: Document optional OAuth 2.0 settings required for each identity provider
2 parents a2a1467 + f7a7fb3 commit d622524

File tree

21 files changed

+398
-243
lines changed

21 files changed

+398
-243
lines changed

docs/management/index.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ To configure OAuth 2.0 in the management UI you need a [minimum configuration](#
375375
* [Allow Basic and OAuth 2 authentication for management HTTP API](#allow-basic-auth-for-http-api)
376376
* [Allow Basic and OAuth 2 authentication for management UI](#allow-basic-auth-for-mgt-ui)
377377
* [Logging out of the management UI](#about-logout-workflow)
378+
* [Configure extra parameters for authorization and token endpoints](#extra-endpoint-params)
378379
* [Special attention to CSP header `connect-src`](#csp-header)
379380
* [Identity-Provider initiated logon](#idp-initiated-logon)
380381
* [Support multiple OAuth 2.0 resources](#support-multiple-resources)
@@ -403,10 +404,14 @@ management.oauth_scopes = <SPACE-SEPARATED LIST OF SCOPES. See below>
403404
- `oauth_scopes` is a mandatory field which must be set at all times except in the case when OAuth providers automatically grant scopes associated to the `oauth_client_id`. `oauth_scopes` is a list of space-separated strings that indicate which permissions the application is requesting. Most OAuth providers only issue tokens with the scopes requested during the user authentication. RabbitMQ sends this field along with its `oauth_client_id` during the user authentication. If this field is not set, RabbitMQ defaults to `openid profile`.
404405

405406
Given above configuration, when a user visits the management UI, the following two events take place:
406-
1. RabbitMQ uses the URL found in `auth_oauth2.issuer` followed by the path `/.well-known/openid-configuration` to download the OpenID Provider configuration. It contains information about other endpoints such as the `jwks_uri` (used to download the keys to validate the token's signature) or the `token_endpoint`.
407+
1. RabbitMQ uses the URL found in `auth_oauth2.issuer` to download the OpenID Provider configuration. Learn more in the [OAuth 2.0 guide](./oauth2#discovery-endpoint-params)
407408

408409
:::warning
409-
If RabbitMQ cannot download the OpenID provider configuration, it shows an error message and OAuth 2.0 authentication is disabled in the management UI.
410+
If RabbitMQ cannot download the OpenID provider configuration, it shows an error message and the OAuth 2.0 authentication option will be disabled in the management UI
411+
:::
412+
413+
:::tip
414+
If you used to configure `management.oauth_metadata_url` because your provider did not use the standard OpenId Discovery endpoint's path, since RabbitMQ 4.1 you should instead configure the correct path as it is explained [here](./oauth2#discovery-endpoint-params).
410415
:::
411416

412417
2. RabbitMQ displays a button with the label "Click here to login". When the user clicks on the button, the management UI initiates the OAuth 2.0 Authorization Code Flow, which redirects the user to the identity provider to authenticate and get a token.
@@ -505,6 +510,30 @@ RabbitMQ 3.13.1 and earlier versions require the [OpenId Connect Discovery endpo
505510
There are other two additional scenarios which can trigger a logout. One scenario occurs when the OAuth Token expires. Although RabbitMQ renews the token in the background before it expires, if the token expires, the user is logged out.
506511
The second scenario is when the management UI session exceeds the maximum allowed time configured on the [Login Session Timeout](#login-session-timeout).
507512

513+
### Configure Extra URI Parameters for Authorization and Token Endpoints {#extra-endpoint-params}
514+
515+
Some OAuth 2.0 providers require additional URI parameters to be included into the request sent to the **authorization endpoint** and/or to the **token endpoint**.
516+
These parameters are vendor- or IDP installation-specific. The Management UI already sends all the parameters required by the OAuth 2.0 Authorization Code flow.
517+
518+
In the followingexample an extra URI parameter called `audience` is added for both the **authorization** and **token** endpoints:
519+
520+
```ini
521+
management.oauth_authorization_endpoint_params.audience = some-audience-id
522+
523+
management.oauth_token_endpoint_params.audience = some-audience-id
524+
```
525+
526+
Multiple parameters can be configured like so:
527+
528+
```ini
529+
management.oauth_authorization_endpoint_params.audience = some-audience-id
530+
management.oauth_authorization_endpoint_params.example = example-value
531+
532+
management.oauth_token_endpoint_params.audience = some-audience-id
533+
management.oauth_token_endpoint_params.other = other-value
534+
```
535+
536+
508537
### Special attention to CSP header `connect-src` {#csp-header}
509538

510539
To support the OAuth 2.0 protocol, RabbitMQ makes asynchronous REST calls to the [OpenId Connect Discovery endpoint](https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfigurationRequest). If you override the default [CSP headers](#csp), you have to make sure that the `connect-src` CSP directive whitelists the [OpenId Connect Discovery endpoint](https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfigurationRequest).
@@ -600,6 +629,18 @@ the following settings:
600629
- `resource` : `rabbit_prod`
601630
- `scopes` : `openid rabbitmq.tag:management rabbitmq.read:*/*`
602631

632+
### Configure Extra URI Parameters for Authorization and Token Endpoints {#extra-endpoint-params}
633+
634+
Some OAuth 2.0 providers require additional URI parameters to be included into the request sent to the **authorization endpoint** and/or to the **token endpoint**.
635+
These parameters are vendor- or IDP installation-specific. The Management UI already sends all the parameters required by the OAuth 2.0 Authorization Code flow.
636+
637+
The following example sets an extra URI parameter called `audience` for both endpoints for the resource `some-resource-id`:
638+
639+
```ini
640+
management.oauth_resource_servers.2.id = some-resource-id
641+
management.oauth_resource_servers.2.oauth_authorization_endpoint_params.audience = some-resource-id
642+
management.oauth_resource_servers.2.oauth_token_endpoint_params.audience = some-resource-id
643+
```
603644

604645
#### Optionally do not expose some resources in the management UI
605646

docs/oauth2-examples-auth0.md

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Use https://auth0.com/ as Auth 2.0 server
2+
title: Use auth0.com as OAuth 2.0 Server
33
displayed_sidebar: docsSidebar
44
---
55
<!--
@@ -19,26 +19,26 @@ See the License for the specific language governing permissions and
1919
limitations under the License.
2020
-->
2121

22-
# Use https://auth0.com/ as OAuth 2.0 server
22+
# Use [auth0.com](https://auth0.com) as OAuth 2.0 server
2323

2424
This guide explains how to set up OAuth 2.0 for RabbitMQ
2525
and Auth0 as Authorization Server using the following flows:
2626

2727
* Access [management UI](./management/) via a browser
28-
* Access management rest api
28+
* Access management HTTP API
2929
* Application authentication and authorization
3030

3131
## Prerequisites to follow this guide
3232

33-
* Have an account in https://auth0.com/.
33+
* Have an [Auth0](https://auth0.com/) account
3434
* Docker
3535
* A local clone of a [GitHub repository](https://github.com/rabbitmq/rabbitmq-oauth2-tutorial) that contains all the configuration files and scripts used on this example
3636

3737
## Create RabbitMQ API
3838

3939
In Auth0, resources are mapped to Application APIs.
4040

41-
1. Once you have logged onto your account in https://auth0.com/, go to **dashboard > Applications > APIs > Create an API**.
41+
1. After logging into the Auth0 account, go to **dashboard > Applications > APIs > Create an API**.
4242
2. Give it the name `rabbitmq`. The important thing here is the `identifier` which must have the name of the *resource_server_id* we configured in RabbitMQ. This `identifier` goes into the `audience` JWT field. In our case, it is called `rabbitmq`.
4343
3. Choose `RS256` as the signing algorithm.
4444
4. Enable **RBAC**.
@@ -69,10 +69,9 @@ of the end user.
6969
In the settings, choose:
7070

7171
* Application type : `Single Page applications`
72-
* Token Endpoint Authentication Method: `None`
73-
* Allowed Callback URLs: `http://localhost:15672/js/oidc-oauth/login-callback.html`
74-
* Allowed Web Origins: `http://localhost:15672`
75-
* Allowed Origins (CORS): `http://localhost:15672`
72+
* Allowed Callback URLs: `https://localhost:15671/js/oidc-oauth/login-callback.html`
73+
* Allowed Web Origins: `https://localhost:15671`
74+
* Allowed Origins (CORS): `https://localhost:15671`
7675

7776

7877
## Create a User for Management UI Access
@@ -100,8 +99,26 @@ To configure RabbitMQ you need to gather the following information from Auth0:
10099
4. And take note of the *Domain* value
101100
5. Use the last values in *Client ID* and *Domain* fields in the RabbitMQ configuration file
102101

103-
Edit the configuration file [conf/auth0/rabbitmq.conf](https://github.com/rabbitmq/rabbitmq-oauth2-tutorial/blob/main/conf/auth0/rabbitmq.conf) and replace `{CLIENT_ID}` and `{DOMAIN}` with the
104-
values you gathered above.
102+
Copy [conf/auth0/rabbitmq.conf.tmpl](https://github.com/rabbitmq/rabbitmq-oauth2-tutorial/blob/main/conf/auth0/rabbitmq.conf.tmpl) as `rabbitmq.conf`.
103+
It must be in same folder as `rabbitmq.conf.tmpl`.
104+
105+
Edit `rabbitmq.conf` and proceed as follows:
106+
107+
1. Replace `{Client ID}` with the values you gathered above.
108+
2. Same for `{Domain}`
109+
110+
:::important
111+
112+
Starting with RabbitMQ 4.1.x, you must configure RabbitMQ to include a URI parameter
113+
called `audience` whose value matches the value of `auth_oauth2.resource_server_id`.
114+
115+
Earlier RabbitMQ versions always sent this URI parameter. If this additional URI parameter is not configured,
116+
Auth0 will consider the token invalid and RabbitMQ will display "No authorized" for error.
117+
118+
These [two configuration lines](https://github.com/rabbitmq/rabbitmq-oauth2-tutorial/blob/main/conf/auth0/rabbitmq.conf.tmpl#L8-L9)
119+
configure the `audience` parameter with the value `rabbitmq`.
120+
121+
:::
105122

106123
## Start RabbitMQ
107124

@@ -114,7 +131,7 @@ make start-rabbitmq
114131

115132
## Verify Management UI flows
116133

117-
1. Go to management UI `http://localhost:15672`.
134+
1. Go to management UI `https://localhost:15671`.
118135
2. Click on the single button, authenticate with your secondary Auth0 user. You should be redirected back to the management UI.
119136

120137
**Auth0** issues an access token like this one below. It has in the `scope` claim

docs/oauth2-examples-entra-id/index.md

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ limitations under the License.
2424
This guide explains how to set up OAuth 2.0 for RabbitMQ
2525
and Microsoft Entra ID as Authorization Server using the following flows:
2626

27-
* Access the management UI via a browser
27+
* Access the management UI via a browser using v2.0 api version
28+
2829

2930
## Prerequisites to follow this guide
3031

@@ -48,7 +49,7 @@ When using **Entra ID as OAuth 2.0 server**, your client app (in our case Rabbit
4849
4. In the **Register an application** pane, provide the following information:
4950

5051
* **Name**: the name you would like to give to your application (ex: *rabbitmq-oauth2*)
51-
* **Supported Account Types**: select **Accounts in this organizational directory only (Default Directory only - Single tenant)** (you can choose other options if you want to enlarge the audience of your app)
52+
* **Supported Account Types**: select **Accounts in this organizational directory only (Default Directory only - Single tenant)** (this guide will focus on this option for simplicity)
5253
* On the **Select a platform** drop-down list, select **Single-page application (SPA)**
5354
* Configure the **Redirect URI** to: `https://localhost:15671/js/oidc-oauth/login-callback.html`
5455

@@ -65,16 +66,8 @@ When using **Entra ID as OAuth 2.0 server**, your client app (in our case Rabbit
6566

6667
Note the following values, as you will need it later to configure the `rabbitmq_auth_backend_oauth2` on RabbitMQ side:
6768

68-
* Directory (tenant ID)
69-
* Application (client) ID
70-
71-
6. Click on the **Endpoints** tab if it is visible.
72-
7. On the right pane that has just opened, copy the value of **OpenID Connect metadata document** (ex: `https://login.microsoftonline.com/{TENANT_ID}/v2.0/.well-known/openid-configuration`) and open it in your browser.
73-
74-
Note the value of the `jwks_uri` key (ex: `https://login.microsoftonline.com/{TENANT_ID}/discovery/v2.0/keys`), as you will also need it later to configure the `rabbitmq_auth_backend_oauth2` on RabbitMQ side.
75-
76-
![Entra ID JWKS URI](./entra-id-jwks-uri.png)
77-
8. If the **Endpoints** tab is not visible,
69+
* **Directory (tenant ID)**
70+
* **Application (client) ID**
7871

7972

8073
## Create OAuth 2.0 roles for your app
@@ -97,18 +90,12 @@ To learn more about roles in Entra ID, see [Entra ID documentation](https://docs
9790

9891
2. Then, click on **Create App Role** to create an OAuth 2.0 role that will be used to give access to the RabbitMQ Management UI.
9992

100-
:::info
101-
102-
To learn more about how permissions are managed when RabbitMQ is used together with OAuth 2.0,
103-
see [this portion of the OAuth 2 tutorial](https://github.com/rabbitmq/rabbitmq-oauth2-tutorial#about-permissions)
104-
105-
:::
10693

10794
3. On the right menu that has just opened, provide the requested information:
10895

10996
* **Display Name**: the name you want to give to the role (ex: *Management UI Admin*)
11097
* **Allowed member types**: Both (Users/Groups + Applications)
111-
* **Value**: `Application_ID.tag:administrator` (where *Application_ID* is the value of the *Application (client) ID* noted earlier in this tutorial)
98+
* **Value**: `{Application_ID}.tag:administrator` (where *Application_ID* is the value of the *Application (client) ID* noted earlier in this tutorial)
11299
* **Description**: briefly describe what this role aims to (here just to give admin access to the RabbitMQ Management UI)
113100
* **Do you want to enable this app role**: `yes` (check the box)
114101

@@ -122,7 +109,7 @@ see [this portion of the OAuth 2 tutorial](https://github.com/rabbitmq/rabbitmq-
122109

123110
* **Display Name**: the name you want to give to the role (ex: *Configure All Vhosts*)
124111
* **Allowed member types**: Both (Users/Groups + Applications)
125-
* **Value**: `Application_ID.configure:*/*` (where *Application_ID* is the value of the *Application (client) ID* noted earlier in this tutorial)
112+
* **Value**: `{Application_ID}.configure:*/*` (where *Application_ID* is the value of the *Application (client) ID* noted earlier in this tutorial)
126113
* **Description**: briefly describe what this role aims to (here to give permissions to configure all resources on all the vhosts available on the RabbitMQ instance)
127114
* **Do you want to enable this app role**: `yes` (check the box)
128115

@@ -159,38 +146,57 @@ Now that some roles have been created for your application, you still need to as
159146

160147
9. Repeat the operations for all the roles you want to assign.
161148

162-
## Configure Custom Signing Keys
149+
## Create a Scope for Management UI Access
163150

164-
It is optional to create a signing key for your application. If you create one though, you must append an `appid` query parameter containing the *app ID* to the `jwks_uri`. Otherwise, the standard jwks_uri endpoint will not include the custom signing key and RabbitMQ will not find the signing key to validate the token's signature.
151+
There is one last configuration step required. Without this step, the `access_token` returned
152+
by **Entra ID** won't be useable with RabbitMQ. More specifically, RabbitMQ will not be able to validate its signature because the `access_token` is meant for Microsoft resources
165153

166-
For example, given your application id, `{my-app-id}` and your tenant `{tenant}`, the OIDC discovery endpoint uri would be `https://login.microsoftonline.com/{tenant}/.well-known/openid-configuration?appid={my-app-id}`. The returned payload contains the `jwks_uri` attribute whose value is something like `https://login.microsoftonline.com/{tenant}/discovery/keys?appid=<my-app-idp>`. RabbitMQ should be configured with that `jwks_uri` value.
154+
Therefore, create a new scope associated with the application registered above to be used for RabbitMQ management UI.
155+
To do so:
167156

157+
1. Go to **App registrations**
158+
2. Click on your application
159+
3. Go to **Manage** option on the left menu and choose the option **Expose an API**
160+
4. Click on **Add a scope**
161+
5. Enter a name, eg. `management-ui`. Enter the same name for **Admin consent display name** and a description and save it
162+
7. The scope is named `api://{Application (client) ID}/{scope_name}`
168163

169-
## Configure RabbitMQ to Use Entra ID as OAuth 2.0 Authentication Backend
164+
This scope will be used further below in this guide.
170165

171-
The configuration on Entra ID side is done. Next, configure RabbitMQ to use these resources.
172166

173-
[rabbitmq.conf](https://github.com/rabbitmq/rabbitmq-oauth2-tutorial/tree/main/conf/entra/rabbitmq.conf) is a sample RabbitMQ configuration to **enable Entra ID as OAuth 2.0 authentication backend** for the RabbitMQ Management UI.
167+
## Configure Custom Signing Keys
174168

175-
Update it with the following values:
169+
Creating a signing key for the application is optional. If a custom key is created, RabbitMQ must be configured accordingly.
170+
In the example below, replace `{Application(client) ID}` with the actual *Application(client) ID*.
176171

177-
* **Tenant ID** associated to the app that you registered in Entra ID
178-
* **Application ID** associated to the app that you registered in Entra ID
179-
* Value of the **jwks_uri** key from `https://login.microsoftonline.com/{TENANT_ID}/v2.0/.well-known/openid-configuration`
172+
Without this bit of configuration, the standard `jwks_uri` endpoint will not include the custom signing key
173+
and therefore RabbitMQ will not find the necessary signing key to validate the token's signature.
180174

181175
```ini
182-
auth_backends.1 = rabbit_auth_backend_oauth2
183-
auth_backends.2 = rabbit_auth_backend_internal
176+
auth_oauth2.discovery_endpoint_params.appid = {Application(client) ID}
177+
```
178+
179+
For more information, check out Microsoft Entra documentation about [configuring custom signing keys](https://learn.microsoft.com/en-us/entra/identity-platform/jwt-claims-customization#validate-token-signing-key).
180+
181+
182+
## Configure RabbitMQ to Use Entra ID as OAuth 2.0 Authentication Backend
184183

185-
management.oauth_enabled = true
186-
management.oauth_client_id = {PUT YOUR AZURE AD APPLICATION ID}
187-
management.oauth_provider_url = https://login.microsoftonline.com/{YOUR_ENTRA_ID_TENANT_ID}
184+
The configuration on **Entra ID** side is done. Next, configure RabbitMQ to use these resources.
188185

189-
auth_oauth2.resource_server_id = {PUT YOUR AZURE AD APPLICATION ID}
190-
auth_oauth2.additional_scopes_key = roles
191-
auth_oauth2.jwks_url = {PUT YOUR ENTRA ID JWKS URI VALUE}
186+
Clone [rabbitmq.conf.tmpl](https://github.com/rabbitmq/rabbitmq-oauth2-tutorial/tree/main/conf/entra/rabbitmq.conf.tmpl) from the tutorial repository
187+
to `rabbitmq.conf`. It must be in the same directory as `rabbitmq.conf.tmpl`.
188+
189+
Edit the new `rabbitmq.conf` file and proceed as follows:
190+
191+
1. Replace `{Directory (tenant) ID}` with the value gathered earlier as **Application (client) ID**
192+
2. Replace `{Application(client) ID}` with the value gathered as **Application (client) ID**
193+
3. If you decide to configure your application with custom signing(s), you need to uncomment the following configuration line. This is required otherwise the `jwks_uri` endpoint announced by the OpenID Discovery endpoint does not contain applications' custom signing keys.
194+
195+
```ini
196+
#auth_oauth2.discovery_endpoint_params.appid = {Application(client) ID}
192197
```
193198

199+
194200
## Start RabbitMQ
195201

196202
Run the following commands to run RabbitMQ docker image:
@@ -201,8 +207,7 @@ make start-rabbitmq
201207
```
202208

203209
This starts a Docker container named `rabbitmq`, with RabbitMQ Management UI/API with HTTPS enabled, and configured to use your Entra ID as OAuth 2.0 authentication backend,
204-
based on the information you provided in [rabbitmq.conf](https://github.com/rabbitmq/rabbitmq-oauth2-tutorial/blob/main/conf/entra/rabbitmq.conf)
205-
in the previous steps of this tutorial.
210+
based on the values set in `rabbitmq.conf` in the previous steps of this tutorial.
206211

207212
## Automatic generation of a TLS Certificate and Key Pair
208213

docs/oauth2-examples-keycloak.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ This guide explains how to set up OAuth 2.0 for RabbitMQ
2525
and Keycloak as Authorization Server using the following flows:
2626

2727
* Access [management UI](./management/) via a browser
28-
* Access management rest api
28+
* Access management HTTP API
2929
* Application authentication and authorization
3030

3131
## Prerequisites to follow this guide

docs/oauth2-examples-multiresource.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ The RabbitMQ OAuth 2 plugin is configured like so:
6767
auth_oauth2.preferred_username_claims.1 = preferred_username
6868
auth_oauth2.preferred_username_claims.2 = user_name
6969
auth_oauth2.preferred_username_claims.3 = email
70+
auth_oauth2.issuer = https://keycloak:8443/realms/test
7071
auth_oauth2.scope_prefix = rabbitmq.
7172
```
7273
* With one oauth provider:

0 commit comments

Comments
 (0)