2

I was trying to collect the List of Deny Assignments present in a particular tenant, so I passed the required arguments here:

tenant_id = arguments['tenant_id']
client_id = arguments['client_id']
client_secret = arguments['client_secret']

I created ClientSecretCredentials here:

csc = ClientSecretCredential(tenant_id=tenant_id,
                             client_id=client_id,
                             client_secret=client_secret)

From some other code, I have received a list of subscription IDs:

for subscription_id in subscription_id_list:
    resource_client = authenticate.resource_client(subscription_id)
    resources_groups = get_all_resource_groups_detail(resource_client)

I am able to get resourceGroups in that subscription id using this code:

    amc = AuthorizationManagementClient(csc, subscription_id)
    for resource_group in resources_groups:
        denylocks = amc.deny_assignments.list_for_resource_group(resource_group)
        try:

Here, it creates an error (denylocks); I am getting:

<azure.mgmt.authorization.v2018_07_01_preview.models._paged_models.DenyAssignmentPaged object>

When I loop over the list of that object, it gives the error

:ERROR 'ClientSecretCredential' object has no attribute 'signed_session'

for locks in denylocks:
    print(locks)
    except Exception as exc:
    logger.error(exc)
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
gnsharans
  • 21
  • 3

2 Answers2

3

'ClientSecretCredential' object has no attribute 'signed_session'

To resolve above error, according to documentation:

  • A client expecting an azure-common credential will raise an error like 'ClientSecretCredential' object has no attribute 'signed_session' when given an azure-identity credential.

So, try following code snippet according to documentation:

  • azure-common uses ServicePrincipalCredentials to authenticate a service principal:
from azure.common.credentials import ServicePrincipalCredentials

credential = ServicePrincipalCredentials(client_id, client_secret, tenant=tenant_id)

Alternatively, you can upgrade azure.mgmt.authorization to the latest version and continue using ClientSecretCredential of azure-identity.

Ecstasy
  • 1,866
  • 1
  • 9
  • 17
1

It's because of the azure.mgmt.resource package, its latest version have some issue.

Try the following command:
pip install azure.mgmt.resource==21.2.1

colinD
  • 1,641
  • 1
  • 20
  • 22
ramendra
  • 11
  • 1