Enabling OAuth2 on Management UI #9963
-
I use the rabbitmq:3.12-management docker image, and I am trying to configure it with the OAuth2. My OAuth2 is home made server based on the oidc-provider. My first step was to enable the OAuth2 on backend, I added the following lines to the config file auth_backends.1 = rabbit_auth_backend_oauth2 and it works - great! The problem started when I tried to configure the OAuth2 on the Management side, so what I did is I added this to the config file: management.oauth_enabled = true Authorization flow with PKCE is executed properly, the OAuth2 server generates the response containing the access_token and id_token. But after getting the response the UI Management query GET /api/whoami and it uses the access_token (while I believe it should use the id_token) as the bearer token in the authorization header - in result I have the error on the RabbitMQ server-side - Authentication using an OAuth 2/JWT token failed: provided token is invalid- and I cannot log in into the management. If I query the GET /api/whoami with the id_token (generated during the authorization flow with PKCE started from the UI) the response is correct. Thank you in advance |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 2 replies
-
Thank you for re-posting your question here 😄 |
Beta Was this translation helpful? Give feedback.
-
access_token is what is always used to make access control decisions, not id_token. The latter only carry identities not permissions and/or scopes. Can you share your access_token here? The encoded version. I think your access token is not fully compliant with what RabbitMQ expect. https://github.com/rabbitmq/rabbitmq-oauth2-tutorial#understanding-access-tokens-and-how-rabbitmq-uses-it I will investigate tomorrow your oidc server which i was not aware of. |
Beta Was this translation helpful? Give feedback.
-
My OIDC/OAuth2 server produces the following response when requesting the token: { You can see that the access_token is the opaque token, while the id_token is the JWT token. When configuring the OAuth2 backend in RabittMQ, I pointed where it can take from the public key : When connecting programatically to RabbitMQ server with the amqp I send the id_token as password (leaving the user empty), and I believe the RabbitMQ decodes it with the given public key and from there it knows the scope which is translated to permissions. I thought the frontend will work the same way -> just it will get the token itself followng the authorization with PKCE key. |
Beta Was this translation helpful? Give feedback.
-
When you access amqp, you are actually passing the id_token .. As far as RabbitMQ is concerned, as long as the token conforms to the standard access token format which has a header and a payload and a sIgnature, and RabbitMQ can extract the scopes from the "scope" claim or from other claim you configured, then the token is accepted by RabbitMQ. In your case, the id_token contains the "scope" claim which is uncommon. Typically, id_token only contains identities and other information relative to the user. The management plugin, via the PKCE authorization flow, receives an access_token and an id_token from the oauth provider. And RabbitMQ will only use the access_token because it is the token which carries the scopes / permissions. Not the id_token. Can you please find out if you can configure your provider to issue JWT access-token not opaque ones? If you cannot, then I need to decide what it is best: Let me know what you think. |
Beta Was this translation helpful? Give feedback.
-
Ok, understood. I overlooked the need to issue the access-token in JWT format. It looks like the library I use, supports issuing access-token in JWT format, I need to figure out how to do it. |
Beta Was this translation helpful? Give feedback.
When you access amqp, you are actually passing the id_token .. As far as RabbitMQ is concerned, as long as the token conforms to the standard access token format which has a header and a payload and a sIgnature, and RabbitMQ can extract the scopes from the "scope" claim or from other claim you configured, then the token is accepted by RabbitMQ. In your case, the id_token contains the "scope" claim which is uncommon. Typically, id_token only contains identities and other information relative to the user.
The management plugin, via the PKCE authorization flow, receives an access_token and an id_token from the oauth provider. And RabbitMQ will only use the access_token because it is the toke…