-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Service Bus trigger using identity-based connection uses incorrect user identity when run locally #30961
Comments
Hi @ashtmMSFT, I would agree that the docs should be improved to specifically mention which settings map to which credential types and link to the docs for these credential types. We should also mention that if you don't specify any settings beyond the Uri (or only specify an incomplete set such as just the tenantId), we will fall back to DefaultAzureCredential. We should also link to the DefaultAzureCredential docs which mention the different supported environment variables. |
Hi @ashtmMSFT. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text “ |
Hi @ashtmMSFT. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text “ |
/unresolve Folks, I do greatly appreciate the response to the thread, but I don't think the issue is resolved. I would consider the issue resolved after discussion has concluded and at a minimum the documentation is updated. I linked the most relevant articles which would need updates in my original post. Please let me know if you have a different criteria for the issue being resolved. I would like to minimize the chance of another dev hitting this issue with identity-based connections, as it was the biggest pain point by far in seamlessly developing and sharing a small Functions proof of concept with my customer. We should make it as easy as possible for devs to build solutions with a workload identity story that doesn't introduce secrets. |
Hi @JoshLove-msft, thank you for the prompt reply. If what you are saying is true, that we are falling back to using a DefaultAzureCredential which first tries to use an EnvironmentCredential and recognize the AZURE_* environment variables, then my code should work if I specify AZURE_TENANT_ID, AZURE_USERNAME, and AZURE_PASSWORD values accordingly for user B in my local.settings.json. Unfortunately, this isn't the case: Revised Local Context -- Still Broken with AZURE_* Settings
I see the same error about an invalid token issuer. === Furthermore, if DefaultAzureCredential is being used and I were to specify no environment variables, shouldn't the identity context be picked up from either the user identity I used to login to VS Code (via the Azure Account extension) OR from AZ CLI (via my Revised Local Context -- Still Broken with VSCode or AZ CLI User Context
I see the same error about an invalid token issuer. === The Only Workaround That Does The Trick To reinforce an earlier point I made:
Am I misunderstanding something here? Does this imply a bug with DefaultAzureCredential? |
Do you have logging enabled in your function app via your local.settings.json file? This would help us determine which credential Identity is using. |
I was able to get additional logs by adding the I re-ran all the scenarios described above and was able to determine how the usage of DefaultAzureCredential (and all the underlying chained credentials) failed to match my expectations for its behavior. Rather than share logs and the exact type of credential ultimately used in each scenario above, I'll just highlight the points of confusion. The DefaultAzureCredential attempted to use the following credentials in this order on my machine: EnvironmentCredential, ManagedIdentityCredential, VisualStudioCredential, VisualStudioCodeCredential, AzureCliCredential. (Note the SharedTokenCacheCredential was never used despite being mentioned in the documentation.) EnvironmentCredential Unfortunately, specifying a (username, password, and tenantId) tuple via environment variables is not supported. If you specify a tenantId, the EnvironmentCredential assumes you are not using a username and password and will throw The table in the troubleshooting guide contains all valid tuples of AZURE_* environment variables that can be used for authentication. I suggest that we update the currently ambiguous EnvironmentCredential documentation to include this list of valid environment variable combinations. VisualStudioCredential This meant that most of the time my identity was unknowingly being pulled from VS and I never got to leverage the credentials further down the chain where I was logged in with the appropriate identity. Interestingly, if the AZURE_TENANT_ID environment variable is set when your code runs and it does not match the tenantId for the user with which you're logged into Visual Studio, VisualStudioCredential will try to authenticate your stored user identity against this specified tenant. In my case, I saw this: Triggering this failure was significant in my case because it meant a credential further down the chain (Azure CLI) would be used and succeed. VisualStudioCodeCredential Unfortunately, when you figure that out, it flat out doesn't work: The troubleshooting guide mentions that "it's a known issue that VisualStudioCodeCredential doesn't work with Azure Account extension versions newer than 0.9.11." Ouch. Great to know, but seeing as how this affects literally every fresh install of that extension, could we please publicize this information more broadly? The VisualStudioCodeCredential documentation and Azure Account extension pages are great candidates. === ASK |
Assigning to @christothes for his thoughts on what we can do to improve Identity docs. I will look into clarifying the functions docs. |
This is a good one for @scottaddie |
We've updated the behavior on the Azure Functions extensions side to respect the passed in tenantId, clientId, and resourceId even if we fall back to the DefaultAzureCredential. Removing myself from this issue as I believe all that remains is to improve Identity docs. |
Addressed in #31867 |
Library name and version
Microsoft.Azure.WebJobs.Extensions.ServiceBus 5.7.0
Describe the bug
I had a lot of trouble getting a managed identity to work correctly locally for a C# Azure Function with a Service Bus Queue-triggered binding on my devbox with VS Code. The problem seems to stem from the fact that the user identity being picked up at runtime is incorrect.
Context -- Local Tooling
code --version
== 1.70.2dotnet --version
== 6.0.400Context -- Cloud
Context -- Local Dev Workflow
az account show
, which shows me I am logged in as user A (associated with tenant A).az login
and login as user B.az account show
, which shows me I am now logged in as user B (associated with tenant B).code .
) in the folder with my Azure Functions project containing a Service Bus Queue-triggered function.The Error / Actual Behavior
When I run the code, I see this error spammed in the VS Code terminal:
The error message is indicative of the fact that the auth token presented to the Service Bus in tenant B was issued by tenant A.
In short, the ServiceBusConnection__tenantId setting does not seem to work.
The Fix / Expected Behavior
Instead, what did work, and what I only found thanks to this seemingly incorrectly closed Github issue, was specifying the id for tenant B in AZURE_TENANT_ID in local.settings.json.
After specifying this setting, the error went away, and the function was triggered by messages picked up from the queue.
It's not clear to me why this setting is needed, because if the user context is already being picked up from the VS Code extension OR the login done with Azure CLI, the proper tenant for that user should already be known.
At the very least, the documentation should be updated to reflect the need to specify the AZURE_TENANT_ID setting. If this approach is taken, please revise these documents:
Expected behavior
No error is seen and the function can be triggered by messages picked up from the queue.
Actual behavior
When I run the project that hosts the function, I see this error spammed in the VS Code terminal:
As best I can tell, this error message is indicative of the fact that the auth token presented to the Service Bus in tenant B was issued by tenant A.
In short, the ServiceBusConnection__tenantId setting does not seem to work.
Reproduction Steps
With a setup as described in the bug description, run the project to start the functions host with a SB queue-triggered function like the one below. Wait until you see the error spam.
Environment
code --version
== 1.70.2dotnet --version
== 6.0.400The text was updated successfully, but these errors were encountered: