Skip to content

Conversation

@eerhardt
Copy link
Member

@eerhardt eerhardt commented Mar 18, 2025

Description

We currently don't support an easy API for modifying the role assignments on database resources. There are no role types that can be used from the Azure.Provisioning libraries today. So for now we will just move our existing role assignments to the ACA roles bicep module.

To support database resources, we add a new virtual method on AzureProvisioningResource - AddRoleAssignments passing in a context object containing the information on the role assignments to add.

Also needed to split all role assignments out of the {app}-roles bicep module because of an issue with CosmosDB failing if the role assignment is added in the same bicep file as the managed identity it is pointing to. This simplifies the code because the role assignment generation is the same whether the resource is existing or not.

Contributes to #6161
Fix #8142

Checklist

  • Is this feature complete?
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Ongoing
  • Does the change require an update in our Aspire docs?

@eerhardt eerhardt requested review from captainsafia, Copilot and davidfowl and removed request for Copilot March 18, 2025 15:34
@github-actions github-actions bot added the area-integrations Issues pertaining to Aspire Integrations packages label Mar 18, 2025
…dentity

We currently don't support an easy API for modifying the role assignments on database resources. There are no role types that can be used from the Azure.Provisioning libraries today. So for now we will just move our existing role assignments to the ACA roles bicep module.

To support database resources, we add a new annotation "RoleAssignmentCustomizationAnnotation" which contains a callback that the resource can implement to inject the role assignment objects into the Azure bicep infrastructure.

Contributes to dotnet#6161
@eerhardt eerhardt force-pushed the AzureDatabaseRoleAssignments2 branch from b356d30 to a1caca5 Compare March 18, 2025 18:48
… role assignments to applied role assignments even when empty. Add test to ensure.

- Update playground manifests
- Fix tests
This works around an issue with CosmosDB where creating a managed identity and assigning a CosmosDB role assignment in the same bicep module fails.
Copy link
Member

@captainsafia captainsafia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good given the gnarliness you had to work around with the way role assignments are managed for these resource types.

Add a new virtual method on AzureProvisioningResource to add role assignments. This method is overriden in database resources (like CosmosDB and Redis) to customize how the role assignments are created.
@captainsafia captainsafia self-requested a review March 19, 2025 19:06
@eerhardt
Copy link
Member Author

@davidfowl @captainsafia - I believe this is now ready for review.

Copy link
Member

@captainsafia captainsafia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Reads much easier than the annotations-based implementation. 😅

var resource = new AzureCosmosDBResource(name, ConfigureCosmosDBInfrastructure);
return builder.AddResource(resource);
return builder.AddResource(resource)
.WithAnnotation(new DefaultRoleAssignmentsAnnotation(new HashSet<RoleDefinition>()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does an empty DefaultRoleAssignmentsAnnotation actually help us achieve here? This is just here to pass through to AppliedRoleAssignmentsAnnotation in the non-ACA scenario, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one part that I'm not super excited about, and would like some feedback on.

This is just here to pass through to AppliedRoleAssignmentsAnnotation in the non-ACA scenario, right?

No, this works for both ACA and non-ACA.

  • You're right that in non-ACA scenarios this turns into an AppliedRoleAssignmentsAnnotation, which will inject the contributor role into the cosmos resource's bicep.
  • In ACA scenarios, the AzureResourcePreparer will copy the DefaultRoleAssignmentsAnnotation to a regular (empty) RoleAssignmentAnnotation, which will cause the role to be written to the role bicep file.

One thought I had was to make up a "fake" contributor/admin RoleDefinition with a random Guid, and check for that in both places. But just having the empty one serves the purposes I need it to.

Thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In ACA scenarios, the AzureResourcePreparer will copy the DefaultRoleAssignmentsAnnotation to a regular (empty) RoleAssignmentAnnotation, which will cause the role to be written to the role bicep file.

Ah, I see where this happens.

Thoughts?

IMO, an empty one feels better than a fake role assignment. We clarified in an offline discussion why we need DefaultRoleAssignments vs RoleAssignment here.

@eerhardt
Copy link
Member Author

eerhardt commented Mar 20, 2025

Merging now because this change and #8171 will conflict. So merging will help avoid conflicts now.

I address the above feedback in Follow up on database role assignments (dotnet/aspire#8212)

@eerhardt eerhardt merged commit 272798c into dotnet:main Mar 20, 2025
166 checks passed
@eerhardt eerhardt deleted the AzureDatabaseRoleAssignments2 branch March 20, 2025 13:50
eerhardt added a commit to eerhardt/aspire that referenced this pull request Mar 20, 2025
Adding role assignment support for PostgreSQL following the pattern set in dotnet#8140

Contributes to dotnet#6161
eerhardt added a commit to eerhardt/aspire that referenced this pull request Mar 20, 2025
eerhardt added a commit that referenced this pull request Mar 20, 2025
eerhardt added a commit to eerhardt/aspire that referenced this pull request Mar 20, 2025
davidfowl pushed a commit that referenced this pull request Mar 20, 2025
eerhardt added a commit to eerhardt/aspire that referenced this pull request Mar 20, 2025
Adding role assignment support for PostgreSQL following the pattern set in dotnet#8140

Contributes to dotnet#6161
eerhardt added a commit to eerhardt/aspire that referenced this pull request Mar 20, 2025
…tity

Adding role assignment support for PostgreSQL following the pattern set in dotnet#8140

Fix dotnet#6161
eerhardt added a commit that referenced this pull request Mar 21, 2025
…tity (#8226)

* Support Azure SqlServer role assignments on app specific managed identity

Adding role assignment support for PostgreSQL following the pattern set in #8140

Fix #6161

* Update playground manifest
eerhardt added a commit to eerhardt/aspire that referenced this pull request Mar 21, 2025
Adding role assignment support for PostgreSQL following the pattern set in dotnet#8140

Contributes to dotnet#6161
eerhardt added a commit that referenced this pull request Mar 21, 2025
…8209)

* Support PostgreSQL role assignments on app specific managed identity

Adding role assignment support for PostgreSQL following the pattern set in #8140

Contributes to #6161

* Fix publisher tests

* Add ACA RunMode test
@github-actions github-actions bot locked and limited conversation to collaborators Apr 20, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-integrations Issues pertaining to Aspire Integrations packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AsExisting to a Redis resource doesn't create a unique access policy name

3 participants