Skip to content

Commit 32d6083

Browse files
authored
Merge pull request #1206 from berndverst/master
Integration test setup for AKV
2 parents 4532359 + 029ca1d commit 32d6083

File tree

6 files changed

+52
-7
lines changed

6 files changed

+52
-7
lines changed

.github/infrastructure/conformance/azure/setup-azure-conf-test.sh

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ IOT_HUB_PUBSUB_CONSUMER_GROUP_VAR_NAME="AzureIotHubPubsubConsumerGroup"
181181

182182
KEYVAULT_CERT_NAME="AzureKeyVaultSecretStoreCert"
183183
KEYVAULT_CLIENT_ID_VAR_NAME="AzureKeyVaultSecretStoreClientId"
184+
KEYVAULT_SERVICE_PRINCIPAL_CLIENT_SECRET_VAR_NAME="AzureKeyVaultSecretStoreServicePrincipalClientSecret"
185+
KEYVAULT_SERVICE_PRINCIPAL_CLIENT_ID_VAR_NAME="AzureKeyVaultSecretStoreServicePrincipalClientId"
184186
KEYVAULT_TENANT_ID_VAR_NAME="AzureKeyVaultSecretStoreTenantId"
185187
KEYVAULT_NAME_VAR_NAME="AzureKeyVaultName"
186188

@@ -297,11 +299,17 @@ echo "INFO: SQL_SERVER_ADMIN_NAME=${SQL_SERVER_ADMIN_NAME}"
297299
# Give the service principal used by the SDK write access to the entire resource group
298300
MSYS_NO_PATHCONV=1 az role assignment create --assignee "${SDK_AUTH_SP_ID}" --role "Contributor" --scope "/subscriptions/${SUB_ID}/resourceGroups/${RESOURCE_GROUP_NAME}"
299301

300-
# Create Identity
302+
# Create Identity if it doesn't exist
301303
# We use the standard name "azure-managed-identity" for the identity so we can easily query for it later using the CLI
302-
echo "Creating Identity azure-managed-identity"
303-
MANAGED_IDENTITY_SP="$(az identity create -g ${RESOURCE_GROUP_NAME} -n azure-managed-identity --location ${DEPLOY_LOCATION} --query principalId -otsv)"
304-
# This identity can later be injected into services for managed identity authentication
304+
if az identity show -g ${RESOURCE_GROUP_NAME} -n azure-managed-identity --query id -otsv; then
305+
echo "Reusing Identity azure-managed-identity"
306+
MANAGED_IDENTITY_SP="$(az identity show -g ${RESOURCE_GROUP_NAME} -n azure-managed-identity --query principalId -otsv)"
307+
else
308+
echo "Creating Identity azure-managed-identity"
309+
MANAGED_IDENTITY_SP="$(az identity create -g ${RESOURCE_GROUP_NAME} -n azure-managed-identity --location ${DEPLOY_LOCATION} --query principalId -otsv)"
310+
# This identity can later be injected into services for managed identity authentication
311+
fi
312+
305313
MANAGED_IDENTITY_ID="$(az identity show -g ${RESOURCE_GROUP_NAME} -n azure-managed-identity --query id -otsv)"
306314
echo "Created Identity ${MANAGED_IDENTITY_ID}"
307315

@@ -313,6 +321,15 @@ az keyvault set-policy --name "${KEYVAULT_NAME}" -g "${RESOURCE_GROUP_NAME}" --s
313321
# Other tests verifying managed identity will want to grant permission like so:
314322
# MSYS_NO_PATHCONV=1 az role assignment create --assignee-object-id "${MANAGED_IDENTITY_SP}" --assignee-principal-type ServicePrincipal --role "Azure Service Bus Data Owner" --scope "/subscriptions/${SUB_ID}/resourceGroups/${RESOURCE_GROUP_NAME}/providers/Microsoft.ServiceBus/namespaces/${SERVICE_BUS_NAME}"
315323

324+
# Creating service principal for service principal authentication with KeyVault
325+
AKV_SPAUTH_SP_NAME="${PREFIX}-akv-spauth-conf-test-sp"
326+
echo "Creating service principal ${AKV_SPAUTH_SP_NAME} for use with KeyVault ${KEYVAULT_NAME}"
327+
{ read AKV_SPAUTH_SP_CLIENT_ID ; read AKV_SPAUTH_SP_CLIENT_SECRET ; } < <(az ad sp create-for-rbac --name ${AKV_SPAUTH_SP_NAME} --skip-assignment --years 1 --query "[appId,password]" -otsv)
328+
329+
# Give the service principal read access to the KeyVault Secrets
330+
AKV_SPAUTH_SP_OBJECTID="$(az ad sp show --id ${AKV_SPAUTH_SP_CLIENT_ID} --query objectId -otsv)"
331+
az keyvault set-policy --name "${KEYVAULT_NAME}" -g "${RESOURCE_GROUP_NAME}" --secret-permissions get list --object-id "${AKV_SPAUTH_SP_OBJECTID}"
332+
316333
# Update service principal credentials and roles for created resources
317334
echo "Creating ${CERT_AUTH_SP_NAME} certificate ..."
318335
az ad sp credential reset --name "${CERT_AUTH_SP_NAME}" --create-cert --cert "${KEYVAULT_CERT_NAME}" --keyvault "${KEYVAULT_NAME}"
@@ -418,6 +435,13 @@ KEYVAULT_CLIENT_ID="$(az ad sp list --display-name "${CERT_AUTH_SP_NAME}" --quer
418435
echo export ${KEYVAULT_CLIENT_ID_VAR_NAME}=\"${KEYVAULT_CLIENT_ID}\" >> "${ENV_CONFIG_FILENAME}"
419436
az keyvault secret set --name "${KEYVAULT_CLIENT_ID_VAR_NAME}" --vault-name "${KEYVAULT_NAME}" --value "${KEYVAULT_CLIENT_ID}"
420437

438+
KEYVAULT_SERVICE_PRINCIPAL_CLIENT_ID=${AKV_SPAUTH_SP_CLIENT_ID}
439+
echo export ${KEYVAULT_SERVICE_PRINCIPAL_CLIENT_ID_VAR_NAME}=\"${KEYVAULT_SERVICE_PRINCIPAL_CLIENT_ID}\" >> "${ENV_CONFIG_FILENAME}"
440+
az keyvault secret set --name "${KEYVAULT_SERVICE_PRINCIPAL_CLIENT_ID_VAR_NAME}" --vault-name "${KEYVAULT_NAME}" --value "${KEYVAULT_SERVICE_PRINCIPAL_CLIENT_ID}"
441+
442+
KEYVAULT_SERVICE_PRINCIPAL_CLIENT_SECRET=${AKV_SPAUTH_SP_CLIENT_SECRET}
443+
echo export ${KEYVAULT_SERVICE_PRINCIPAL_CLIENT_SECRET_VAR_NAME}=\"${KEYVAULT_SERVICE_PRINCIPAL_CLIENT_SECRET}\" >> "${ENV_CONFIG_FILENAME}"
444+
az keyvault secret set --name "${KEYVAULT_SERVICE_PRINCIPAL_CLIENT_SECRET_VAR_NAME}" --vault-name "${KEYVAULT_NAME}" --value "${KEYVAULT_SERVICE_PRINCIPAL_CLIENT_SECRET}"
421445
# ------------------------------------
422446
# Populate Blob Storage test settings
423447
# ------------------------------------

.github/workflows/conformance.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,11 @@ jobs:
113113
required-secrets: AzureServiceBusConnectionString
114114
- component: bindings.azure.storagequeues
115115
required-secrets: AzureBlobStorageAccessKey,AzureBlobStorageAccount,AzureBlobStorageQueue
116-
- component: secretstores.azure.keyvault
116+
- component: secretstores.azure.keyvault.certificate
117117
required-secrets: AzureKeyVaultName,AzureKeyVaultSecretStoreTenantId,AzureKeyVaultSecretStoreClientId
118118
required-certs: AzureKeyVaultSecretStoreCert
119+
- component: secretstores.azure.keyvault.serviceprincipal
120+
required-secrets: AzureKeyVaultName,AzureKeyVaultSecretStoreTenantId,AzureKeyVaultSecretStoreServicePrincipalClientId,AzureKeyVaultSecretStoreServicePrincipalClientSecret
119121
EOF
120122
)
121123
echo "::set-output name=cron-components::$CRON_COMPONENTS"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: dapr.io/v1alpha1
2+
kind: Component
3+
metadata:
4+
name: azurekeyvault-service-principal
5+
spec:
6+
type: secretstores.azure.keyvault
7+
metadata:
8+
- name: vaultName
9+
value: ${{AzureKeyVaultName}}
10+
- name: azureTenantId
11+
value: ${{AzureKeyVaultSecretStoreTenantId}}
12+
- name: azureClientId
13+
value: ${{AzureKeyVaultSecretStoreServicePrincipalClientId}}
14+
- name: azureClientSecret
15+
value: ${{AzureKeyVaultSecretStoreServicePrincipalClientSecret}}

tests/config/secretstores/tests.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ components:
55
operations: ["get"]
66
- component: localfile
77
allOperations: true
8-
- component: azure.keyvault
8+
- component: azure.keyvault.certificate
9+
allOperations: true
10+
- component: azure.keyvault.serviceprincipal
911
allOperations: true
1012
- component: kubernetes
1113
allOperations: true

tests/conformance/common.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,9 @@ func loadPubSub(tc TestComponent) pubsub.PubSub {
372372
func loadSecretStore(tc TestComponent) secretstores.SecretStore {
373373
var store secretstores.SecretStore
374374
switch tc.Component {
375-
case "azure.keyvault":
375+
case "azure.keyvault.certificate":
376+
store = ss_azure.NewAzureKeyvaultSecretStore(testLogger)
377+
case "azure.keyvault.serviceprincipal":
376378
store = ss_azure.NewAzureKeyvaultSecretStore(testLogger)
377379
case "kubernetes":
378380
store = ss_kubernetes.NewKubernetesSecretStore(testLogger)

0 commit comments

Comments
 (0)