Skip to content

Commit 963ca4f

Browse files
author
Jill Grant
authored
Merge pull request #286949 from v-jaswel/aca/v-jaswel_20240918_work_item_310315
[ACA] Recommend storing secrets in Key Vault.
2 parents cbf5a6b + 2574841 commit 963ca4f

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

articles/container-apps/code/secure-app-arm-template.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"environment_id": {
99
"type": "String"
1010
},
11-
"queue-connection-string": {
11+
"key_vault_secret_uri": {
1212
"type": "String"
1313
}
1414
},
@@ -27,7 +27,8 @@
2727
"secrets": [
2828
{
2929
"name": "queue-connection-string",
30-
"value": "[parameters('queue-connection-string')]"
30+
"keyVaultUrl": "[parameters('key_vault_secret_uri')",
31+
"identity": "system"
3132
}]
3233
},
3334
"template": {

articles/container-apps/get-started-existing-container-image.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ author: craigshoemaker
66
ms.service: azure-container-apps
77
ms.custom: devx-track-azurecli, devx-track-azurepowershell
88
ms.topic: quickstart
9-
ms.date: 08/31/2022
9+
ms.date: 09/12/2024
1010
ms.author: cshoe
1111
zone_pivot_groups: container-apps-registry-types
1212
---

articles/container-apps/manage-secrets.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ services: container-apps
55
author: craigshoemaker
66
ms.service: azure-container-apps
77
ms.topic: how-to
8-
ms.date: 03/23/2023
8+
ms.date: 09/18/2024
99
ms.author: cshoe
1010
ms.custom: devx-track-azurecli, devx-track-azurepowershell, build-2023
1111
---
@@ -30,6 +30,9 @@ Before you delete a secret, deploy a new revision that no longer references the
3030

3131
Secrets are defined as a set of name/value pairs. The value of each secret is specified directly or as a reference to a secret stored in Azure Key Vault.
3232

33+
> [!NOTE]
34+
> Avoid specifying the value of a secret directly in a production environment. Instead, use a reference to a secret stored in Azure Key Vault, as described in the [Store secret value in Container Apps section](#reference-secret-from-key-vault).
35+
3336
### Store secret value in Container Apps
3437

3538
When you define secrets through the portal, or via different command line options.
@@ -191,7 +194,7 @@ az containerapp create \
191194
--secrets "queue-connection-string=keyvaultref:<KEY_VAULT_SECRET_URI>,identityref:<USER_ASSIGNED_IDENTITY_ID>"
192195
```
193196

194-
Here, a connection string to a queue storage account is declared in the `--secrets` parameter. Replace `<KEY_VAULT_SECRET_URI>` with the URI of your secret in Key Vault. Replace `<USER_ASSIGNED_IDENTITY_ID>` with the resource ID of the user assigned identity. For system assigned identity, use `system` instead of the resource ID.
197+
Here, a connection string to a queue storage account is declared in the `--secrets` parameter. Replace `<KEY_VAULT_SECRET_URI>` with the URI of your secret in Key Vault. Replace `<USER_ASSIGNED_IDENTITY_ID>` with the resource ID of the user assigned identity.
195198

196199
> [!NOTE]
197200
> The user assigned identity must have access to read the secret in Key Vault. System assigned identity can't be used with the create command because it's not available until after the container app is created.
@@ -252,7 +255,7 @@ After you've [defined a secret](#defining-secrets) in your container app, you ca
252255

253256
In this example, the application connection string is declared as `queue-connection-string` and becomes available elsewhere in the configuration sections.
254257

255-
:::code language="json" source="code/secure-app-arm-template.json" highlight="11,12,13,27,28,29,30,31,44,45,61,62":::
258+
:::code language="json" source="code/secure-app-arm-template.json" highlight="11-13,27-32,45-46,62-63":::
256259

257260
Here, the environment variable named `connection-string` gets its value from the application-level `queue-connection-string` secret. Also, the Azure Queue Storage scale rule's authentication configuration uses the `queue-connection-string` secret as to define its connection.
258261

@@ -268,14 +271,17 @@ az containerapp create \
268271
--name myQueueApp \
269272
--environment "my-environment-name" \
270273
--image demos/myQueueApp:v1 \
271-
--secrets "queue-connection-string=$CONNECTIONSTRING" \
274+
--user-assigned "<USER_ASSIGNED_IDENTITY_ID>" \
275+
--secrets "queue-connection-string=keyvaultref:<KEY_VAULT_SECRET_URI>,identityref:<USER_ASSIGNED_IDENTITY_ID>" \
272276
--env-vars "QueueName=myqueue" "ConnectionString=secretref:queue-connection-string"
273277
```
274278

275279
Here, the environment variable named `connection-string` gets its value from the application-level `queue-connection-string` secret.
276280

277281
# [PowerShell](#tab/powershell)
278282

283+
Secrets Key Vault references aren't supported in PowerShell.
284+
279285
In this example, you create a container using Azure PowerShell with a secret that's referenced in an environment variable. To reference the secret in an environment variable in PowerShell, set its value to `secretref:`, followed by the name of the secret.
280286

281287
```azurepowershell-interactive
@@ -359,7 +365,7 @@ In this example, two secrets are declared at the application level. These secret
359365
"environment_id": {
360366
"type": "String"
361367
},
362-
"queue-connection-string": {
368+
"key_vault_secret_uri": {
363369
"type": "Securestring"
364370
},
365371
"api-key": {
@@ -381,7 +387,8 @@ In this example, two secrets are declared at the application level. These secret
381387
"secrets": [
382388
{
383389
"name": "queue-connection-string",
384-
"value": "[parameters('queue-connection-string')]"
390+
"keyVaultUrl": "[parameters('key_vault_secret_uri')",
391+
"identity": "system"
385392
},
386393
{
387394
"name": "api-key",
@@ -425,7 +432,8 @@ To load specific secrets and specify their paths within the mounted volume, you
425432
"secrets": [
426433
{
427434
"name": "queue-connection-string",
428-
"value": "[parameters('queue-connection-string')]"
435+
"keyVaultUrl": "[parameters('key_vault_secret_uri')",
436+
"identity": "system"
429437
},
430438
{
431439
"name": "api-key",
@@ -477,7 +485,8 @@ az containerapp create \
477485
--name myQueueApp \
478486
--environment "my-environment-name" \
479487
--image demos/myQueueApp:v1 \
480-
--secrets "queue-connection-string=$CONNECTIONSTRING" "api-key=$API_KEY" \
488+
--user-assigned "<USER_ASSIGNED_IDENTITY_ID>" \
489+
--secrets "queue-connection-string=keyvaultref:<KEY_VAULT_SECRET_URI>,identityref:<USER_ASSIGNED_IDENTITY_ID>" "api-key=$API_KEY" \
481490
--secret-volume-mount "/mnt/secrets"
482491
```
483492

0 commit comments

Comments
 (0)