Skip to content

Commit 8e1c713

Browse files
committed
Initial draft
1 parent c8acea9 commit 8e1c713

File tree

1 file changed

+93
-4
lines changed

1 file changed

+93
-4
lines changed

articles/container-apps/manage-secrets.md

Lines changed: 93 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ ms.custom: event-tier1-build-2022, ignite-2022, devx-track-azurecli, devx-track-
1212

1313
# Manage secrets in Azure Container Apps
1414

15-
Azure Container Apps allows your application to securely store sensitive configuration values. Once secrets are defined at the application level, secured values are available to container apps. Specifically, you can reference secured values inside scale rules. For information on using secrets with Dapr, refer to [Dapr integration](./dapr-overview.md)
15+
Azure Container Apps allows your application to securely store sensitive configuration values. Once secrets are defined at the application level, secured values are available to revisions in your container apps. Additionally, you can reference secured values inside scale rules. For information on using secrets with Dapr, refer to [Dapr integration](./dapr-overview.md)
1616

1717
- Secrets are scoped to an application, outside of any specific revision of an application.
1818
- Adding, removing, or changing secrets doesn't generate new revisions.
@@ -26,11 +26,13 @@ An updated or deleted secret doesn't automatically affect existing revisions in
2626

2727
Before you delete a secret, deploy a new revision that no longer references the old secret. Then deactivate all revisions that reference the secret.
2828

29-
> [!NOTE]
30-
> Container Apps doesn't support Azure Key Vault integration. Instead, enable managed identity in the container app and use the [Key Vault SDK](../key-vault/general/developers-guide.md) in your app to access secrets.
29+
## Defining secrets
3130

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

33-
## Defining secrets
33+
### Store secret value in Container Apps
34+
35+
When you define a secret, you can specify its value directly.
3436

3537
# [ARM template](#tab/arm-template)
3638

@@ -97,6 +99,93 @@ Here, a connection string to a queue storage account is declared. The value for
9799

98100
---
99101

102+
### Reference secret from Key Vault
103+
104+
When you define a secret, you can specify a reference to a secret stored in Azure Key Vault. To reference a secret from Key Vault, you must first enable managed identity in your container app and grant the identity access to the Key Vault secrets.
105+
106+
To enable managed identity in your container app, see [Managed identities](managed-identity.md).
107+
108+
To grant access to Key Vault secrets, [create an access policy](../key-vault/general/assign-access-policy.md) in Key Vault for the managed identity you created. Enable the "Get" secret permission on this policy.
109+
110+
# [ARM template](#tab/arm-template)
111+
112+
Secrets are defined at the application level in the `resources.properties.configuration.secrets` section.
113+
114+
```json
115+
"resources": [
116+
{
117+
...
118+
"properties": {
119+
"configuration": {
120+
"secrets": [
121+
{
122+
"name": "queue-connection-string",
123+
"keyVaultUrl": "<KEY-VAULT-SECRET-URI>",
124+
"identity": "System"
125+
}],
126+
}
127+
}
128+
}
129+
```
130+
131+
Here, a connection string to a queue storage account is declared in the `secrets` array. Its value is automatically retrieved from Key Vault using the specified identity. To use a user managed identity, replace `System` with the identity's resource ID.
132+
133+
Replace `<KEY-VAULT-SECRET-URI>` with the URI of your secret in Key Vault.
134+
135+
# [Azure CLI](#tab/azure-cli)
136+
137+
When you create a container app, secrets are defined using the `--secrets` parameter.
138+
139+
- The parameter accepts a space-delimited set of name/value pairs.
140+
- Each pair is delimited by an equals sign (`=`).
141+
142+
```bash
143+
az containerapp create \
144+
--resource-group "my-resource-group" \
145+
--name queuereader \
146+
--environment "my-environment-name" \
147+
--image demos/queuereader:v1 \
148+
--secrets "queue-connection-string=$CONNECTION_STRING"
149+
```
150+
151+
Here, a connection string to a queue storage account is declared in the `--secrets` parameter. The value for `queue-connection-string` comes from an environment variable named `$CONNECTION_STRING`.
152+
153+
# [PowerShell](#tab/powershell)
154+
155+
When you create a container app, secrets are defined as one or more Secret objects that are passed through the `ConfigurationSecrets` parameter.
156+
157+
```azurepowershell
158+
$EnvId = (Get-AzContainerAppManagedEnv -ResourceGroupName my-resource-group -EnvName my-environment-name).Id
159+
$TemplateObj = New-AzContainerAppTemplateObject -Name queuereader -Image demos/queuereader:v1
160+
$SecretObj = New-AzContainerAppSecretObject -Name queue-connection-string -Value $QueueConnectionString
161+
162+
$ContainerAppArgs = @{
163+
Name = 'my-resource-group'
164+
Location = '<location>'
165+
ResourceGroupName = 'my-resource-group'
166+
ManagedEnvironmentId = $EnvId
167+
TemplateContainer = $TemplateObj
168+
ConfigurationSecret = $SecretObj
169+
}
170+
171+
New-AzContainerApp @ContainerAppArgs
172+
```
173+
174+
Here, a connection string to a queue storage account is declared. The value for `queue-connection-string` comes from an environment variable named `$QueueConnectionString`.
175+
176+
---
177+
178+
### Key Vault secret URI and secret rotation
179+
180+
The Key Vault secret URI must be in the following format:
181+
182+
* `https://myvault.vault.azure.net/secrets/mysecret/ec96f02080254f109c51a1f14cdb1931`: Reference a specific version of a secret.
183+
* `https://myvault.vault.azure.net/secrets/mysecret`: Reference the latest version of a secret.
184+
185+
If a version is not specified in the URI, then the app will use the latest version that exists in the key vault. When newer versions become available, the app will automatically retrieve the latest version within 30 minutes. Any active revisions that reference the secret in an environment variable is automatically restarted to pick up the new value.
186+
187+
To force the app to retrieve the latest version of the secret, you can restart a revision.
188+
100189
## <a name="using-secrets"></a>Referencing secrets in environment variables
101190

102191
After declaring secrets at the application level as described in the [defining secrets](#defining-secrets) section, you can reference them in environment variables when you create a new revision in your container app. When an environment variable references a secret, its value is populated with the value defined in the secret.

0 commit comments

Comments
 (0)