You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
az login --identity --client-id ${managedIdentityClientId}
30
+
else
31
+
echo"Authenticating with Azure CLI..."
32
+
az login
33
+
fi
34
+
echo"Not authenticated with Azure. Attempting to authenticate..."
35
+
fi
28
36
29
-
echo"Script Started"
37
+
echo"Getting signed in user id"
38
+
signed_user_id=$(az ad signed-in-user show --query id -o tsv)
39
+
40
+
echo"Getting storage account resource id"
41
+
storage_account_resource_id=$(az storage account show --name $storageAccount --query id --output tsv)
42
+
43
+
# ✅ Assign Storage Blob Data Contributor role (if not already assigned)
44
+
echo"Checking if user has the Storage Blob Data Contributor role"
45
+
storage_role_assignment=$(az role assignment list --assignee $signed_user_id --role "Storage Blob Data Contributor" --scope $storage_account_resource_id --query "[].roleDefinitionId" -o tsv)
46
+
47
+
if [ -z"$storage_role_assignment" ];then
48
+
echo"Assigning Storage Blob Data Contributor role..."
49
+
az role assignment create --assignee $signed_user_id --role "Storage Blob Data Contributor" --scope $storage_account_resource_id --output none
50
+
echo"Role assignment for Blob Storage completed."
51
+
else
52
+
echo"User already has Storage Blob Data Contributor role."
53
+
fi
54
+
55
+
# ✅ Assign Key Vault Secrets User role (NEW BLOCK)
56
+
echo"Getting Key Vault resource ID"
57
+
key_vault_resource_id=$(az keyvault show --name $keyVaultName --query id --output tsv)
58
+
59
+
echo"Checking if user has Key Vault Secrets User role"
60
+
kv_role_assignment=$(az role assignment list --assignee $signed_user_id --role "Key Vault Secrets User" --scope $key_vault_resource_id --query "[].roleDefinitionId" -o tsv)
61
+
62
+
if [ -z"$kv_role_assignment" ];then
63
+
echo"Assigning Key Vault Secrets User role..."
64
+
az role assignment create --assignee $signed_user_id --role "Key Vault Secrets User" --scope $key_vault_resource_id --output none
65
+
echo"Role assignment for Key Vault completed."
66
+
else
67
+
echo"User already has Key Vault Secrets User role."
68
+
fi
30
69
31
-
# Authenticate with Azure using managed identity
32
-
az login --identity --client-id ${managedIdentityClientId}
33
-
# Using az storage blob upload-batch to upload files with managed identity authentication, as the az storage fs directory upload command is not working with managed identity authentication.
0 commit comments