-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: storage account 403 error when creating new tre env #4406
Open
ShakutaiGit
wants to merge
6
commits into
main
Choose a base branch
from
fix-sa-bootstrap-err
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3c407d7
Refactor role assignment check to validate both "Storage Blob Data Co…
ShakutaiGit bdb0886
Remove unused script source from bootstrap.sh
ShakutaiGit c421afb
Refactor role assignment check to use local variables for clarity
ShakutaiGit 52598a6
Update CHANGELOG and add role assignment for Storage Account Contribu…
ShakutaiGit 1094118
Refactor role assignment check to use counts for validation and strea…
ShakutaiGit 4c26cde
Refactor role assignment check to use non-empty value validation and …
ShakutaiGit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,33 +28,55 @@ else | |
az storage account show --resource-group "$TF_VAR_mgmt_resource_group_name" --name "$TF_VAR_mgmt_storage_account_name" --output table | ||
fi | ||
|
||
# shellcheck disable=SC1091 | ||
source ../scripts/mgmtstorage_enable_public_access.sh | ||
|
||
# Grant user blob data contributor permissions | ||
echo -e "\n\e[34m»»» 🔑 \e[96mGranting Storage Blob Data Contributor role to the current user\e[0m..." | ||
if [ -n "${ARM_CLIENT_ID:-}" ]; then | ||
USER_OBJECT_ID=$(az ad sp show --id "$ARM_CLIENT_ID" --query id --output tsv) | ||
else | ||
USER_OBJECT_ID=$(az ad signed-in-user show --query id --output tsv) | ||
fi | ||
|
||
az role assignment create --assignee "$USER_OBJECT_ID" \ | ||
--role "Storage Account Contributor" \ | ||
--scope "/subscriptions/$ARM_SUBSCRIPTION_ID/resourceGroups/$TF_VAR_mgmt_resource_group_name/providers/Microsoft.Storage/storageAccounts/$TF_VAR_mgmt_storage_account_name" | ||
|
||
az role assignment create --assignee "$USER_OBJECT_ID" \ | ||
--role "Storage Blob Data Contributor" \ | ||
--scope "/subscriptions/$ARM_SUBSCRIPTION_ID/resourceGroups/$TF_VAR_mgmt_resource_group_name/providers/Microsoft.Storage/storageAccounts/$TF_VAR_mgmt_storage_account_name" | ||
|
||
# Function to check if the role assignment exists | ||
check_role_assignment() { | ||
az role assignment list --assignee "$USER_OBJECT_ID" --role "Storage Blob Data Contributor" --scope "/subscriptions/$ARM_SUBSCRIPTION_ID/resourceGroups/$TF_VAR_mgmt_resource_group_name/providers/Microsoft.Storage/storageAccounts/$TF_VAR_mgmt_storage_account_name" --query "[].id" --output tsv | ||
check_role_assignments() { | ||
local sbdc | ||
sbdc=$(az role assignment list \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion from copilot, not tested, but makes sense to have a timeout of some sort...
|
||
--assignee "$USER_OBJECT_ID" \ | ||
--role "Storage Blob Data Contributor" \ | ||
--scope "/subscriptions/$ARM_SUBSCRIPTION_ID/resourceGroups/$TF_VAR_mgmt_resource_group_name/providers/Microsoft.Storage/storageAccounts/$TF_VAR_mgmt_storage_account_name" \ | ||
--query "[].id" --output tsv) | ||
|
||
local sac | ||
sac=$(az role assignment list \ | ||
--assignee "$USER_OBJECT_ID" \ | ||
--role "Storage Account Contributor" \ | ||
--scope "/subscriptions/$ARM_SUBSCRIPTION_ID/resourceGroups/$TF_VAR_mgmt_resource_group_name/providers/Microsoft.Storage/storageAccounts/$TF_VAR_mgmt_storage_account_name" \ | ||
--query "[].id" --output tsv) | ||
|
||
# Return a non-empty value only if both roles are assigned | ||
if [[ -n "$sbdc" && -n "$sac" ]]; then | ||
echo "both" | ||
fi | ||
} | ||
|
||
# Wait for the role assignment to be applied | ||
echo -e "\n\e[34m»»» ⏳ \e[96mWaiting for role assignment to be applied\e[0m..." | ||
while [ -z "$(check_role_assignment)" ]; do | ||
while [ -z "$(check_role_assignments)" ]; do | ||
echo "Waiting for role assignment..." | ||
sleep 10 | ||
done | ||
echo "Role assignment applied." | ||
|
||
# shellcheck disable=SC1091 | ||
source ../scripts/mgmtstorage_enable_public_access.sh | ||
ShakutaiGit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Blob container | ||
# shellcheck disable=SC2154 | ||
az storage container create --account-name "$TF_VAR_mgmt_storage_account_name" --name "$TF_VAR_terraform_state_container_name" --auth-mode login -o table | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you work out why this is required? I thought the object ID that creates the storage account should have sufficient permissions?