I have a StorageManagementClient
object authenticated with a service account. How do I get the creators of storage accounts listed in storage_client.storage_accounts.list()
?
How do I get the creator of a storage account in Azure?
The creator of a storage account is not directly exposed by the Azure Storage service. There isn't any creator-specific attribute in the storage account resource directly. A specific way to obtain the creator information isn't provided by the Storage Management API, which gets used by the StorageManagementClient
in the Azure SDK for Python.
If you need to get the creator using Python while creating a storage account you need to add the tag with CreatedBy:venkat
once you added it, you can retrieve it with tags.
Code:
from azure.identity import DefaultAzureCredential
from azure.mgmt.storage import StorageManagementClient
subscription_id = ""
credential = DefaultAzureCredential()
storage_client = StorageManagementClient(credential, subscription_id)
# Get the storage account properties
storage_account = storage_client.storage_accounts.list()
for storageaccount in storage_account:
print(storageaccount.name)
print(storageaccount.tags)
Output:
Alter, you can use the log analytic workspace to get the logs who Creates or update the storage account
by using below query.
Query:
AzureActivity
|where OperationName == "Create/Update Storage Account"
|where OperationNameValue == "Microsoft.Storage/storageAccounts/write"
|where ActivityStatus == "Succeeded"
|project Caller, ResourceId
Output:
Note: Limitation: Activity Log has a fixed retention period of 90 days
Reference: How can I get a report of who created resources in Azure Analytics? - Microsoft Q&A