I’m newbie to azure, trying to list the repositories in azure container registry using client id, tenant id, secret using below code.
from azure.containerregistry import ContainerRegistryClient
from azure.identity import ClientSecretCredential
registry_name = "test1"
resource_group = "donieee"
app_id="xxxxx"
secret="xxxxxxx"
tenantid="xxxxxx"
credential = ClientSecretCredential(client_id=app_id,client_secret=secret,tenant_id=tenantid)
# Create a client object for the ACR
client = ContainerRegistryClient(
endpoint=f"{registry_name}.azurecr.io",
credential=credential
)
repositories = client.list_repository_names()
for repo in repositories:
print(repo)
getting below error azure.core.exceptions.ClientAuthenticationError: Operation returned an invalid status ‘Unauthorised’
Kindly suggest me answer.
I tried in my environment and got the same error:
The above error occurs when your application doesn't have the proper role to list the repositories.
Note: According to MS-DOCS to list the respositories you need either
ACR pull
role orContributor
role required.
On my side, I have assigned the role to the application and run the same code it is listing the repositories.
Code:
from azure.containerregistry import ContainerRegistryClient
from azure.identity import ClientSecretCredential
registry_name = "test1"
resource_group = "donieee"
app_id="xxxxx"
secret="xxxxxxx"
tenantid="xxxxxx"
credential = ClientSecretCredential(client_id=app_id,client_secret=secret,tenant_id=tenantid)
# Create a client object for the ACR
client = ContainerRegistryClient(
endpoint=f"{registry_name}.azurecr.io",
credential=credential
)
repositories = client.list_repository_names()
for repo in repositories:
print(repo)
In my portal, I have some repositories in my Azure container registry like as below.
Portal:
Output: