Skip to content

Commit 4d2422c

Browse files
Merge pull request #2278 from rabbitmq/feature-13894
Add variable expansion section to oauth2 docs
2 parents ac99c0e + 19ed84f commit 4d2422c

File tree

4 files changed

+49
-11
lines changed

4 files changed

+49
-11
lines changed

docs/oauth2.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ There's also a companion [troubleshooting guide for OAuth 2-specific problems](.
3434
### [How to configure it](#how-to-configure-it)
3535

3636
* [Prerequisites](#prerequisites)
37-
* [Configure OAuth 2.0 for identity providers compliant with OpenId Connect](#configure-for-openid-connect)
37+
* [Configure OAuth 2.0 step by step](#configure-for-openid-connect)
3838

3939
### [How it works](#how-it-works)
4040

@@ -98,7 +98,7 @@ example, the following configuration adds OAuth 2.0 as the only authentication b
9898
auth_backends.1 = rabbit_auth_backend_oauth2
9999
```
100100

101-
### Configure OAuth 2.0 for identity providers compliant with OpenId Connect{#configure-for-openid-connect}
101+
### Configure OAuth 2.0 step by step {#configure-for-openid-connect}
102102

103103
Nowadays, the majority of the identity providers are compliant with OpenId Connect. At minimum,
104104
this means that they expose an HTTP endpoint called *Discovery endpoint* mounted at
@@ -237,7 +237,7 @@ and [6)](#step6).
237237

238238
#### Step 5: Ensure your scopes are recognized RabbitMQ scopes {#step5}
239239

240-
Ensure that the scopes contained in the token are recognized RabbitMQ scopes.
240+
Ensure that the scopes contained in the token are [recognized RabbitMQ scopes](#scope-translation).
241241

242242
Here are examples of recognized RabbitMQ scopes:
243243

@@ -760,6 +760,23 @@ If `scope_prefix` is configured then scopes are prefixed as follows: `<scope_pre
760760
For example, if `scope_prefix` is `api://` and the permission is `read:*/*` the scope would be
761761
`api://read:*/*`
762762

763+
#### Variable expansion
764+
765+
OAuth 2.0 authorisation backend supports variable expansion when checking permission on vhosts and resources
766+
such as queues and exchanges.
767+
Variabbles can be any JWT claims whose value is a plain string and/or the `vhost` variable.
768+
769+
For example, a user connected with the token below to the vhost `prod` should have a write
770+
permission on all exchanges starting with `x-prod-`, and any routing key starting with `u-bob-`,
771+
where `bob` comes from the `sub` JWT claim:
772+
773+
```json
774+
{
775+
"sub" : "bob",
776+
"scope" : [ "rabbitmq.write:*/x-{vhost}-*/u-{sub}-*" ]
777+
}
778+
```
779+
763780
### Topic Exchange scopes {#topic-exchange-scopes}
764781

765782
The [previous](#scope-translation) section explained, in detail, how permissions are mapped to
@@ -782,6 +799,8 @@ To publish to a **Topic Exchange**, you need to have the following scope:
782799

783800
> for example `rabbitmq.write:*/*/*`
784801
802+
#### Variable expansion
803+
785804
OAuth 2.0 authorisation backend supports variable expansion when checking permission on topics.
786805
It supports JWT claims whose value is a plain string, plus the `vhost` variable.
787806

versioned_docs/version-3.13/oauth2.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ There's also a companion [troubleshooting guide for OAuth 2-specific problems](.
3232
### [How to configure it](#how-to-configure-it)
3333

3434
* [Prerequisites](#prerequisites)
35-
* [Configure OAuth 2.0 for identity providers compliant with OpenId Connect](#configure-for-openid-connect)
35+
* [Configure OAuth 2.0 step by step](#configure-for-openid-connect)
3636

3737
### [How it works](#how-it-works)
3838

@@ -94,7 +94,7 @@ example, the following configuration adds OAuth 2.0 as the only authentication b
9494
auth_backends.1 = rabbit_auth_backend_oauth2
9595
```
9696

97-
### Configure OAuth 2.0 for identity providers compliant with OpenId Connect{#configure-for-openid-connect}
97+
### Configure OAuth 2.0 step by step {#configure-for-openid-connect}
9898

9999
Nowadays, the majority of the identity providers are compliant with OpenId Connect. At minimum, this
100100
means that they expose an HTTP endpoint called *Discovery endpoint* mounted at

versioned_docs/version-4.0/oauth2.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ There's also a companion [troubleshooting guide for OAuth 2-specific problems](.
3232
### [How to configure it](#how-to-configure-it)
3333

3434
* [Prerequisites](#prerequisites)
35-
* [Configure OAuth 2.0 for identity providers compliant with OpenId Connect](#configure-for-openid-connect)
35+
* [Configure OAuth 2.0 step by step](#configure-for-openid-connect)
3636

3737
### [How it works](#how-it-works)
3838

@@ -94,7 +94,7 @@ example, the following configuration adds OAuth 2.0 as the only authentication b
9494
auth_backends.1 = rabbit_auth_backend_oauth2
9595
```
9696

97-
### Configure OAuth 2.0 for identity providers compliant with OpenId Connect{#configure-for-openid-connect}
97+
### Configure OAuth 2.0 step by step{#configure-for-openid-connect}
9898

9999
Nowadays, the majority of the identity providers are compliant with OpenId Connect. At minimum, this
100100
means that they expose an HTTP endpoint called *Discovery endpoint* mounted at
@@ -195,7 +195,7 @@ below, you need to upgrade to [RabbitMQ 4.1](/docs/oauth2#step4).
195195
#### Step 5: Ensure your scopes are recognized RabbitMQ scopes {#step5}
196196

197197
Ensure that the scopes contained in the token are recognized RabbitMQ scopes. Here are examples of
198-
recognized RabbitMQ scopes:
198+
[recognized RabbitMQ scopes](#scope-translation):
199199

200200
* `rabbitmq.tag:administrator` Here `rabbitmq` is the name of the `resource_server_id` you configured
201201
in the first step. `tag:administrator` grants the administrator role to the management UI.

versioned_docs/version-4.1/oauth2.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ There's also a companion [troubleshooting guide for OAuth 2-specific problems](.
3434
### [How to configure it](#how-to-configure-it)
3535

3636
* [Prerequisites](#prerequisites)
37-
* [Configure OAuth 2.0 for identity providers compliant with OpenId Connect](#configure-for-openid-connect)
37+
* [Configure OAuth 2.0 step by step](#configure-for-openid-connect)
3838

3939
### [How it works](#how-it-works)
4040

@@ -98,7 +98,7 @@ example, the following configuration adds OAuth 2.0 as the only authentication b
9898
auth_backends.1 = rabbit_auth_backend_oauth2
9999
```
100100

101-
### Configure OAuth 2.0 for identity providers compliant with OpenId Connect{#configure-for-openid-connect}
101+
### Configure OAuth 2.0 step by step {#configure-for-openid-connect}
102102

103103
Nowadays, the majority of the identity providers are compliant with OpenId Connect. At minimum,
104104
this means that they expose an HTTP endpoint called *Discovery endpoint* mounted at
@@ -237,7 +237,7 @@ and [6)](#step6).
237237

238238
#### Step 5: Ensure your scopes are recognized RabbitMQ scopes {#step5}
239239

240-
Ensure that the scopes contained in the token are recognized RabbitMQ scopes.
240+
Ensure that the scopes contained in the token are [recognized RabbitMQ scopes](#scope-translation).
241241

242242
Here are examples of recognized RabbitMQ scopes:
243243

@@ -760,6 +760,23 @@ If `scope_prefix` is configured then scopes are prefixed as follows: `<scope_pre
760760
For example, if `scope_prefix` is `api://` and the permission is `read:*/*` the scope would be
761761
`api://read:*/*`
762762

763+
#### Variable expansion
764+
765+
OAuth 2.0 authorisation backend supports variable expansion when checking permission on vhosts and resources
766+
such as queues and exchanges.
767+
Variabbles can be any JWT claims whose value is a plain string and/or the `vhost` variable.
768+
769+
For example, a user connected with the token below to the vhost `prod` should have a write
770+
permission on all exchanges starting with `x-prod-`, and any routing key starting with `u-bob-`,
771+
where `bob` comes from the `sub` JWT claim:
772+
773+
```json
774+
{
775+
"sub" : "bob",
776+
"scope" : [ "rabbitmq.write:*/x-{vhost}-*/u-{sub}-*" ]
777+
}
778+
```
779+
763780
### Topic Exchange scopes {#topic-exchange-scopes}
764781

765782
The [previous](#scope-translation) section explained, in detail, how permissions are mapped to
@@ -782,6 +799,8 @@ To publish to a **Topic Exchange**, you need to have the following scope:
782799

783800
> for example `rabbitmq.write:*/*/*`
784801
802+
#### Variable expansion
803+
785804
OAuth 2.0 authorisation backend supports variable expansion when checking permission on topics.
786805
It supports JWT claims whose value is a plain string, plus the `vhost` variable.
787806

0 commit comments

Comments
 (0)