@Arhanti Doshi Thanks for reply!
As you have Set up Managed Identity for the Web Apps for Containers below few points needs to be cross checked-
- The instructions only apply to Linux based containers configurations.
- Ensure Webapp and the Azure Container registry must be on the same azure subscription
- Important to note that - Accessing a container registry on a different subscription is currently not supported.
Further I am sharing detailed Steps for - Managed Identity can be enabled through the portal as well with the following steps. Please cross check-
In this case, System Assigned Identity is used - steps for User Assigned Identity will essentially be the same.
- Enable System Assigned Identity by turning the Status to "On" and then select "Yes" on the popup to enable it:
- Go to Deployment Center in the Azure Portal and enter the details needed - ensure that Authentication is set to Managed Identity:
- After successfully setting the image and authentication type from the portal, the AcrPull role should automatically be added to this identity. You can validate this by going to the Azure Portal -> Identity -> and click on Azure role assignments:
- At this point, the image pull should be successful - this can be validated in Application Logs. For troubleshooting, see the Troubleshooting section below.
Generate and assign the System Assigned Managed Identity-
- Below we generate and assign a System Assigned Managed Identity and configure the application to use the output principal (Object) ID.
az webapp identity assign --resource-group <group-name> --name <app-name> --query principalId --output tsv
NOTE: To assign an Identity to a slot, use the --slot parameter on az webapp identity assign. Review documentation usage here . - Grant the Identity access to the Azure Container Registry- Get the resource URI of your container registry by running the following command:
az acr show --resource-group <group-name> --name <registry-name> --query id --output tsv
- Next, we will grant this identity the 'pull' role on the targeted Azure Container Registry. In this case only the 'acrpull' role is assigned.
az role assignment create --assignee <principal-id> --scope <registry-resource-id> --role "AcrPull"
- Lastly, we configure the application to use the Managed Identity that we created and assigned to the application:
az webapp config set --resource-group <group-name> --name <app-name> --generic-configurations '{"acrUseManagedIdentityCreds": true}'
Through Deployment Center or the CLI, set the image and tag that needs to be pulled from Azure Container Registry. - More information on Azure Container Registry roles and permissions can be found here .
For Generating and assign the User Assigned Managed Identity
User Assigned identity steps are essentially the same. The below are commands to walk through how to create the identity, as seen here
Confirm this is working
To validate this is working ensure that 'Admin User' is disabled on the Azure Container Registry that is being targeted. After successfully enabling a Managed Identity in the above scenario - the DOCKER_REGISTRY_USERNAME and DOCKER_REGISTRY_PASSWORD are no longer needed if the Web App for Container was initially created with this.
Troubleshoot steps-
- In docker.log (and our platform logging like the Application Logs detector), a container with the name yourapp_0_000000_msiProxy will be created. This is the "token service" container that is used whenever a customer enabled Managed Identity.
- Ensure the Managed Identity being used actually has the AcrPull role assigned to it.
- Validate if the container is still using 'Admin User Credentials' against the Azure Container Registry.
- Under [resources.azure.com] ensure that the property acrManagedIdentityCreds for the application in question is not set to false.
- Check if the Managed Identity ObjectID visible in the portal under the Identity tab is the same one initially set up with to authenticate to ACR. If the prior Managed Identity was deleted or changed without updating the Web App for Container, this may cause an authentication error.
- If Azure Container Registry is set to only allow certain IP's but the pull is done over one that is not whitelisted
- If the App Service is VNET integrated (and the ACR has a Private Endpoint) but the App Service is not explicitly set to pull images through the VNET. In this case, the pull may happen over a public IP.
- A misconfigured VNET set up (as well on the ACR side)
Hope this helps- Please let us know if query remains.