Skip to content
This repository was archived by the owner on May 27, 2025. It is now read-only.

Commit db74536

Browse files
committed
enable entra id authentication with AKS
1 parent ba3be1b commit db74536

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

docker/Dockerfile-backend

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ RUN cd backend \
2020
# download all nltk data that graphrag requires
2121
RUN python -m nltk.downloader punkt averaged_perceptron_tagger maxent_ne_chunker words wordnet
2222

23-
# Note: we temporarily patch the adlfs library to enable use of managed identity. A PR has been submitted to the adlfs library.
24-
# See https://github.com/fsspec/adlfs/pull/480
25-
# TODO: remove this once PR has been merged and a new version released
26-
RUN sed -i '/self.credential = credential/a\ \ \ \ \ \ \ \ if kwargs.get("account_host"): self.account_host = kwargs.get("account_host")' /usr/local/lib/python3.10/site-packages/adlfs/spec.py
27-
2823
WORKDIR /backend
2924
EXPOSE 80
3025
CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "80"]

infra/core/aks/aks.bicep

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ param ingressRoleAssignments array = []
6262
@description('Array of objects with fields principalType, roleDefinitionId')
6363
param systemRoleAssignments array = []
6464

65+
@description('Array of object ids that will have admin role of the cluster')
66+
param clusterAdmins array = []
6567

6668
resource privateDnsZone 'Microsoft.Network/privateDnsZones@2020-06-01' existing = {
6769
name: privateDnsZoneName
@@ -76,6 +78,11 @@ resource aks 'Microsoft.ContainerService/managedClusters@2024-02-01' = {
7678
properties: {
7779
enableRBAC: true
7880
dnsPrefix: !empty(dnsPrefix) ? dnsPrefix : toLower(clusterName)
81+
aadProfile: {
82+
managed: true
83+
enableAzureRBAC: true
84+
adminGroupObjectIDs: clusterAdmins
85+
}
7986
addonProfiles: {
8087
omsagent: {
8188
enabled: true

infra/deploy.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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

77
aksNamespace="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)

infra/main.bicep

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ param graphRagName string
2929
@description('Cloud region for all resources')
3030
param location string = resourceGroup().location
3131

32+
@description('Principal/Object ID of the deployer. Will be used to assign admin roles to the AKS cluster.')
33+
param deployerPrincipalId string
34+
3235
@minLength(1)
3336
@description('Name of the publisher of the API Management instance.')
3437
param publisherName string
@@ -188,6 +191,7 @@ module aks 'core/aks/aks.bicep' = {
188191
location: location
189192
graphragVMSize: 'standard_d8s_v5' // 8 vcpu, 32 GB memory
190193
graphragIndexingVMSize: 'standard_e8s_v5' // 8 vcpus, 64 GB memory
194+
clusterAdmins: ['${deployerPrincipalId}']
191195
sshRSAPublicKey: aksSshRsaPublicKey
192196
logAnalyticsWorkspaceId: log.outputs.id
193197
subnetId: vnet.properties.subnets[1].id // aks subnet

0 commit comments

Comments
 (0)