Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save brandonmartinez/98bf2dc782c6c3dc56e24e08851bf5eb to your computer and use it in GitHub Desktop.
Save brandonmartinez/98bf2dc782c6c3dc56e24e08851bf5eb to your computer and use it in GitHub Desktop.
Disables shared key access on all storage accounts in the given subscription.
#!/usr/bin/env bash
# Be sure to run az login before running
# run this script with a single parameter which is the subscription ID
# Exit if SUBSCRIPTION_ID is empty
if [ -z "$1" ]; then
echo "Please provide a valid subscription ID as the first parameter."
exit 1
fi
# Get the subscription ID
SUBSCRIPTION_ID="$1"
# We want all resource groups; clear if there's a default, but also set subscription ID
az configure --defaults group=""
az account set --subscription "$SUBSCRIPTION_ID"
# List all storage accounts in the subscription
STORAGE_ACCOUNTS=$(az storage account list --query [].name -o tsv)
echo $STORAGE_ACCOUNTS
# Loop through each storage account and turn off shared key access
for STORAGE_ACCOUNT in $STORAGE_ACCOUNTS
do
echo "Turning off shared key access for $STORAGE_ACCOUNT"
az storage account update --name $STORAGE_ACCOUNT --allow-shared-key-access false
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment