Skip to content

Commit 7988d15

Browse files
authored
Merge pull request #2163 from rabbitmq/support-forward-proxy-in-oauth2
Support forward proxy in oauth2
2 parents b99a68c + 47d8813 commit 7988d15

File tree

4 files changed

+130
-4
lines changed

4 files changed

+130
-4
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
---
2+
title: Use an explicit forward proxy and Keycloak as OAuth 2.0 server
3+
displayed_sidebar: docsSidebar
4+
---
5+
<!--
6+
Copyright (c) 2005-2024 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
7+
8+
All rights reserved. This program and the accompanying materials
9+
are made available under the terms of the under the Apache License,
10+
Version 2.0 (the "License”); you may not use this file except in compliance
11+
with the License. You may obtain a copy of the License at
12+
13+
https://www.apache.org/licenses/LICENSE-2.0
14+
15+
Unless required by applicable law or agreed to in writing, software
16+
distributed under the License is distributed on an "AS IS" BASIS,
17+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
See the License for the specific language governing permissions and
19+
limitations under the License.
20+
-->
21+
22+
# Use an explicit forward proxy and Keycloak as OAuth 2.0 server
23+
24+
:::warning
25+
To run this example you need to use the commercial [Tanzu RabbitMQ docker image](https://techdocs.broadcom.com/us/en/vmware-tanzu/data-solutions/tanzu-rabbitmq-oci/4-0/tanzu-rabbitmq-oci-image/overview.html). Support for **forward proxy** is a commercial feature.
26+
:::
27+
28+
This guide explains how to set up OAuth 2.0 for RabbitMQ to access the Authorization Server via an explicit forward proxy.
29+
30+
* Access the RabbitMQ Management UI using a browser through OAuth2 Proxy
31+
32+
```plain
33+
[ Keycloak ]
34+
/|\
35+
|
36+
2.http request (*) | [ RabbitMQ ]
37+
[ forward-proxy ] <----1. http request (*)--- [ http ]
38+
39+
```
40+
41+
RabbitMQ establishes an HTTP connection with Keycloak via the forward-proxy in any of
42+
these situations:
43+
44+
- You have configured `auth_oauth2.issuer` so that RabbitMQ downloads the OpenID configuration via the OpenID discovery endpoint.
45+
- You have configured `auth_oauth2.issuer` or `auth_oauth2.jwks_url` so that RabbitMQ downloads the tokens' signing keys.
46+
47+
## Prerequisites for Using OAuth 2 vith a forward proxy
48+
49+
* Docker
50+
* make
51+
* A local clone of a [GitHub repository](https://github.com/rabbitmq/rabbitmq-oauth2-tutorial/tree/next) for branch `next` that contains all the configuration files and scripts used on this example.
52+
* The following entries in your /etc/hosts file. Without these entries you will get DNS errors in the browser.
53+
```
54+
localhost keycloak rabbitmq forward-proxy
55+
```
56+
57+
:::info
58+
`make start-keycloak` will
59+
generate the TLS certificate and private keys as necessary. These certificates have an expiration date.
60+
61+
In you see any error messages that hint at expired or invalid certificates, stop Keycloak, run `make clean-certs` to regenerate the certificates and private keys,
62+
and then restart Keycloak and the proxy.
63+
:::
64+
65+
## Deploy Keycloak
66+
67+
Deploy keycloak on its own network called `keycloak_net` by running:
68+
69+
```bash
70+
PROVIDER_NETWORK=keycloak_net make start-keycloak
71+
```
72+
73+
To access Keycloak Management UI, go to https://keycloak:8443/ and enter `admin` as the username and password.
74+
75+
There is a dedicated **Keycloak realm** called `Test` configured as follows:
76+
77+
* [rsa](https://keycloak:8443/admin/master/console/#/realms/test/keys) signing-key
78+
* [rsa provider]https://keycloak:8443/admin/master/console/#/realms/test/keys/providers)
79+
* `rabbitmq-proxy-client` client
80+
81+
## Start Forward Proxy
82+
83+
Deploy and start the forward-proxy in two networks, `keycloak_net` and `rabbitmq_net`, by running:
84+
85+
```bash
86+
PROVIDER_NETWORK=keycloak_net make start-forward-proxy
87+
```
88+
89+
The forward proxy is configured by using [httpd.conf](https://github.com/rabbitmq/rabbitmq-oauth2-tutorial/tree/next/conf/forward-proxy/httpd/httpd.conf). This type of configuration inserts the access token into the HTTP **Authorization** header.
90+
91+
92+
## Start RabbitMQ
93+
94+
Deploy RabbitMQ in its own network `rabbitmq_net` and start it by running:
95+
96+
```
97+
export IMAGE=<Tanzu RabbitMQ OCI image name>
98+
export IMAGE_TAG=<Tanzu RabbitMQ OCI image tag>
99+
MODE=forward-proxy OAUTH_PROVIDER=keycloak make start-rabbitmq
100+
```
101+
102+
## Access [management UI](./management/)
103+
104+
Go to https://rabbitmq:15671/, proceed to login, and enter the credentials
105+
`rabbit_admin` as the username and `rabbit_admin` as the password when Keycloak prompts you.
106+
You will be redirected back to RabbitMQ management UI.
107+
108+
The management UI running in the browser goes straight to keycloak.
109+
In other words, it does not go via the forward-proxy. If you want the management UI to
110+
go via the forward-proxy, you must configure the browser. That is beyond
111+
the scope of this example.
112+
113+
However, in order to validate the token the management UI received from keycloak, RabbitMQ has to connect to keycloak via the forward-proxy. This is necessary in order to download the signing keys and to download the OpenID configuration if you only configured the `issuer` URL.
114+
115+
## Access Management API
116+
117+
To access the management API run the following command. It uses the client [mgt_api_client](https://keycloak:8443/admin/master/console/#/test/clients/c5be3c24-0c88-4672-a77a-79002fcc9a9d/settings), which has the scope [rabbitmq.tag:administrator](https://keycloak:8443/admin/master/console/#/test/client-scopes/f6e6dd62-22bf-4421-910e-e6070908764c/settings).
118+
119+
```bash
120+
make curl-keycloak url=https://localhost:15671/api/overview client_id=mgt_api_client secret=LWOuYqJ8gjKg3D2U8CJZDuID3KiRZVDa realm=test
121+
```

docs/oauth2-examples-keycloak.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ RabbitMQ is deployed with TLS enabled and Keycloak is configured with the corres
7474
To access the management api run the following command. It uses the client [mgt_api_client](https://keycloak:8443/admin/master/console/#/test/clients/c5be3c24-0c88-4672-a77a-79002fcc9a9d/settings) which has the scope [rabbitmq.tag:administrator](https://keycloak:8443/admin/master/console/#/test/client-scopes/f6e6dd62-22bf-4421-910e-e6070908764c/settings).
7575

7676
```bash
77-
make curl-keycloak url=https://localhost:15671/api/overview client_id=mgt_api_client secret=LWOuYqJ8gjKg3D2U8CJZDuID3KiRZVDa
77+
make curl-keycloak url=https://localhost:15671/api/overview client_id=mgt_api_client secret=LWOuYqJ8gjKg3D2U8CJZDuID3KiRZVDa realm=test
7878
```
7979

8080
## Application authentication and authorization with PerfTest

docs/oauth2-examples/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ The guide is accompanied by [a public GitHub repository](https://github.com/rabb
7070
* [Google](./oauth2-examples-google) **NOT SUPPORTED**
7171
* [Multiple OAuth 2.0 servers and/or audiences](./oauth2-examples-multiresource)
7272

73+
### Examples for Tanzu RabbitMQ (commercial-only feature)
74+
75+
* [Forward proxy](./oauth2-examples-forward-proxy)
76+
7377
## Prerequisites Used by the Examples in This Guide {#prerequisites}
7478

7579
* Docker must be installed

docs/oauth2.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ In chronological order, here is the sequence of events that occur when a client
159159
| `auth_oauth2.https.fail_if_no_peer_cert` | Used together with `auth_oauth2.https.peer_verification = verify_peer`. When set to `true`, TLS connection will be rejected if the client fails to provide a certificate. The default value is `false`.
160160
| `auth_oauth2.https.hostname_verification` | Enable wildcard-aware hostname verification for key server. Available values: `wildcard`, `none`. The default value is `none`.
161161
| `auth_oauth2.https.crl_check` | [Perform CRL verification](https://www.erlang.org/doc/man/ssl#type-crl_check) (Certificate Revocation List) verification. Default value is false.
162+
| `auth_oauth2.proxy` | Configures explicit [forward proxy](https://techdocs.broadcom.com/us/en/vmware-tanzu/data-solutions/tanzu-rabbitmq-oci/4-0/tanzu-rabbitmq-oci-image/overview.html) used to connect to the `auth_oauth2.issuer` URL. **This is a commercial-only feature**. More information on how to use it can be found on [this example](./oauth2-examples-forward-proxy).
162163
| `auth_oauth2.algorithms` | Restrict [the usable algorithms](https://github.com/potatosalad/erlang-jose#algorithm-support).
163164
| `auth_oauth2.verify_aud` | Whether to verify the [token's `aud`](#token-validation) field or not. The default value is `true`.
164165
| `auth_oauth2.resource_servers` | [Multiple OAuth 2.0 resources configuration](#multiple-resource-servers-configuration).
@@ -277,7 +278,6 @@ auth_oauth2.algorithms.1 = HS256
277278
auth_oauth2.algorithms.2 = RS256
278279
```
279280

280-
281281
## Multiple Resource Servers Сonfiguration {#multiple-resource-servers-configuration}
282282

283283
Each `auth_oauth2.resource_servers.<id/index>.` entry has the following variables shown in the table below. Except for the variables `id` and `oauth_provider_id`, if a resource does not configure a variable, RabbitMQ uses the variable configured at the root level. For instance, if the resource `auth_oauth2.resource_servers.prod` does not configure `preferred_username_claims` variable, RabbitMQ uses the value configured in `auth_oauth2.preferred_username_claims` for the resource `prod`.
@@ -322,8 +322,9 @@ Each `auth_oauth2.oauth_providers.{id/index}` entry has the following sub-keys.
322322
| `https.depth` | The maximum number of non-self-issued intermediate certificates that may follow the peer certificate in a valid [certification path](ssl#peer-verification-depth). The default value is 10.
323323
| `https.verify` | Configures [peer verification](ssl#peer-verification). Available values: `verify_none`, `verify_peer`. The default value is `verify_peer` if there are trusted CA installed in the OS or `auth_oauth2.https.cacertfile` is set.
324324
| `https.fail_if_no_peer_cert` | Used together with `auth_oauth2.https.peer_verification = verify_peer`. When set to `true`, TLS connection will be rejected if the client fails to provide a certificate. The default value is `false`.
325-
| `https.hostname_verification` | Enable wildcard-aware hostname verification for key server. Available values: `wildcard`, `none`. The default value is `none`.
326-
| `https.crl_check` | [Perform CRL verification](https://www.erlang.org/doc/man/ssl#type-crl_check) (Certificate Revocation List) verification. Default value is false.
325+
| `https.hostname_verification`| Enable wildcard-aware hostname verification for key server. Available values: `wildcard`, `none`. The default value is `none`.
326+
| `https.crl_check` | [Perform CRL verification](https://www.erlang.org/doc/man/ssl#type-crl_check) (Certificate Revocation List) verification. Default value is false.
327+
| `auth_oauth2.proxy` | Configures explicit [forward proxy](https://techdocs.broadcom.com/us/en/vmware-tanzu/data-solutions/tanzu-rabbitmq-oci/4-0/tanzu-rabbitmq-oci-image/overview.html) used to connect to the `issuer` URL. **This is a commercial-only feature**. More information on how to use it can be found on [this example](./oauth2-examples-forward-proxy).
327328
| `signing_keys` | Local filesystem paths to the [signing key files](#signing-key-files). The files must exist and be readable.
328329
| `default_key` | ID of the default signing key.
329330
| `algorithms` | Used to restrict [the list of enabled algorithms](https://github.com/potatosalad/erlang-jose#algorithm-support).

0 commit comments

Comments
 (0)