Skip to content
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

EES-5480 - handling creation of container app managed identity and its role assignments in Bicep #5210

Conversation

duncan-at-hiveit
Copy link
Collaborator

This PR:

  • Adds the creation and the role assignments of the Container App managed identity into Bicep rather than being a manual task.

This is made possible now by the work of Mark Nelson to allow our DevOps SPNs to be able to assign a subset of common roles.

@duncan-at-hiveit duncan-at-hiveit force-pushed the EES-5480-adding-container-app-user-and-role-assignments-into-automation branch 5 times, most recently from fbe74e5 to ae4288b Compare September 3, 2024 09:20
Comment on lines 26 to 34
resource roleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid(containerRegistry.id, rolesToRoleIds[role], managedIdentitty.name)
scope: containerRegistry
properties: {
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', rolesToRoleIds[role])
principalId: managedIdentitty.properties.principalId
principalType: 'ServicePrincipal'
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could add a comment to mention that this is dependent on the deploying service principal having the Microsoft.Authorization/roleAssignments/write permission, such as being an Owner, User Access Administrator, or RBAC Administrator at the scope the role is being assigned, and that AcrPull has been allowed through role assignment conditions? I think there's only a small-ish set of roles been conditionally allowed which can be granted, AcrPull being one of them.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've added some comments to this effect thanks. I've also updated containerAppRoleAssignment.bicep to behave like keyVaultRoleAssignment.bicep for consistency (taking an array of principalIds).

Comment on lines 236 to 242
module acrPullRoleAssignmentModule 'components/containerRegistryRoleAssignment.bicep' = {
name: '${apiContainerAppManagedIdentityName}AcrPullRoleAssignmentDeploy'
params: {
role: 'AcrPull'
containerRegistryName: acrName
managedIdentityName: apiContainerAppManagedIdentity.name
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is the Api container's registry access so maybe it should include 'apiContainer' in the name in case another service/identity needs a similar role assignment? Something like apiContainerAcrPullRoleAssignment or apiContainerRegistryAccess rather than acrPullRoleAssignmentModule?

Could also think about grouping everything related to the Api container into a new app/apiContainer.bicep in future.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated to apiContainerAppAcrPullRoleAssignmentModule.

Also, I already have a ticket for better modularising the Bicep as a whole - https://dfedigital.atlassian.net/browse/EES-5479. I think this should be done prior to deploying to Test.

name: containerRegistryName
}

resource managedIdentitty 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' existing = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Spelling mistake in the name here and where it's referenced below

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed anyhow, but nicely spotted thanks.

…s AcrPull role assignment from within Bicep, now that we have permission to grant these ourselves.
…tations around role assignments. Better naming and consistency in role assignment modules.
@duncan-at-hiveit duncan-at-hiveit force-pushed the EES-5480-adding-container-app-user-and-role-assignments-into-automation branch from 202abe6 to 909c0bf Compare September 4, 2024 10:02
@duncan-at-hiveit duncan-at-hiveit merged commit 77b8cf8 into dev Sep 4, 2024
2 of 7 checks passed
@duncan-at-hiveit duncan-at-hiveit deleted the EES-5480-adding-container-app-user-and-role-assignments-into-automation branch September 4, 2024 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants