Skip to content

Commit 7163018

Browse files
authored
Merge pull request #5 from sonalika-roy/main
Update 0401.md
2 parents 9f8332a + dc97bd4 commit 7163018

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

docs/04_lab_secrets/0401.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,21 @@ Since each of these apps already has a user assigned managed identity assigned t
8080
<summary>hint</summary>
8181
<br/>
8282

83+
8384
1. For creating a service connector you will need to add the `serviceconnector-passwordless` extension:
8485

8586
```bash
87+
8688
az extension add --name serviceconnector-passwordless --upgrade
89+
8790
```
8891

8992
1. You will also need your subscription ID for creating the service connections:
9093

9194
```bash
95+
9296
SUBID=$(az account show --query id -o tsv)
97+
9398
```
9499

95100
1. You will also need resource ID of the apps:
@@ -101,11 +106,13 @@ Since each of these apps already has a user assigned managed identity assigned t
101106
--name customers-service \
102107
--query id \
103108
-o tsv)
109+
104110
Visits_ID=$(az containerapp show \
105111
--resource-group $RESOURCE_GROUP \
106112
--name visits-service \
107113
--query id \
108114
-o tsv)
115+
109116
Vets_ID=$(az containerapp show \
110117
--resource-group $RESOURCE_GROUP \
111118
--name vets-service \
@@ -125,25 +132,29 @@ Since each of these apps already has a user assigned managed identity assigned t
125132
--client-type SpringBoot \
126133
--user-identity client-id=$Client_ID subs-id=$SUBID user-object-id=$CURRENT_USER_OBJECTID mysql-identity-id=$ADMIN_IDENTITY_RESOURCE_ID \
127134
-c customers-service
135+
128136
```
129137

130138
1. You can test the validity of this new connection with the `validate` command:
131139

132140
```bash
141+
133142
CUSTOMERS_ConnId=$(az containerapp connection list \
134143
--resource-group $RESOURCE_GROUP \
135144
--name customers-service \
136145
--query [].id -o tsv)
137146
138147
az containerapp connection validate \
139148
--id $CUSTOMERS_ConnId
149+
140150
```
141151

142152
The output of this command should show that the connection was made successful.
143153

144154
1. In the same way create the service connections for the `vets-service` and `visits-service`:
145155

146156
```bash
157+
147158
az containerapp connection create \
148159
mysql-flexible --connection mysql_conn \
149160
--source-id $Vets_ID \
@@ -159,11 +170,13 @@ Since each of these apps already has a user assigned managed identity assigned t
159170
--client-type SpringBoot \
160171
--user-identity client-id=$Client_ID subs-id=$SUBID user-object-id=$CURRENT_USER_OBJECTID mysql-identity-id=$ADMIN_IDENTITY_RESOURCE_ID \
161172
-c visits-service
173+
162174
```
163175

164176
1. You can test the validity of this new connection with the `validate` command:
165177

166178
```bash
179+
167180
Vets_ConnId=$(az containerapp connection list \
168181
--resource-group $RESOURCE_GROUP \
169182
--name vets-service \
@@ -179,6 +192,7 @@ Since each of these apps already has a user assigned managed identity assigned t
179192
180193
az containerapp connection validate \
181194
--id $Visits_ConnId
195+
182196
```
183197

184198
1. In the Azure Portal, navigate to your `customers-service` container app. In the `customers-service` app, select the `Service Connector` menu item. Notice in this screen you can see the details of your service connector. Notice that the service connector has all the config values set like `spring.datasource.url`, `spring.datasource.username`, but for instance no `spring.datasource.password`. These values get turned into environment variables at runtime for your app. This is also why you could remove them from the Key Vault. Instead of `spring.datasource.password` it has a `spring.cloud.azure.credential.client-id`, which is the client ID of your managed identity. It also defines 2 additional variables `spring.datasource.azure.passwordless-enabled` and `spring.cloud.azure.credential.managed-identity-enabled` for enabling the passwordless connectivity.
@@ -231,8 +245,10 @@ The following three apps of your application use the database hosted by the Azur
231245
1. With these changes done. Make sure you are in the /src folder and rebuild the project.
232246

233247
```bash
248+
234249
cd ~/workspaces/java-microservices-aks-lab/src
235250
mvn clean package -DskipTests
251+
236252
```
237253
1. In the config repository you will need to update the database connection information. Replace the contents of the current `application.yml` file with the contents of the [0405_application.yml file](0405_application.yml). Make sure you fill out your current MySQL server name on line `12`. This file includes the following changes:
238254

@@ -243,14 +259,17 @@ The following three apps of your application use the database hosted by the Azur
243259
1. Commit these changes to the config repo.
244260

245261
```bash
262+
246263
git add .
247264
git commit -m 'Changed db config to passwordless'
248265
git push
266+
249267
```
250268

251269
1. Once the build is done, move to the `staging-acr` directory and recreate the container for customers, visits and vets.
252270

253271
```bash
272+
254273
cd staging-acr
255274
rm spring-petclinic-customers-service-$VERSION.jar
256275
rm spring-petclinic-visits-service-$VERSION.jar

0 commit comments

Comments
 (0)