Skip to content

Commit f937906

Browse files
Merge pull request #277229 from vturecek/capps-msi-keda
Container Apps: KEDA and identity settings
2 parents a4c102e + 78c6d10 commit f937906

File tree

1 file changed

+93
-2
lines changed

1 file changed

+93
-2
lines changed

articles/container-apps/managed-identity.md

Lines changed: 93 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ User-assigned identities are ideal for workloads that:
4646

4747
## Limitations
4848

49-
- Managed identities in scale rules isn't supported. You need to include connection strings or keys in the `secretRef` of the scaling rule.
50-
- [Init containers](containers.md#init-containers) can't access managed identities.
49+
[Init containers](containers.md#init-containers) can't access managed identities in [consumption-only environments](environment.md#types) and [dedicated workload profile environments](environment.md#types)
5150

5251
## Configure managed identities
5352

@@ -351,6 +350,98 @@ To get a token for a resource, make an HTTP `GET` request to the endpoint, inclu
351350

352351
---
353352

353+
## Use managed identity for scale rules
354+
355+
Starting in API version `2024-02-02-preview`, you can use managed identities in your scale rules to authenticate with Azure services that support managed identities. To use a managed identity in your scale rule, use the `identity` property instead of the `auth` property in your scale rule. Acceptable values for the `identity` property are either the Azure resource ID of a user-assigned identity, or `system` to use a system-assigned identity
356+
357+
The following example shows how to use a managed identities with an Azure Queue Storage scale rule. The queue storage account uses the `accountName` property to identify the storage account, while the `identity` property specifies which managed identity to use. You do not need to use the `auth` property.
358+
359+
```json
360+
"scale": {
361+
"minReplicas": 1,
362+
"maxReplicas": 10,
363+
"rules": [{
364+
"name": "myQueueRule",
365+
"azureQueue": {
366+
"accountName": "mystorageaccount",
367+
"queueName": "myqueue",
368+
"queueLength": 2,
369+
"identity": "<IDENTITY1_RESOURCE_ID>"
370+
}
371+
}]
372+
}
373+
```
374+
375+
## Control managed identity availability
376+
377+
Container Apps allow you to specify [init containers](containers.md#init-containers) and main containers. By default, both main and init containers in a consumption workload profile environment can use managed identity to access other Azure services. In consumption-only environments and dedicated workload profile environments, only main containers can use managed identity. Managed identity access tokens are available for every managed identity configured on the container app. However, in some situations only the init container or the main container require access tokens for a managed identity. Other times, you may use a managed identity only to access your Azure Container Registry to pull the container image, and your application itself doesn't need to have access to your Azure Container Registry.
378+
379+
Starting in API version `2024-02-02-preview`, you can control which managed identities are available to your container app during the init and main phases to follow the security principle of least privilege. The following options are available:
380+
381+
- `Init`: available only to init containers. Use this when you want to perform some intilization work that requires a managed identity, but you no longer need the managed identity in the main container. This option is currently only supported in [workload profile consumption environments](environment.md#types)
382+
- `Main`: available only to main containers. Use this if your init container does not need managed identity.
383+
- `All`: available to all containers. This is the default setting.
384+
- `None`: not available to any containers. Use this when you have a managed identity that is only used for ACR image pull, scale rules, or Key Vault secrets and does not need to be available to the code running in your containers.
385+
386+
The following example shows how to configure a container app on a workload profile consumption environment that:
387+
388+
- Restricts the container app's system-assigned identity to main containers only.
389+
- Restricts a specific user-assigned identity to init containers only.
390+
- Uses a specific user-assigned identity for Azure Container Registry image pull without allowing the code in the containers to use that managed identity to access the registry. In this example, the containers themselves don't need to access the registry.
391+
392+
This approach limits the resources that can be accessed if a malicious actor were to gain unauthorized access to the containers.
393+
394+
```json
395+
{
396+
"location": "eastus2",
397+
"identity":{
398+
"type": "SystemAssigned, UserAssigned",
399+
"userAssignedIdentities": {
400+
"<IDENTITY1_RESOURCE_ID>":{},
401+
"<ACR_IMAGEPULL_IDENTITY_RESOURCE_ID>":{}
402+
}
403+
},
404+
"properties": {
405+
"workloadProfileName":"Consumption",
406+
"environmentId": "<CONTAINER_APPS_ENVIRONMENT_ID>",
407+
"configuration": {
408+
"registries": [
409+
{
410+
"server": "myregistry.azurecr.io",
411+
"identity": "ACR_IMAGEPULL_IDENTITY_RESOURCE_ID"
412+
}],
413+
"identitySettings":[
414+
{
415+
"identity": "ACR_IMAGEPULL_IDENTITY_RESOURCE_ID",
416+
"lifecycle": "none"
417+
},
418+
{
419+
"identity": "<IDENTITY1_RESOURCE_ID>",
420+
"lifecycle": "init"
421+
},
422+
{
423+
"identity": "system",
424+
"lifecycle": "main"
425+
}]
426+
},
427+
"template": {
428+
"containers":[
429+
{
430+
"image":"myregistry.azurecr.io/main:1.0",
431+
"name":"app-main"
432+
}
433+
],
434+
"initContainers":[
435+
{
436+
"image":"myregistry.azurecr.io/init:1.0",
437+
"name":"app-init",
438+
}
439+
]
440+
}
441+
}
442+
}
443+
```
444+
354445
## View managed identities
355446

356447
You can show the system-assigned and user-assigned managed identities using the following Azure CLI command. The output shows the managed identity type, tenant IDs and principal IDs of all managed identities assigned to your container app.

0 commit comments

Comments
 (0)