22# Licensed under the MIT License.
33#! /usr/bin/env bash
44
5- # set -ux # uncomment this line to debug
5+ set -ux # uncomment this line to debug
66
77aksNamespace=" graphrag"
88
@@ -297,6 +297,16 @@ getAksCredentials () {
297297 printf " Getting AKS credentials... "
298298 az aks get-credentials -g $rg -n $aks --overwrite-existing 2>&1
299299 exitIfCommandFailed $? " Error getting AKS credentials, exiting..."
300+ kubelogin convert-kubeconfig -l azurecli
301+ exitIfCommandFailed $? " Error logging into AKS, exiting..."
302+ # get principal/object id of the signed in user
303+ local principalId=$( az ad signed-in-user show --output json | jq -r .id)
304+ exitIfValueEmpty $principalId " Principal ID of deployer not found"
305+ # assign "Azure Kubernetes Service RBAC Admin" role to deployer
306+ local scope=$( az aks show --resource-group $rg --name $aks --query " id" -o tsv)
307+ exitIfValueEmpty " $scope " " Unable to get AKS scope, exiting..."
308+ az role assignment create --role " Azure Kubernetes Service RBAC Cluster Admin" --assignee-object-id $principalId --scope $scope
309+ exitIfCommandFailed $? " Error assigning 'Azure Kubernetes Service RBAC Cluster Admin' role to deployer, exiting..."
300310 kubectl config set-context $aks --namespace=$aksNamespace
301311 printf " Done\n"
302312}
@@ -326,6 +336,9 @@ deployAzureResources () {
326336 echo " Deploying Azure resources..."
327337 local SSH_PUBLICKEY=$( jq -r .publicKey <<< $SSHKEY_DETAILS )
328338 exitIfValueEmpty " $SSH_PUBLICKEY " " Unable to read ssh publickey, exiting..."
339+ # get principal/object id of the signed in user
340+ local deployerPrincipalId=$( az ad signed-in-user show --output json | jq -r .id)
341+ exitIfValueEmpty $deployerPrincipalId " Principal ID of deployer not found"
329342 local datetime=" ` date +%Y-%m-%d_%H-%M-%S` "
330343 local deployName=" graphrag-deploy-$datetime "
331344 echo " Deployment name: $deployName "
@@ -342,6 +355,7 @@ deployAzureResources () {
342355 --parameters " publisherEmail=$PUBLISHER_EMAIL " \
343356 --parameters " enablePrivateEndpoints=$ENABLE_PRIVATE_ENDPOINTS " \
344357 --parameters " acrName=$CONTAINER_REGISTRY_NAME " \
358+ --parameters " deployerPrincipalId=$deployerPrincipalId " \
345359 --output json)
346360 # errors in deployment may not be caught by exitIfCommandFailed function so we also check the output for errors
347361 exitIfCommandFailed $? " Error deploying Azure resources..."
@@ -579,7 +593,7 @@ grantDevAccessToAzureResources() {
579593
580594 # get principal/object id of the signed in user
581595 local principalId=$( az ad signed-in-user show --output json | jq -r .id)
582- exitIfValueEmpty $principalId " Principal ID not found"
596+ exitIfValueEmpty $principalId " Principal ID of deployer not found"
583597
584598 # assign storage account roles
585599 local storageAccountName=$( az storage account list --resource-group $RESOURCE_GROUP --output json | jq -r .[0].name)
0 commit comments