Skip to content

Commit 6ee3670

Browse files
authored
Merge pull request #5619 from nawazkh/add_comments
Add explanatory comments
1 parent d3c0f03 commit 6ee3670

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

scripts/aks-as-mgmt.sh

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ export SKIP_AKS_CREATE="${SKIP_AKS_CREATE:-false}"
5757

5858
main() {
5959

60+
# if using SKIP_AKS_CREATE=true, skip creating the AKS cluster
61+
if [[ "${SKIP_AKS_CREATE}" == "true" ]]; then
62+
echo "Skipping AKS cluster creation"
63+
return
64+
fi
65+
6066
echo "--------------------------------"
6167
echo "MGMT_CLUSTER_NAME: $MGMT_CLUSTER_NAME"
6268
echo "AKS_RESOURCE_GROUP: $AKS_RESOURCE_GROUP"
@@ -90,12 +96,6 @@ main() {
9096
echo "AZURE_USER_ASSIGNED_IDENTITY_RESOURCE_ID: ${AZURE_USER_ASSIGNED_IDENTITY_RESOURCE_ID:-}"
9197
echo "--------------------------------"
9298

93-
# if using SKIP_AKS_CREATE=true, skip creating the AKS cluster
94-
if [[ "${SKIP_AKS_CREATE}" == "true" ]]; then
95-
echo "Skipping AKS cluster creation"
96-
return
97-
fi
98-
9999
create_aks_cluster
100100
set_env_variables
101101
}
@@ -226,14 +226,22 @@ create_aks_cluster() {
226226
export MANAGED_IDENTITY_RG
227227
echo "mgmt resource identity resource group: ${MANAGED_IDENTITY_RG}"
228228

229-
echo "assigning contributor role to the service principal"
229+
230+
echo "assigning contributor role to managed identity over the $AZURE_SUBSCRIPTION_ID subscription"
231+
# Note: Even though --assignee-principal-type ServicePrincipal is specified, this does not mean that the role assignment is for a secret of type service principal.
232+
# Creating a role assignment for a managed identity using other assignee-principal-type from (Group, User, ForeignGroup) will lead to RBAC error.
233+
# To avoid RBAC error, we need to assign the role to the managed identity using the --assignee-principal-type ServicePrincipal.
234+
# refer: https://learn.microsoft.com/en-us/azure/role-based-access-control/troubleshooting?tabs=bicep#symptom---assigning-a-role-to-a-new-principal-sometimes-fails
230235
until az role assignment create --assignee-object-id "${AKS_MI_OBJECT_ID}" --role "Contributor" \
231236
--scope "/subscriptions/${AZURE_SUBSCRIPTION_ID}" --assignee-principal-type ServicePrincipal --output none \
232237
--only-show-errors; do
233-
echo "retrying to assign role to the service principal"
238+
echo "retrying to assign contributor role"
234239
sleep 5
235240
done
236241

242+
# Set the ASO_CREDENTIAL_SECRET_MODE to podidentity to
243+
# use the client ID of the managed identity created by AKS for authentication
244+
# refer: https://github.com/Azure/azure-service-operator/blob/190edf60f1d84da7ae4ee5c4df9806068c0cd982/v2/internal/identity/credential_provider.go#L279-L301
237245
echo "using ASO_CREDENTIAL_SECRET_MODE as podidentity"
238246
ASO_CREDENTIAL_SECRET_MODE="podidentity"
239247
}

0 commit comments

Comments
 (0)