Skip to content

Commit eeed08f

Browse files
authored
Merge pull request #1918 from aramase/aramase/ci/fix_rbac
ci: update azure scripts to use rbac for keyvault permissions
2 parents 2600485 + 9ae58c2 commit eeed08f

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

test/scripts/run-e2e-azure.sh

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,23 @@ get_random_region() {
3232
}
3333

3434
cleanup() {
35-
echo "Deleting the AKS cluster ${CLUSTER_NAME}"
35+
echo "Cleaning up resources"
3636
az login --service-principal -u "${AZURE_CLIENT_ID}" --t "${AZURE_TENANT_ID}" --federated-token "$(cat "${AZURE_FEDERATED_TOKEN_FILE}")" > /dev/null
3737
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}"
3852
az group delete --name "${CLUSTER_NAME}" --yes --no-wait || true
3953
}
4054
trap cleanup EXIT
@@ -116,9 +130,13 @@ main() {
116130
--subject "system:serviceaccount:negative-test-ns:default" \
117131
--audiences api://AzureADTokenExchange > /dev/null
118132

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
122140

123141
docker pull "${IMAGE_TAG}" || ALL_ARCH_linux=amd64 make container-all push-manifest
124142
make e2e-install-prerequisites

0 commit comments

Comments
 (0)