Fix Azure Functions Role Assignments to Host Storage#8290
Merged
eerhardt merged 2 commits intomicrosoft:mainfrom Mar 25, 2025
Merged
Fix Azure Functions Role Assignments to Host Storage#8290eerhardt merged 2 commits intomicrosoft:mainfrom
eerhardt merged 2 commits intomicrosoft:mainfrom
Conversation
With microsoft#8127, a mistake was made in that WithRoleAssignments only works if the app is using ACA infrastructure. If the app isn't using our ACA infrastructure, WithRoleAssignments throws an exception at startup. To make Azure Functions work correctly both with and without ACA infrastructure we use the internal WithDefaultRoleAssignments method to set the default role assignments on the Host Storage, which will be respected for both.
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes the role assignment issue for Azure Functions host storage so that default role assignments are applied when not using ACA infrastructure. The changes adjust how storage resources are created and update tests to reflect the correct built-in role assignments.
- Updated storage resource creation to use WithDefaultRoleAssignments when the storage resource is null.
- Removed the block that removed role assignments for explicit storage resources.
- Updated test resources to match the expected built-in role IDs and resource names.
Reviewed Changes
Copilot reviewed 2 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Aspire.Hosting.Azure.Functions/AzureFunctionsProjectResourceExtensions.cs | Change storage creation logic to conditionally add default role assignments without removing explicit role assignments. |
| tests/Aspire.Hosting.Azure.Tests/AzureFunctionsTests.cs | Swapped test resource names and role definition IDs to match updated role assignments. |
Files not reviewed (2)
- playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.AppHost/aspire-manifest.json: Language not supported
- src/Aspire.Hosting.Azure.Functions/Aspire.Hosting.Azure.Functions.csproj: Language not supported
Comments suppressed due to low confidence (2)
src/Aspire.Hosting.Azure.Functions/AzureFunctionsProjectResourceExtensions.cs:49
- The new conditional block applies default role assignments only when storage is implicitly created. Please verify that this change does not lead to unintended role conflicts when an explicit storage resource is provided.
if (storage is null)
tests/Aspire.Hosting.Azure.Tests/AzureFunctionsTests.cs:315
- The role assignment resource names and roleDefinition IDs have been swapped relative to previous tests. Ensure that the intended built-in role (StorageTableDataContributor vs StorageQueueDataContributor) is consistently referenced between the code and tests.
resource funcstorage634f8_StorageTableDataContributor 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
src/Aspire.Hosting.Azure.Functions/AzureFunctionsProjectResourceExtensions.cs
Show resolved
Hide resolved
captainsafia
approved these changes
Mar 25, 2025
Contributor
captainsafia
left a comment
There was a problem hiding this comment.
Thanks for adding the test!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
With #8127, a mistake was made in that WithRoleAssignments only works if the app is using ACA infrastructure. If the app isn't using our ACA infrastructure, WithRoleAssignments throws an exception at startup.
To make Azure Functions work correctly both with and without ACA infrastructure we use the internal WithDefaultRoleAssignments method to set the default role assignments on the Host Storage, which will be respected for both.
Checklist