-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
simplify certificate sample setup steps (#21856)
* simplify certificate sample setup cost
- Loading branch information
Showing
10 changed files
with
288 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...g-boot-samples/azure-spring-boot-sample-keyvault-certificates-client-side/script/setup.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env bash | ||
|
||
source ../azure-spring-boot-sample-keyvault-certificates-server-side/script/export_environment_variables.sh | ||
source ../azure-spring-boot-sample-keyvault-certificates-server-side/script/export_environment_variables_of_created_resource.sh |
8 changes: 4 additions & 4 deletions
8
...e-spring-boot-sample-keyvault-certificates-client-side/src/main/resources/application.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...ring-boot-sample-keyvault-certificates-server-side/script/export_environment_variables.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Set your Azure Subscription id where all required resources will be created. | ||
export SUBSCRIPTION_ID= | ||
|
||
# Set the name for your Azure resource group to be created. | ||
export RESOURCE_GROUP_NAME= | ||
|
||
# Set the region for all resources to be created. | ||
export REGION_NAME= | ||
|
||
# Set the name for your Azure Key Vault to be created. | ||
export KEY_VAULT_NAME= | ||
|
||
# Set the name for your certificate to be created. | ||
export CERTIFICATE_NAME= | ||
|
||
# Set the name for your Service Principal to be created. It should be NULL if using managed identity. ==== | ||
export SERVICE_PRINCIPAL_NAME= |
9 changes: 9 additions & 0 deletions
9
...vault-certificates-server-side/script/export_environment_variables_of_created_resource.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env bash | ||
|
||
export KEY_VAULT_URI= | ||
|
||
export SERVICE_PRINCIPAL_ID= | ||
|
||
export SERVICE_PRINCIPAL_SECRET= | ||
|
||
export SERVICE_PRINCIPAL_TETANT= |
40 changes: 40 additions & 0 deletions
40
...g-boot-samples/azure-spring-boot-sample-keyvault-certificates-server-side/script/setup.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env bash | ||
|
||
source script/export_environment_variables.sh | ||
|
||
# ==== set Azure Subscription ==== | ||
az account set --subscription ${SUBSCRIPTION_ID} | ||
|
||
# ==== Create Resource Group ==== | ||
az group create --name ${RESOURCE_GROUP_NAME} --location ${REGION_NAME} | ||
|
||
# ==== Create Key Vault and certificate ==== | ||
az keyvault create --name ${KEY_VAULT_NAME} \ | ||
--resource-group ${RESOURCE_GROUP_NAME} \ | ||
--location ${REGION_NAME} | ||
KEY_VAULT_URI=$(az keyvault show --name ${KEY_VAULT_NAME} --resource-group ${RESOURCE_GROUP_NAME} | jq -r '.properties.vaultUri') | ||
sed -i 's#export KEY_VAULT_URI=#&'"$KEY_VAULT_URI"'#' script/export_environment_variables_of_created_resource.sh | ||
|
||
az keyvault certificate create --vault-name ${KEY_VAULT_NAME} \ | ||
-n ${CERTIFICATE_NAME} \ | ||
-p "$(az keyvault certificate get-default-policy)" | ||
|
||
# ==== Create Service Principal ==== | ||
if [ ${SERVICE_PRINCIPAL_NAME} ];then | ||
SERVICE_PRINCIPAL_SECRET=$(az ad sp create-for-rbac --name ${SERVICE_PRINCIPAL_NAME} | jq -r '.password') | ||
sed -i 's#export SERVICE_PRINCIPAL_SECRET=#&'"$SERVICE_PRINCIPAL_SECRET"'#' script/export_environment_variables_of_created_resource.sh | ||
|
||
SERVICE_PRINCIPAL_ID=$(az ad sp list --display-name ${SERVICE_PRINCIPAL_NAME} | jq -r '.[0].appId') | ||
sed -i 's#export SERVICE_PRINCIPAL_ID=#&'"$SERVICE_PRINCIPAL_ID"'#' script/export_environment_variables_of_created_resource.sh | ||
|
||
SERVICE_PRINCIPAL_TETANT=$(az ad sp list --display-name ${SERVICE_PRINCIPAL_NAME} | jq -r '.[0].appOwnerTenantId') | ||
sed -i 's#export SERVICE_PRINCIPAL_TETANT=#&'"$SERVICE_PRINCIPAL_TETANT"'#' script/export_environment_variables_of_created_resource.sh | ||
|
||
az keyvault set-policy --name ${KEY_VAULT_NAME} --certificate-permission get list \ | ||
--key-permission get list \ | ||
--secret-permission get list \ | ||
--spn ${SERVICE_PRINCIPAL_ID} \ | ||
--resource-group ${RESOURCE_GROUP_NAME} | ||
fi | ||
|
||
source script/export_environment_variables_of_created_resource.sh |
Oops, something went wrong.