@@ -32,9 +32,23 @@ get_random_region() {
32
32
}
33
33
34
34
cleanup () {
35
- echo " Deleting the AKS cluster ${CLUSTER_NAME} "
35
+ echo " Cleaning up resources "
36
36
az login --service-principal -u " ${AZURE_CLIENT_ID} " --t " ${AZURE_TENANT_ID} " --federated-token " $( cat " ${AZURE_FEDERATED_TOKEN_FILE} " ) " > /dev/null
37
37
az account set --subscription " ${AZURE_SUBSCRIPTION_ID} " > /dev/null
38
+
39
+ # Clean up role assignment if IDENTITY_OBJECT_ID is set
40
+ if [[ -n " ${IDENTITY_OBJECT_ID:- } " ]]; then
41
+ echo " Removing role assignment from Key Vault"
42
+ KEYVAULT_RESOURCE_ID=$( az keyvault show --name " ${KEYVAULT_NAME} " --query " id" -otsv 2> /dev/null || true)
43
+ if [[ -n " ${KEYVAULT_RESOURCE_ID} " ]]; then
44
+ az role assignment delete \
45
+ --role " Key Vault Secrets User" \
46
+ --assignee " ${IDENTITY_OBJECT_ID} " \
47
+ --scope " ${KEYVAULT_RESOURCE_ID} " > /dev/null 2>&1 || true
48
+ fi
49
+ fi
50
+
51
+ echo " Deleting the AKS cluster ${CLUSTER_NAME} "
38
52
az group delete --name " ${CLUSTER_NAME} " --yes --no-wait || true
39
53
}
40
54
trap cleanup EXIT
@@ -116,9 +130,13 @@ main() {
116
130
--subject " system:serviceaccount:negative-test-ns:default" \
117
131
--audiences api://AzureADTokenExchange > /dev/null
118
132
119
- # Assigning the managed identity the necessary permissions to access the keyvault
120
- echo " Assigning managed identity permissions to get secrets from keyvault"
121
- az keyvault set-policy --name " ${KEYVAULT_NAME} " --secret-permissions get --object-id " ${IDENTITY_OBJECT_ID} " > /dev/null
133
+ # Assigning the managed identity the necessary permissions to access the keyvault using RBAC
134
+ echo " Assigning managed identity Key Vault Secrets User role on keyvault"
135
+ KEYVAULT_RESOURCE_ID=$( az keyvault show --name " ${KEYVAULT_NAME} " --query " id" -otsv)
136
+ az role assignment create \
137
+ --role " Key Vault Secrets User" \
138
+ --assignee " ${IDENTITY_OBJECT_ID} " \
139
+ --scope " ${KEYVAULT_RESOURCE_ID} " > /dev/null
122
140
123
141
docker pull " ${IMAGE_TAG} " || ALL_ARCH_linux=amd64 make container-all push-manifest
124
142
make e2e-install-prerequisites
0 commit comments