azureauthorizationazure-container-registry

Regenerate ACR access key using Rest API received Unauthorized


The issue is we cannot regenerate ACR access key using ACR rest API Registries - Regenerate Credential - REST API (Azure Container Registry) | Microsoft Learn

Throwing exception Microsoft.Azure.Deployment.Express.Server.Common.Management.AzureResourceManagementException: Failed to regenerate Password: 'password'. HttpStatusCode 'Forbidden', Reason phrase:'Forbidden' and Content:'{"error":{"code":"AuthorizationFailed","message":"The client 'xxxxxxxxxxxxxxx' with object id 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx' does not have authorization to perform action 'Microsoft.ContainerRegistry/registries/regenerateCredential/action' over scope '/subscriptions/xxxxxxxxxxxxx/resourceGroups/xxxxxxxxxxxxxxxxx/providers/Microsoft.ContainerRegistry/registries/xxxxxxxxxxxx' or the scope is invalid. If access was recently granted, please refresh your credentials."}}'

Expect to not receive the unauthorized issue


Solution

  • Regenerate ACR access key using Rest API received Unauthorized

    The error you encountered is due to invalid permissions. To regenerate an ACR access key, you may need one of the following roles to perform that action.

    enter image description here

    REST API details

    In my case, I have the Owner role at the subscription level.

    enter image description here

    Response:

    enter image description here

    After executing the REST API, the ACR password was successfully regenerated.

    enter image description here

    Reference: Registries - Regenerate Credential