Include scope parameter & values when refreshing Azure OIDC tokens #21200
rowansmithau
started this conversation in
Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
slack context: https://codercom.slack.com/archives/C014JH42DBJ/p1763983935459739
This is a feature request to add support for including the original values supplied in
CODER_OIDC_SCOPESin thescopesparameter when submitting a token refresh request to Azure in order to solve a token refresh failure problem. This issue exists specifically in Azure due to Azure requiring thescopesparameter be included on refresh requests. The RFC states:However Microsoft have advised:
When authenticating to Coder with OIDC, specifically via Azure, i.e. following the guide at https://coder.com/docs/admin/users/oidc-auth/microsoft while specifying
CODER_OIDC_SCOPES=offline_access,openid,email,profileandCODER_OIDC_IGNORE_USERINFO=false(the default value), a JSON response is received from Azure to coderd which is as follows:The access token has claims as follows:
These values correspond to the Azure graph service and not to the customer's Azure tenant. In Microsoft terminology this is considered a version 1 token. As a result of this the
access_tokencan only be validated by Azure, which means it is unsuitable for use cases such as https://registry.coder.com/modules/coder/vault-jwt. When attempting to authenticate to Vault using this token Vault responds with:If Microsoft's guidance is followed and the 'Expose an API' option is used to create an API scope, and the scope is then added to the 'API permissions' list to be included on the token, the following changes can be made to Coder to request a token for the scope:
The resulting response now includes a version 2 token with the
scopecorresponding to the requested value inCODER_OIDC_SCOPES:The
access_tokenfield is now populated with an audience value corresponding to the Azure app registration used for OIDC and the issuer now reflects the customer's Azure tenant:This token is then able to be used for authenticating to Vault, or other services which may consume a JWT and validate it against the customer's Azure tenant.
In the background coderd will as required attempt to perform a refresh of the OIDC access token using the following request body:
This however will fail with an HTTP 400 response:
As the
scopesparameter is not included in the request the token refresh process fails and the customer is logged out of Coder and must reauthenticate. For the customer this issue is logged against they are logged out of Coder after 10 minutes.Coder appears to use the
x/oauth2package to construct the refresh requests in https://github.com/coder/coder/blob/a59a84b2a789d46a96d0214e8923f1bcd3cc93d8/coderd/httpmw/oauth2.go, and perx/oauth2's oauth2.go refresh implementation it does not include thescopesparameter on the token refresh request.An alternative approach was considered to capture the
id_tokenfrom the initial Azure login response body and make it available for use (i.e. authenticate to Vault) as it would negate the requirement for using the 'Expose an API' function in Azure and does not result in the session timeout issue, however the idea was rejected due to security concerns and a desire to solve the issue using another method, potentially by supplying thescopesparameter on refresh requests.Beta Was this translation helpful? Give feedback.
All reactions