Azure / Azure/azure-cli-extensions

az containerapp create not respecting existing user-managed identity and unnecessarily erroring trying to assign permissions

Open
#9,175 4 comments 0 reactions 0 assignees View on GitHub
Auto-Assign bug ContainerApp customer-reported Service Attention
Dominant language
Python
Stars
454
Forks
1.7k
Avg merge
2d 19h
Merged PRs (30d)
64

Description

### Describe the bug

I'm trying to deploy an Azure Functions app to Azure Container Apps using the CLI with the ACA app pulling from ACR using a user managed identity. The create works under my account, but not the GitHub Action OIDC as the credential does not have permissions granting roles.

The [docs](https://learn.microsoft.com/en-us/cli/azure/containerapp?view=azure-cli-latest#az-containerapp-create:~:text=False-,%2D%2Dregistry%2Didentity,-A%20Managed%20Identity) say (bold for my emphasis)
> --registry-identity
> A Managed Identity to authenticate with the registry server instead of username/password. Use a resource ID or 'system' for user-defined and system-defined identities, respectively. The registry must be an ACR. **If possible**, an 'acrpull' role assignemnt will be created for the identity automatically.

Giving it a resource ID for user-defined is prompting it to try creating an acrpull role assignment and fail the command entirely because of the lack of permissions but it should be optional to assign permissions.

### Related command

az containerapp create

[ghaction.yml](https://github.com/user-attachments/files/22390761/ghaction.yml)

### Errors

```
azure.cli.core.azclierror.UnauthorizedError: Role assignment failed with error message: "(AuthorizationFailed)
The client 'guidA' with object id 'guidA' does not have authorization to perform action 'Microsoft.Authorization/roleAssignments/write' over scope '/subscriptions/***/resourceGroups/***/providers/Microsoft.ContainerRegistry/registries/***acr4s45c/providers/Microsoft.Authorization/roleAssignments/e22609a6-f847-4c09-b15c-1134dadbbb00' or the scope is invalid. If access was recently granted, please refresh your credentials.

Code: AuthorizationFailed
```

[debuglogs.txt](https://github.com/user-attachments/files/22390758/debuglogs.txt)

### Issue script & Debug output

[ghaction.yml](https://github.com/user-attachments/files/22390761/ghaction.yml)
[debuglogs.txt](https://github.com/user-attachments/files/22390758/debuglogs.txt)

```
az extension add -n containerapp --upgrade --allow-preview true
az version
az containerapp create --debug --name ${{ env.ACA }} \
--resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} \
--environment ${{ env.ACA_ENV }} \
--kind 'functionapp' \
--image ${{ env.IMAGE }} --container-name api \
--cpu 0.5 --memory 1Gi \
--ingress 'external' --target-port 80 \
--registry-server ${{ env.ACR }} \
--user-assigned ${{ secrets.ACA_USER_ASSIGNED }} \
--secrets azure-sql-connection-string=${{ env.DB_CONN }}
```

secrets.ACA_USER_ASSIGNED like /subscriptions/<>/resourcegroups/<>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<>

### Expected behavior

The create statement should use the user-managed identity and when it cannot assign permissions proceed to attach the user-maanged identity anyway, enabling the script to succeed.

### Environment Summary

{
"azure-cli": "2.77.0",
"azure-cli-core": "2.77.0",
"azure-cli-telemetry": "1.1.0",
"extensions": {
"containerapp": "1.2.0b3"
}
}

### Additional context

_No response_

[ghaction.yml](https://github.com/user-attachments/files/22390785/ghaction.yml)
[debuglogs.txt](https://github.com/user-attachments/files/22390784/debuglogs.txt)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.