You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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).
16
16
17
17
- Secrets are scoped to an application, outside of any specific revision of an application.
18
18
- Adding, removing, or changing secrets doesn't generate new revisions.
@@ -26,11 +26,29 @@ An updated or deleted secret doesn't automatically affect existing revisions in
26
26
27
27
Before you delete a secret, deploy a new revision that no longer references the old secret. Then deactivate all revisions that reference the secret.
28
28
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
31
30
31
+
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.
32
32
33
-
## Defining secrets
33
+
### Store secret value in Container Apps
34
+
35
+
When you define secrets through the portal, or via different command line options.
36
+
37
+
# [Azure portal](#tab/azure-portal)
38
+
39
+
1. Go to your container app in the [Azure portal](https://portal.azure.com).
40
+
41
+
1. Under the *Settings* section, select **Secrets**.
42
+
43
+
1. Select **Add**.
44
+
45
+
1. In the *Add secret* context pane, enter the following information:
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`.
91
+
Here, a connection string to a queue storage account is declared in the `--secrets` parameter. Replace `<CONNECTION_STRING>` with the value of your connection string.
74
92
75
93
# [PowerShell](#tab/powershell)
76
94
@@ -97,14 +115,136 @@ Here, a connection string to a queue storage account is declared. The value for
97
115
98
116
---
99
117
118
+
### <aname="reference-secret-from-key-vault"></a>Reference secret from Key Vault (preview)
119
+
120
+
When you define a secret, you create a reference to a secret stored in Azure Key Vault. Container Apps automatically retrieves the secret value from Key Vault and makes it available as a secret in your container app.
121
+
122
+
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.
123
+
124
+
To enable managed identity in your container app, see [Managed identities](managed-identity.md).
125
+
126
+
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.
127
+
128
+
# [Azure portal](#tab/azure-portal)
129
+
130
+
1. Go to your container app in the [Azure portal](https://portal.azure.com).
131
+
132
+
1. Under the *Settings* section, select **Identity**.
133
+
134
+
1. In the *System assigned* tab, select **On**.
135
+
136
+
1. Select **Save** to enable system-assigned managed identity.
137
+
138
+
1. Under the *Settings* section, select **Secrets**.
139
+
140
+
1. Select **Add**.
141
+
142
+
1. In the *Add secret* context pane, enter the following information:
143
+
144
+
-**Name**: The name of the secret.
145
+
-**Type**: Select **Key Vault reference**.
146
+
-**Key Vault secret URL**: The URI of your secret in Key Vault.
147
+
-**Identity**: The identity to use to retrieve the secret from Key Vault.
148
+
149
+
1. Select **Add**.
150
+
151
+
# [ARM template](#tab/arm-template)
152
+
153
+
Secrets are defined at the application level in the `resources.properties.configuration.secrets` section.
154
+
155
+
```json
156
+
"resources": [
157
+
{
158
+
...
159
+
"properties": {
160
+
"configuration": {
161
+
"secrets": [
162
+
{
163
+
"name": "queue-connection-string",
164
+
"keyVaultUrl": "<KEY-VAULT-SECRET-URI>",
165
+
"identity": "System"
166
+
}],
167
+
}
168
+
}
169
+
}
170
+
```
171
+
172
+
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.
173
+
174
+
Replace `<KEY-VAULT-SECRET-URI>` with the URI of your secret in Key Vault.
175
+
176
+
# [Azure CLI](#tab/azure-cli)
177
+
178
+
When you create a container app, secrets are defined using the `--secrets` parameter.
179
+
180
+
- The parameter accepts a space-delimited set of name/value pairs.
181
+
- Each pair is delimited by an equals sign (`=`).
182
+
- To specify a Key Vault reference, use the format `<SECRET_NAME>=keyvaultref:<KEY_VAULT_SECRET_URI>,identityref:<MANAGED_IDENTITY_ID>`. For example, `queue-connection-string=keyvaultref:https://mykeyvault.vault.azure.net/secrets/queuereader,identityref:/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/my-resource-group/providers/Microsoft.ManagedIdentity/userAssignedIdentities/my-identity`.
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.
195
+
196
+
> [!NOTE]
197
+
> 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.
198
+
199
+
# [PowerShell](#tab/powershell)
200
+
201
+
Secrets Key Vault references aren't supported in PowerShell.
202
+
203
+
---
204
+
205
+
#### Key Vault secret URI and secret rotation
206
+
207
+
The Key Vault secret URI must be in one of the following formats:
208
+
209
+
*`https://myvault.vault.azure.net/secrets/mysecret/ec96f02080254f109c51a1f14cdb1931`: Reference a specific version of a secret.
210
+
*`https://myvault.vault.azure.net/secrets/mysecret`: Reference the latest version of a secret.
211
+
212
+
If a version isn't specified in the URI, then the app uses the latest version that exists in the key vault. When newer versions become available, the app automatically retrieves 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.
213
+
214
+
For full control of which version of a secret is used, specify the version in the URI.
215
+
100
216
## <aname="using-secrets"></a>Referencing secrets in environment variables
101
217
102
218
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.
103
219
104
-
## Example
220
+
###Example
105
221
106
222
The following example shows an application that declares a connection string at the application level. This connection is referenced in a container environment variable and in a scale rule.
107
223
224
+
# [Azure portal](#tab/azure-portal)
225
+
226
+
After you've [defined a secret](#defining-secrets) in your container app, you can reference it in an environment variable when you create a new revision.
227
+
228
+
1. Go to your container app in the [Azure portal](https://portal.azure.com).
229
+
230
+
1. Open the *Revision management* page.
231
+
232
+
1. Select **Create new revision**.
233
+
234
+
1. In the *Create and deploy new revision* page, select a container.
235
+
236
+
1. In the *Environment variables* section, select **Add**.
237
+
238
+
1. Enter the following information:
239
+
240
+
-**Name**: The name of the environment variable.
241
+
-**Source**: Select **Reference a secret**.
242
+
-**Value**: Select the secret you want to reference.
243
+
244
+
1. Select **Save**.
245
+
246
+
1. Select **Create** to create the new revision.
247
+
108
248
# [ARM template](#tab/arm-template)
109
249
110
250
In this example, the application connection string is declared as `queue-connection-string` and becomes available elsewhere in the configuration sections.
0 commit comments