Skip to content

Commit bafe924

Browse files
MarcialRosalesmkuratczyk
authored andcommitted
Document preferred_username_claims cuttlefish setting
1 parent caf3094 commit bafe924

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

site/oauth2-examples.md

+29-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ To understand the details of how to configure RabbitMQ with Oauth2, go to the [U
3333
* [Use advanced OAuth 2.0 configuration](#advanced-configuration)
3434
- [Use custom scope field](#use-custom-scope-field)
3535
- [Use multiple asymmetrical signing keys](#use-multiple-asymmetrical-signing-keys)
36-
- [Use Scope Aliases](#use-scope-aliases)
36+
- [Use Scope Aliases](#use-scope-aliases)
37+
- [Preferred username claims](#preferred-username-claims)
3738
- [Use Rich Authorization Requests tokens](#use-rar-tokens)
3839
* Use different OAuth 2.0 servers
3940
- [KeyCloak](oauth2-examples-keycloak.html)
@@ -62,13 +63,18 @@ To understand the details of how to configure RabbitMQ with Oauth2, go to the [U
6263

6364
## <a id="getting-started-with-uaa-and-rabbitmq" class="anchor" href="#getting-started-with-uaa-and-rabbitmq">Getting started with UAA and RabbitMQ</a>
6465

65-
Before proceed other more sophisiticated examples, let's start RabbitMQ fully configured with OAuth 2.0 plugin and
66-
UAA as an OAuth 2.0 Authorization Server.
66+
Before proceeding with other more sophisticated examples, let's start RabbitMQ configured with OAuth 2.0 plugin and
67+
[UAA](https://docs.cloudfoundry.org/concepts/architecture/uaa.html) as the OAuth 2.0 Authorization Server.
6768

6869
In the next section, you
6970
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
70-
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
71-
straight to them. They are [KeyCloak](use-cases/keycloak.md), [https://auth0.com/](use-cases/oauth0.md) and [Azure Active Directory](use-cases/azure.md) in addition to UAA which you will use it in the next sections.
71+
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
72+
straight to them. They are:
73+
74+
- [KeyCloak](use-cases/keycloak.md)
75+
- [https://auth0.com/](use-cases/oauth0.md)
76+
- [Azure Active Directory](use-cases/azure.md)
77+
- [UAA](#uaa-asymmetrical-signing-keys)
7278

7379

7480
#### <a id="uaa-asymmetrical-signing-keys" class="anchor" href="#uaa-asymmetrical-signing-keys">Use Asymmetrical Digital Singing Keys</a>
@@ -639,6 +645,24 @@ make stop-perftest-producer PRODUCER=producer_with_roles
639645
make stop-perftest-consumer CONSUMER=consumer_with_roles
640646
</pre>
641647

648+
### <a id="preferred-username-claims" class="anchor" href="#preferred-username-claims">Preferred username claims</a>
649+
650+
RabbitMQ needs to figure out the username associated to the token so that it can display it in the management ui.
651+
By default, RabbitMQ will first look for the `sub` claim and if it is not found it uses the `client_id`.
652+
653+
Most authorization servers return the user's GUID in the `sub` claim rather than the actual user's username or email address, anything the user can relate to. When the `sub` claim does not carry a *user-friendly username*, you can configure one or several claims to extract the username from the token.
654+
655+
Given this configuration:
656+
657+
```
658+
...
659+
{rabbitmq_auth_backend_oauth2, [
660+
{resource_server_id, <<"rabbitmq">>},
661+
{preferred_username_claims, [<<"user_name">>,<<"email">>]},
662+
...
663+
```
664+
665+
RabbitMQ would first look for the `user_name` claim and if it is not found it looks for `email`. Else it uses its default lookup mechanism which first looks for `sub` and then `client_id`.
642666

643667

644668
### <a id="use-rar-tokens" class="anchor" href="#use-rar-tokens">Use Rich Authorization Request Tokens</a>

site/oauth2.md

+4
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ NOTE: `jwks_url` takes precedence over `signing_keys` if both are provided.
167167
| `auth_oauth2.resource_server_id` | [The Resource Server ID](#resource-server-id-and-scope-prefixes)
168168
| `auth_oauth2.resource_server_type` | [The Resource Server Type](#rich-authorization-request)
169169
| `auth_oauth2.additional_scopes_key` | Configure the plugin to also look in other fields (maps to `additional_rabbitmq_scopes` in the old format).
170+
| `auth_oauth2.preferred_username_claims` | List of JWT claims to look for username associated to the token
170171
| `auth_oauth2.default_key` | ID of the default signing key.
171172
| `auth_oauth2.signing_keys` | Paths to signing key files.
172173
| `auth_oauth2.jwks_url` | The URL of key server. According to the [JWT Specification](https://datatracker.ietf.org/doc/html/rfc7515#section-4.1.2) key server URL must be https.
@@ -184,6 +185,8 @@ Configure with key files
184185
<pre class="lang-ini">
185186
auth_oauth2.resource_server_id = new_resource_server_id
186187
auth_oauth2.additional_scopes_key = my_custom_scope_key
188+
auth_oauth2.preferred_username_claims.1 = username
189+
auth_oauth2.preferred_username_claims.2 = user_name
187190
auth_oauth2.default_key = id1
188191
auth_oauth2.signing_keys.id1 = test/config_schema_SUITE_data/certs/key.pem
189192
auth_oauth2.signing_keys.id2 = test/config_schema_SUITE_data/certs/cert.pem
@@ -265,6 +268,7 @@ These are the typical permissions examples:
265268
- `read:vhost1/*`(`read:vhost1/*/*`) - read permissions to any resource on the `vhost1` vhost
266269
- `read:vhost1/some*` - read permissions to all the resources, starting with `some` on the `vhost1` vhost
267270
- `write:vhost1/some*/routing*` - topic write permissions to publish to an exchange starting with `some` with a routing key starting with `routing`
271+
- `read:*/*/*` and `write:*/*/*` - queue binding permissions required to bind a queue on a topic exchange with any routing key
268272

269273
See the [wildcard matching test suite](https://github.com/rabbitmq/rabbitmq-server/blob/main/deps/rabbitmq_auth_backend_oauth2/test/wildcard_match_SUITE.erl) and [scopes test suite](https://github.com/rabbitmq/rabbitmq-server/blob/main/deps/rabbitmq_auth_backend_oauth2/test/scope_SUITE.erl) for more examples.
270274

0 commit comments

Comments
 (0)