Skip to content

Commit 9765525

Browse files
Merge pull request #234293 from KarlErickson/karler-108099
fixes MicrosoftDocs/azure-docs#108099
2 parents e34fba4 + 2b72430 commit 9765525

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

articles/spring-apps/tutorial-managed-identities-key-vault.md

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ ms.custom: devx-track-java, devx-track-azurecli, event-tier1-build-2022
1616
1717
**This article applies to:** ✔️ Java ❌ C#
1818

19-
**This article applies to:** ✔️ Basic/Standard tier ✔️ Enterprise tier
19+
**This article applies to:** ✔️ Basic/Standard ✔️ Enterprise
2020

2121
This article shows you how to create a managed identity for an Azure Spring Apps app and use it to access Azure Key Vault.
2222

@@ -32,14 +32,14 @@ The following video describes how to manage secrets using Azure Key Vault.
3232

3333
* [Sign up for an Azure subscription](https://azure.microsoft.com/free/)
3434
* [Install the Azure CLI version 2.45.0 or higher](/cli/azure/install-azure-cli)
35-
* [Install Maven 3.0 or above](https://maven.apache.org/download.cgi)
35+
* [Install Maven 3.0 or higher](https://maven.apache.org/download.cgi)
3636

3737
## Create a resource group
3838

3939
A resource group is a logical container into which Azure resources are deployed and managed. Create a resource group to contain both the Key Vault and Spring Cloud using the command [az group create](/cli/azure/group#az-group-create):
4040

4141
```azurecli
42-
az group create --name "myResourceGroup" -l "EastUS"
42+
az group create --name "myResourceGroup" --location "EastUS"
4343
```
4444

4545
## Set up your Key Vault
@@ -55,7 +55,7 @@ az keyvault create \
5555
--name "<your-keyvault-name>"
5656
```
5757

58-
Make a note of the returned `vaultUri`, which will be in the format `https://<your-keyvault-name>.vault.azure.net`. It will be used in the following step.
58+
Make a note of the returned `vaultUri`, which is in the format `https://<your-keyvault-name>.vault.azure.net`. You use this value in the following step.
5959

6060
You can now place a secret in your Key Vault with the command [az keyvault secret set](/cli/azure/keyvault/secret#az-keyvault-secret-set):
6161

@@ -84,42 +84,46 @@ The following example creates an app named `springapp` with a system-assigned ma
8484
```azurecli
8585
az spring app create \
8686
--resource-group <your-resource-group-name> \
87-
--name "springapp" \
8887
--service <your-Azure-Spring-Apps-instance-name> \
88+
--name "springapp" \
8989
--assign-endpoint true \
9090
--system-assigned
91-
export SERVICE_IDENTITY=$(az spring app show --name "springapp" -s "myspringcloud" -g "myResourceGroup" | jq -r '.identity.principalId')
91+
export SERVICE_IDENTITY=$(az spring app show \
92+
--resource-group "<your-resource-group-name>" \
93+
--service "<your-Azure-Spring-Apps-instance-name>" \
94+
--name "springapp" \
95+
| jq -r '.identity.principalId')
9296
```
9397

9498
### [User-assigned managed identity](#tab/user-assigned-managed-identity)
9599

96-
First, create a user-assigned managed identity in advance with its resource ID set to `$USER_IDENTITY_RESOURCE_ID`. Save the client ID for the property configuration below.
100+
First, create a user-assigned managed identity in advance with its resource ID set to `$USER_IDENTITY_RESOURCE_ID`. Save the client ID for the property configuration.
97101

98102
:::image type="content" source="media/tutorial-managed-identities-key-vault/app-user-managed-identity-key-vault.png" alt-text="Screenshot of Azure portal showing the Managed Identity Properties screen with 'Resource ID', 'Principle ID' and 'Client ID' highlighted." lightbox="media/tutorial-managed-identities-key-vault/app-user-managed-identity-key-vault.png":::
99103

100-
```azurecli
101-
export SERVICE_IDENTITY={principal ID of user-assigned managed identity}
102-
export USER_IDENTITY_RESOURCE_ID={resource ID of user-assigned managed identity}
104+
```bash
105+
export SERVICE_IDENTITY=<principal-ID-of-user-assigned-managed-identity>
106+
export USER_IDENTITY_RESOURCE_ID=<resource-ID-of-user-assigned-managed-identity>
103107
```
104108

105109
The following example creates an app named `springapp` with a user-assigned managed identity, as requested by the `--user-assigned` parameter.
106110

107111
```azurecli
108112
az spring app create \
109113
--resource-group <your-resource-group-name> \
110-
--name "springapp" \
111114
--service <your-Azure-Spring-Apps-instance-name> \
112-
--assign-endpoint true \
113-
--user-assigned $USER_IDENTITY_RESOURCE_ID
115+
--name "springapp" \
116+
--user-assigned $USER_IDENTITY_RESOURCE_ID \
117+
--assign-endpoint true
114118
az spring app show \
115119
--resource-group <your-resource-group-name> \
116-
--name "springapp" \
117-
--service <your-Azure-Spring-Apps-instance-name>
120+
--service <your-Azure-Spring-Apps-instance-name> \
121+
--name "springapp"
118122
```
119123

120124
---
121125

122-
Make a note of the returned URL, which will be in the format `https://<your-app-name>.azuremicroservices.io`. This URL will be used in the following step.
126+
Make a note of the returned URL, which is in the format `https://<your-app-name>.azuremicroservices.io`. You use this value in the following step.
123127

124128
## Grant your app access to Key Vault
125129

@@ -137,17 +141,17 @@ az keyvault set-policy \
137141
138142
## Build a sample Spring Boot app with Spring Boot starter
139143

140-
This app will have access to get secrets from Azure Key Vault. Use the Azure Key Vault Secrets Spring boot starter. Azure Key Vault is added as an instance of Spring **PropertySource**. Secrets stored in Azure Key Vault can be conveniently accessed and used like any externalized configuration property, such as properties in files.
144+
This app has access to get secrets from Azure Key Vault. Use the Azure Key Vault Secrets Spring boot starter. Azure Key Vault is added as an instance of Spring **PropertySource**. Secrets stored in Azure Key Vault can be conveniently accessed and used like any externalized configuration property, such as properties in files.
141145

142146
1. Use the following command to generate a sample project from `start.spring.io` with Azure Key Vault Spring Starter.
143147

144-
```azurecli
148+
```bash
145149
curl https://start.spring.io/starter.tgz -d dependencies=web,azure-keyvault -d baseDir=springapp -d bootVersion=2.7.2 -d javaVersion=1.8 | tar -xzvf -
146150
```
147151

148152
1. Specify your Key Vault in your app.
149153

150-
```azurecli
154+
```bash
151155
cd springapp
152156
vim src/main/resources/application.properties
153157
```
@@ -172,7 +176,7 @@ spring.cloud.azure.keyvault.secret.property-sources[0].credential.client-id={Cli
172176
---
173177

174178
> [!NOTE]
175-
> You must add the key vault URL in the *application.properties* file as shown above. Otherwise, the key vault URL may not be captured during runtime.
179+
> You must add the key vault URL in the *application.properties* file as shown previously. Otherwise, the key vault URL may not be captured during runtime.
176180
177181
1. Add the following code example to *src/main/java/com/example/demo/DemoApplication.java*. This code retrieves the connection string from the key vault.
178182

@@ -208,7 +212,7 @@ spring.cloud.azure.keyvault.secret.property-sources[0].credential.client-id={Cli
208212
}
209213
```
210214

211-
If you open the *pom.xml* file, you'll see the dependency of `spring-cloud-azure-starter-keyvault`.
215+
If you open the *pom.xml* file, you can see the `spring-cloud-azure-starter-keyvault` dependency, as shown in the following example:
212216

213217
```xml
214218
<dependency>
@@ -219,7 +223,7 @@ spring.cloud.azure.keyvault.secret.property-sources[0].credential.client-id={Cli
219223

220224
1. Use the following command to package your sample app.
221225

222-
```azurecli
226+
```bash
223227
./mvnw clean package -DskipTests
224228
```
225229

@@ -228,18 +232,18 @@ spring.cloud.azure.keyvault.secret.property-sources[0].credential.client-id={Cli
228232
```azurecli
229233
az spring app deploy \
230234
--resource-group <your-resource-group-name> \
231-
--name "springapp" \
232235
--service <your-Azure-Spring-Apps-instance-name> \
236+
--name "springapp" \
233237
--artifact-path target/demo-0.0.1-SNAPSHOT.jar
234238
```
235239

236240
1. To test your app, access the public endpoint or test endpoint by using the following command:
237241

238-
```azurecli
242+
```bash
239243
curl https://myspringcloud-springapp.azuremicroservices.io/get
240244
```
241245

242-
You'll see the message `Successfully got the value of secret connectionString from Key Vault https://<your-keyvault-name>.vault.azure.net/: jdbc:sqlserver://SERVER.database.windows.net:1433;database=DATABASE;`.
246+
You're shown the message `Successfully got the value of secret connectionString from Key Vault https://<your-keyvault-name>.vault.azure.net/: jdbc:sqlserver://SERVER.database.windows.net:1433;database=DATABASE;`.
243247

244248
## Next steps
245249

0 commit comments

Comments
 (0)