Skip to content

Commit c19112d

Browse files
Explain how to configure extra params for authorize and token endpoints
1 parent ea33b63 commit c19112d

File tree

9 files changed

+209
-103
lines changed

9 files changed

+209
-103
lines changed

docs/management/index.md

Lines changed: 30 additions & 1 deletion
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,12 +404,16 @@ 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. Check out the [OAuth 2.0](./oauth2#discovery-endpoint-params) documentation about OpenId discovery endpoint to learn more about it.
407408

408409
:::warning
409410
If RabbitMQ cannot download the OpenID provider configuration, it shows an error message and OAuth 2.0 authentication is disabled in the management UI.
410411
:::
411412

413+
:::tip
414+
If you used to configure `auth_oauth2.metadata_url` because your provider used a slightly different OpenId Discovery endpoint url, since RabbitMQ 4.1 you should instead configure the correct path and/or include any additional parameters. Please read [this section of the documentation](./oauth2#discovery-endpoint-params) where it is explained how to do it. `auth_oauth2.metadata_url` may be deprecated in future versions.
415+
:::
416+
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.
413418

414419
### Configure client secret {#configure-client-secret}
@@ -505,6 +510,19 @@ 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 parameters for authorization and token endpoints {#extra-endpoint-params}
514+
515+
There are some OAuth 2.0 providers which require extra parameters in the request sent to the **authorization endpoint** and/or to the **token endpoint**. These parameters are custom parameters. The Management UI already sends all the parameters required by the OAuth 2.0 Authorization Code flow.
516+
517+
Here is an example of setting an extra parameter called `audience` for both endpoints, the **authorization** and **token** endpoint:
518+
519+
```ini
520+
management.oauth_authorization_endpoint_params.audience = some-audience-id
521+
management.oauth_token_endpoint_params.audience = some-audience-id
522+
```
523+
524+
You can configure as many parameters as you need.
525+
508526
### Special attention to CSP header `connect-src` {#csp-header}
509527

510528
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 +618,17 @@ the following settings:
600618
- `resource` : `rabbit_prod`
601619
- `scopes` : `openid rabbitmq.tag:management rabbitmq.read:*/*`
602620

621+
#### Configure extra parameters for authorization and token endpoints
622+
623+
There are some OAuth 2.0 providers which require extra parameters in the request sent to the **authorization endpoint** and/or to the **token endpoint**. These parameters are custom parameters and specified per resource. The Management UI already sends all the parameters required by the OAuth 2.0 Authorization Code flow.
624+
625+
Here is an example of setting an extra parameter called `audience` for both endpoints for the resource `some-resource-id`:
626+
627+
```ini
628+
management.oauth_resource_servers.2.id = some-resource-id
629+
management.oauth_resource_servers.2.oauth_authorization_endpoint_params.audience = some-resource-id
630+
management.oauth_resource_servers.2.oauth_token_endpoint_params.audience = some-resource-id
631+
```
603632

604633
#### Optionally do not expose some resources in the management UI
605634

docs/oauth2-examples-auth0.md

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,9 @@ of the end user.
7070
In the settings, choose:
7171

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

7877

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

104-
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
105-
values you gathered above.
103+
Clone the configuration file [conf/auth0/rabbitmq.conf.tmpl](https://github.com/rabbitmq/rabbitmq-oauth2-tutorial/blob/main/conf/auth0/rabbitmq.conf.tmpl) as `rabbitmq.conf` (in the 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+
Since RabbitMQ 4.1.x, you must configure RabbitMQ to include a request parameter
113+
called `audience` whose value matches the value you set in `auth_oauth2.resource_server_id`.
114+
Earlier RabbitMQ versions always sent this parameter. If you do not configure it,
115+
Auth0 sends an invalid token and RabbitMQ shows the error message `No authorized`.
116+
117+
These [two configuration lines](https://github.com/rabbitmq/rabbitmq-oauth2-tutorial/blob/main/conf/auth0/rabbitmq.conf.tmpl#L8-L9) configure the `audience` parameter with the value `rabbitmq`.
118+
119+
:::
106120

107121
## Start RabbitMQ
108122

@@ -115,7 +129,7 @@ make start-rabbitmq
115129

116130
## Verify Management UI flows
117131

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

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

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

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ limitations under the License.
2424
Demonstrate how to authenticate using the OAuth 2.0 protocol
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

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

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

69-
* Directory (tenant ID)
70-
* Application (client) ID
70+
* **Directory (tenant ID)**.
71+
* **Application (client) ID**.
7172

7273

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

9192
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.
9293

93-
:::info
94-
95-
To learn more about how permissions are managed when RabbitMQ is used together with OAuth 2.0,
96-
see [this portion of the OAuth 2 tutorial](https://github.com/rabbitmq/rabbitmq-oauth2-tutorial#about-permissions)
97-
98-
:::
9994

10095
3. On the right menu that has just opened, provide the requested information:
10196

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

@@ -115,7 +110,7 @@ see [this portion of the OAuth 2 tutorial](https://github.com/rabbitmq/rabbitmq-
115110

116111
* **Display Name**: the name you want to give to the role (ex: *Configure All Vhosts*)
117112
* **Allowed member types**: Both (Users/Groups + Applications)
118-
* **Value**: `Application_ID.configure:*/*` (where *Application_ID* is the value of the *Application (client) ID* noted earlier in this tutorial)
113+
* **Value**: `{Application_ID}.configure:*/*` (where *Application_ID* is the value of the *Application (client) ID* noted earlier in this tutorial)
119114
* **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)
120115
* **Do you want to enable this app role**: `yes` (check the box)
121116

@@ -152,11 +147,11 @@ Now that some roles have been created for your application, you still need to as
152147

153148
9. Repeat the operations for all the roles you want to assign.
154149

155-
## Create scope required by Management ui during authorization
150+
## Create scope for management UI
156151

157-
So far we have created the roles and granted the roles to the user who is going to
158-
access the management UI. When this user logs into RabbitMQ management UI, its token
159-
contains the granted roles.
152+
There is one last configuration step required. Without this step, the `access_token` returned
153+
by **Entra ID** is invalid. RabbitMQ cannot validate its signature because the `access_token` is meant for Microsoft resources.
154+
First, you need to create a scope associated to the application you registered for RabbitMQ management UI as follows:
160155

161156
1. Go to **App registrations**.
162157
2. Click on your application.
@@ -165,40 +160,35 @@ contains the granted roles.
165160
5. Enter a name, eg. `management-ui`. Enter the same name for **Admin consent display name** and a description and save it.
166161
7. The scope is named `api://{Application (client) ID}/{scope_name}`.
167162

168-
RabbitMQ management ui must provide this scope in `management.oauth_scopes` along with `openid profiles` scopes.
163+
Check out the last section to see how this scope is used to configure RabbitMQ.
169164

170165
## Configure Custom Signing Keys
171166

172-
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.
167+
It is optional to create a signing key for your application. If you create one though, you must add the following RabbitMQ configuration. You need to replace `{Application(client) ID}` with your *Application(client) ID*. Without this configuration, 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.
173168

174-
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.
169+
```ini
170+
auth_oauth2.discovery_endpoint_params.appid = {Application(client) ID}
171+
```
175172

173+
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).
176174

177175
## Configure RabbitMQ to Use Entra ID as OAuth 2.0 Authentication Backend
178176

179-
The configuration on Entra ID side is done. Next, configure RabbitMQ to use these resources.
177+
The configuration on **Entra ID** side is done. Next, configure RabbitMQ to use these resources.
180178

181-
[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.
179+
Clone the file called [rabbitmq.conf.tmpl](https://github.com/rabbitmq/rabbitmq-oauth2-tutorial/tree/main/conf/entra/rabbitmq.conf.tmpl) as `rabbitmq.conf` (in the same folder as `rabbitmq.conf.tmpl`).
182180

183-
Update it with the following values:
181+
Edit the new `rabbitmq.conf` file and proceed as follows:
184182

185-
* **Tenant ID** associated to the app that you registered in Entra ID
186-
* **Application ID** associated to the app that you registered in Entra ID
187-
* Value of the **jwks_uri** key from `https://login.microsoftonline.com/{TENANT_ID}/v2.0/.well-known/openid-configuration`
183+
1. Replace `{Directory (tenant) ID}` with the value gathered earlier as **Application (client) ID**
184+
2. Replace `{Application(client) ID}` with the value gathered as **Application (client) ID**
185+
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.
188186

189187
```ini
190-
auth_backends.1 = rabbit_auth_backend_oauth2
191-
192-
management.oauth_enabled = true
193-
management.oauth_client_id = {Application(client) ID}
194-
management.oauth_scopes = openid profile api://{Application(client) ID}/rabbitmq
195-
196-
auth_oauth2.resource_server_id = {Application(client) ID}
197-
auth_oauth2.additional_scopes_key = roles
198-
auth_oauth2.issuer = https://login.microsoftonline.com/{Directory (tenant) ID}
199-
188+
#auth_oauth2.discovery_endpoint_params.appid = {Application(client) ID}
200189
```
201190

191+
202192
## Start RabbitMQ
203193

204194
Run the following commands to run RabbitMQ docker image:
@@ -209,8 +199,7 @@ make start-rabbitmq
209199
```
210200

211201
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,
212-
based on the information you provided in [rabbitmq.conf](https://github.com/rabbitmq/rabbitmq-oauth2-tutorial/blob/main/conf/entra/rabbitmq.conf)
213-
in the previous steps of this tutorial.
202+
based on the information you provided in `rabbitmq.conf` in the previous steps of this tutorial.
214203

215204
## Automatic generation of a TLS Certificate and Key Pair
216205

docs/oauth2-examples-multiresource.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ This is a summary of the configuration, found in [rabbitmq.conf](https://github.
6666
auth_oauth2.preferred_username_claims.1 = preferred_username
6767
auth_oauth2.preferred_username_claims.2 = user_name
6868
auth_oauth2.preferred_username_claims.3 = email
69-
auth_oauth2.jwks_url = https://keycloak:8443/realms/test/protocol/openid-connect/certs
69+
auth_oauth2.issuer = https://keycloak:8443/realms/test
7070
auth_oauth2.scope_prefix = rabbitmq.
7171
auth_oauth2.https.peer_verification = verify_peer
7272
auth_oauth2.https.cacertfile = /etc/rabbitmq/keycloak-cacert.pem

0 commit comments

Comments
 (0)