oauth2-proxy: v7.3.0 breaks azure provider
After installing v7.3.0 the azure provider breaks. Our configuration works with v7.2.1 but once I install v7.3.0 we get the following in the log file:
[2022/05/30 09:45:12] [azure.go:227] unable to get claims from token: could not get claim "groups": failed to fetch claims from profile URL: error making request to profile URL: unexpected status "400":
I haven’t seen any breaking changes in the change logs that should point to this, any ideas?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 32
- Comments: 71 (18 by maintainers)
I had to change the provider type to
oidcand addoidc-issuer-urlargument to make it work with version7.3.0.7.2.1
7.3.0
@JoelSpeed, this is still an issue.
@JoelSpeed On my AKS cluster I use OAuth2-Proxy with Azure provider to authenticate the users and to authorise them to access the Kubernetes namespaces according to the AAD groups, they belong to. OAuth2-Proxy is installed with its Helm chart (version 6.8.0) and here are the extraArgs:
After updating OAuth2-Proxy to 7.4.0 I get the same error in the logs, that is reported at the beginning of this thread: https://github.com/oauth2-proxy/oauth2-proxy/issues/1666#issue-1252488741
So I have switched to the Azure Auth V2 endpoint, as many have done in this thread by using the following extraArgs:
This lets the user authenticate to the AKS cluster, but it does not authorise them to access the Kubernetes namespaces, which require the AAD groups. I have checked the OAuth2-Proxy and it seems that the groups are acquired though:
As you can see the session’s expiration is set to
1970-01-01 00:00:00 +0000 UTC: do you know what the issue could be? It is strange that the Azure Auth V2 endpoint returns me an expired session.@rouke-broersma Thanks for the heads up, I can look into that. The other issue really is time. I’m pretty short on it these days given this is now a hobby project and not something my employer grants me time to work on. Realistically we need to find engaged maintainers for each provider who can put in the time to make sure their providers are still working as we make changes
@JoelSpeed fyi an azure tenant can be created for free, at which point you will have access to all features you need to test authentication. They are free features and as far as I know don’t even require a credit card attached. If necessary I can create a tenant for you and hand it over to you, if interested.
As far as requiring setting the oidc issuer url, I wonder what the use of the azure specific provider is at that point. I would expect that choosing a specific provider makes working with that provider easier because it uses sane defaults. At most I would expect to pass the tenant id to the config and for the provider to figure out what the exact issuer url is. Would it not make more sense to just always use the oidc provider if we have to provide the full oidc config anyway? Or am I missing something?
@pierluigilenoci and others, I am also using Azure AD with AKS and following are my findings
X-Auth-Request-Access-Tokentoken has groups info in payload butAuthorizationtoken doesn’t contain groups info in payload.While I was able to successfully log in to the Kubernetes Dashboard, I encountered issues with the authorization process as per RBAC. In order to investigate further, I performed manual testing by obtaining the token and testing it with the Kubernetes API.
SelfSubjectReview( its purpose is to find out how Kubernetes cluster maps authentication information to identify me as a client.)I found that using the token obtained via
kubeloginand including it in theAuthorizationheader allowed me to access all the resources in the Kubernetes dashboard.I encountered an issue where the token returned by oauth2_proxy was resulting in an “unauthorized” error.
Upon decoding both tokens, I discovered a difference in the “aud” (audience) value. The token obtained through kubelogin had the “aud” value set to “6dae42f8-4368-4678-94ff-3960e28e3630”, while the token acquired via oauth2 had the “aud” value set to “https://graph.microsoft.com/”.
I attempted to update the “aud” value in oauth2_proxy by setting the resource value to “6dae42f8-4368-4678-94ff-3960e28e3630”, but encountered an error.
[azure.go:105] WARNING: --resource option has no effect when using the Azure OAuth V2 endpoint.To verify this further, I conducted testing using the following two commands:
az account get-access-token --resource https://management.azure.com--> unauthorizeaz account get-access-token --resource 6dae42f8-4368-4678-94ff-3960e28e3630--> authorizeIs there any way we can add resource in v2 ?
PS: It is the same application ID 6dae42f8-4368-4678-94ff-3960e28e3630 in all clouds for Kubernetes Service.
The solution is indeed to switch to the
https://login.microsoftonline.com/<tenant id>/v2.0endpoint and use “oidc” as providerI got it working with
v7.5.1, in my case I don’t need the proxy to fetch the groups, because this is done by AKS managed identity. Here’s my configuration:The scope
openidis required when authenticating usingoidc,6dae42f8-4368-4678-94ff-3960e28e3630/.defaultis the scope forAzure Kubernetes Service AAD Server.Related issue: https://github.com/oauth2-proxy/oauth2-proxy/issues/2314
@JoelSpeed @steakunderscore @NickMeves, any news around this?
Project ded rip
This issue should be added to the breaking changes for the v7.3.0 release.
Hello @JoelSpeed, I have found the issue.
In this func, you had the azure provider set to true.
This then causes the Azure provider to move through the oidc setup, which causes both problems:
1st problem is that the issuerURL must be set. 2nd Problem is that the graph api returns a 400.
What is actually happening is the provider setup is reaching out to the issuerURL and populating the profile URL from here, (which is actually )
from there everything is set, and the Azure init (which relies on empty values to set the azure defaults) fails.
Add Azure into the false case, and it is unbroken.
I had oauth2-proxy running on my Kubernetes cluster which I deployed using Helm via ArtifactHUB > Helm > OAuth2 Proxy chart. I just upgraded oauth2-proxy from
v7.1.3tov7.4.0with its chart from4.2.2to6.16.1and started seeing the following error:[main.go:60] ERROR: Failed to initialise OAuth2 Proxy: error intiailising provider: could not create provider data: error building OIDC ProviderVerifier: invalid provider verifier options: missing required setting: issuer-urlI referred to OAuth2 Proxy > Docs > Azure Auth Provider from documentation to make it work by adding
azure_tenantandoidc_issuer_urlunderconfigin the default values file as follows:Before:
After:
If it still fails after this change with the following error:
Error redeeming code during OAuth2 callback: unable to get email and/or groups claims from token: unable to get claims from token: could not initialise claim extractor: failed to parse ID Token: oidc: malformed jwt, expected 3 parts got 1then set the
oidc_issuer_urlunderconfigin the default values file to V2 Azure Auth endpoint instead as follows:NOTE:
${azure_tenant_id}will be replaced with the actual Azure App Tenant ID which you can find here: Azure Active Directory (AD) > App registrations > All applications >[APP NAME]> Overview > Essentials >Directory (tenant) IDwhere[APP NAME]is the name of the registered app for oauth2-proxy.About a year has passed since several users had problems running the Azure provider. Judging by the comments here, the problem has been fairly cleared up. It may be time to find someone to handle and resolve the situation. What do you think? @JoelSpeed @steakunderscore @NickMeves
For completeness, I also add all the provider’s contributors (maybe someone driven by a positive spirit takes charge of the situation). @adriananeci @ianroberts @weinong @codablock @johejo @wonderhoss @theonewolf @pasha-r @leyshon @MisterWil @jehiah @eelcocramer
Thank you all for the effort invested in the project so far and for what you will invest in the future.
seeing a similar issue as @vittoriocanilli i am able to use it but userinfo is missing… it only seems to be grabbing user email but the rest are blank.
@erikgb I just tried with 7.4 and still seeing the same error.
That’s not really updating the documentation. The azure provider is broken and the instructions found here: https://github.com/oauth2-proxy/oauth2-proxy/blob/master/docs/docs/configuration/auth.md#azure-auth-provider are no longer working.
@JoelSpeed already did, 6 days ago: https://github.com/oauth2-proxy/oauth2-proxy/pull/1771
Update: Working fine with this setup:
@knightian yes, I am using:
The Azure AD app is configured for v2 in the manifest:
"accessTokenAcceptedVersion": 2@knightian it does, but you need to use the group IDs instead of the group names because group names are not returned for oidc.
I can confirm that the suggestion from @AureaMohammadAlavi in https://github.com/oauth2-proxy/oauth2-proxy/issues/1666#issuecomment-1145838016 works for me/us! Thanks! I am not sure if there are any downsides using the standard oidc-provider with Azure? Maybe the azure-provider should be deprecated and eventually removed?
OK, so we clearly have a couple of issues here which were not intentional breakages. Please note that none of the maintainers have easy access to Azure to test changes so we do rely on community feedback for this (and many other providers).
Let’s start with the new requirement of having an
oidc-issuer-urlset. I believe this was a result of #1555 in which we moved the verifier initialisation into the providers package. Looking at the code, in the validation package, the old code would only initialise the verifier if the OIDC issuer URL was set. In the new code, we now have it so that we initialise the verifier if the provider expects to use one. If you look at the azure code you can see that it optionally skipped the verification of the token if the verifier wasn’t initialised.Given this is insecure and the new behaviour is more secure, I’m tempted to call that a bug fix and require that users now set their Issuer URL whenever they use Azure, meaning their tokens are actually veriifed rather than being blindly trusted. Unless there are serious objections from the Azure users on this thread, I will retrospectively add a breaking change note to the changelog saying that users are now required to set their OIDC Issuer URL to provide a more secure default.
For the second issue, it looks like we are trying to make a request to the Azure profile URL to gather more information because either the email or groups are not included in the ID Token. This one is confusing me a bit because the 400 implies we aren’t setting the correct header for authentication to Azure to fetch the profile URL, however, this is the request we have been making historically, this is the new request which should be identical.
Does anyone with access to azure have the ability to build a test image with some debug logging around these code areas to try and work out exactly what the issue is here? I’m wondering if it is because the default profile URL is for v1 tokens and the users seeing this issue are using the v2 issuer URL?
Could all in the thread please confirm if they are setting an issuer URL, what that is (obscured) and likewise with profile URL please?
There has been a very long time since the 7.2.1 release, so my main concern is security vulnerabilities in the container images, some of them critical. I would prefer an urgent bugfix to the borked 7.3.0 release.