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
Code interpreter sessions don't support logging directly. Your application that's interacting with the sessions can log requests to the session pool management API and its responses.
263
+
264
+
## Billing
265
+
266
+
Code interpreter sessions are billed based on the duration of each session. See [Billing](billing.md#dynamic-sessions) for more information.
@@ -174,6 +195,10 @@ This template creates a session pool with the following settings:
174
195
|`scaleConfiguration.readySessionInstances`|`5`| The target number of sessions that are ready in the session pool all the time. Increase this number if sessions are allocated faster than the pool is being replenished. |
175
196
|`dynamicPoolConfiguration.executionType`|`Timed`| The type of execution for the session pool. Must be `Timed` for custom container sessions. |
176
197
|`dynamicPoolConfiguration.cooldownPeriodInSeconds`|`600`| The number of seconds that a session can be idle before the session is terminated. The idle period is reset each time the session's API is called. Value must be between `300` and `3600`. |
198
+
|`secrets`|`[{ "name": "registrypassword", "value": "<REGISTRY_PASSWORD>" }]`| A list of secrets. |
199
+
|`customContainerTemplate.registryCredentials.server`|`myregistry.azurecr.io`| The container registry server hostname. |
200
+
|`customContainerTemplate.registryCredentials.username`|`myregistry`| The username to log in to the container registry. |
201
+
|`customContainerTemplate.registryCredentials.passwordSecretRef`|`registrypassword`| The name of the secret that contains the password to log in to the container registry. |
177
202
|`customContainerTemplate.containers[0].image`|`myregistry.azurecr.io/my-container-image:1.0`| The container image to use for the session pool. |
178
203
|`customContainerTemplate.containers[0].name`|`mycontainer`| The name of the container. |
179
204
|`customContainerTemplate.containers[0].resources.cpu`|`0.25`| The required CPU in cores. |
@@ -189,13 +214,20 @@ This template creates a session pool with the following settings:
189
214
> [!IMPORTANT]
190
215
> If the session is used to run untrusted code, don't include information or data that you don't want the untrusted code to access. Assume the code is malicious and has full access to the container, including its environment variables, secrets, and files.
191
216
217
+
#### Image caching
218
+
219
+
When a session pool is created or updated, Azure Container Apps caches the container image in the pool. This caching helps speed up the process of creating new sessions.
220
+
221
+
Any changes to the image aren't automatically reflected in the sessions. To update the image, update the session pool with a new image tag. Use a unique tag for each image update to ensure that the new image is pulled.
222
+
192
223
### Working with sessions
193
224
194
225
Your application interacts with a session using the session pool's management API.
195
226
196
227
A pool management endpoint for custom container sessions follows this format: `https://<SESSION_POOL>.<ENVIRONMENT_ID>.<REGION>.azurecontainerapps.io`.
197
228
198
229
To retrieve the session pool's management endpoint, use the `az containerapp sessionpool show` command:
230
+
199
231
```bash
200
232
az containerapp sessionpool show \
201
233
--name <SESSION_POOL_NAME> \
@@ -240,6 +272,118 @@ This request is forwarded to the custom container session with the identifier fo
240
272
241
273
In the example, the session's container receives the request at `http://0.0.0.0:<INGRESS_PORT>/<API_PATH_EXPOSED_BY_CONTAINER>`.
242
274
275
+
### Using managed identity
276
+
277
+
A managed identity from Microsoft Entra ID allows your custom container session pools and their sessions to access other Microsoft Entra protected resources. For more about managed identities in Microsoft Entra ID, see [Managed identities for Azure resources](../active-directory/managed-identities-azure-resources/overview.md).
278
+
279
+
You can enable managed identities for your custom container session pools. Both system-assigned and user-assigned managed identities are supported.
280
+
281
+
There are two ways to use managed identities with custom container session pools:
282
+
283
+
***Image pull authentication**: Use the managed identity to authenticate with the container registry to pull the container image.
284
+
285
+
***Resource access**: Use the session pool's managed identity in a session to access other Microsoft Entra protected resources. Due to its security implications, this capability is disabled by default.
286
+
287
+
> [!IMPORTANT]
288
+
> If you enable access to managed identity in a session, any code or programs running in the session can create Entra tokens for the pool's managed identity. Since sessions typically run untrusted code, use this feature with caution.
289
+
290
+
# [Azure CLI](#tab/azure-cli)
291
+
292
+
To enable managed identity for a custom container session pool, use Azure Resource Manager.
293
+
294
+
# [Azure Resource Manager](#tab/arm)
295
+
296
+
To enable managed identity for a custom container session pool, add an `identity` property to the session pool resource. The `identity` property must have a `type` property with the value `SystemAssigned` or `UserAssigned`. For details on how to configure this property, see [Configure managed identities](managed-identity.md?tabs=arm%2Cdotnet#configure-managed-identities).
297
+
298
+
The following example shows an ARM template snippet that enables a user-assigned identity for a custom container session pool and use it for image pull authentication. Before you send the request, replace the placeholders between the `<>` brackets with the appropriate values for your session pool and session identifier.
This template contains the following additional settings for managed identity:
374
+
375
+
| Parameter | Value | Description |
376
+
|---------|-------|-------------|
377
+
|`customContainerTemplate.registryCredentials.identity`|`<IDENTITY_RESOURCE_ID>`| The resource ID of the managed identity to use for image pull authentication. |
378
+
|`managedIdentitySettings.identity`|`<IDENTITY_RESOURCE_ID>`| The resource ID of the managed identity to use in the session. |
379
+
|`managedIdentitySettings.lifecycle`|`None`| The session lifecycle where the managed identity is available.<br><br>- `None` (default): The session can't access the identity. It's only used for image pull.<br><br>- `Main`: In addition to image pull, the main session can also access the identity. **Use with caution.**|
380
+
381
+
---
382
+
383
+
## Logging
384
+
385
+
Console logs from custom container sessions are available in the Azure Log Analytics workspace associated with the Azure Container Apps environment in a table named `AppEnvSessionConsoleLogs_CL`.
386
+
243
387
## Billing
244
388
245
389
Custom container sessions are billed based on the resources consumed by the session pool. For more information, see [Azure Container Apps billing](billing.md#custom-container).
Copy file name to clipboardExpand all lines: articles/container-apps/sessions.md
+25-22Lines changed: 25 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ services: container-apps
5
5
author: craigshoemaker
6
6
ms.service: azure-container-apps
7
7
ms.topic: conceptual
8
-
ms.date: 04/04/2024
8
+
ms.date: 11/04/2024
9
9
ms.author: cshoe
10
10
ms.custom: references_regions
11
11
---
@@ -60,24 +60,30 @@ You can configure pools to set the maximum number of sessions that can be alloca
60
60
61
61
A session is a sandboxed environment that runs your code or application. Each session is isolated from other sessions and from the host environment with a [Hyper-V](/windows-server/virtualization/hyper-v/hyper-v-technology-overview) sandbox. Optionally, you can enable network isolation to further enhance security.
62
62
63
-
#### Session identifiers
63
+
You interact with sessions in a session pool by sending HTTP requests. Each session pool has a unique pool management endpoint.
64
64
65
-
When you interact with sessions in a pool, you must define a session identifier to manage each session. The session identifier is a free-form string, meaning you can define it in any way that suits your application's needs. This identifier is a key element in determining the behavior of the session:
65
+
For code interpreter sessions, you can also use an integration with an [LLM framework](./sessions-code-interpreter.md#llm-framework-integrations).
66
66
67
-
- Reuse of existing sessions: This session is reused if there's already a running session that matches the identifier.
68
-
- Allocation of new sessions: If no running session matches the identifier, a new session is automatically allocated from the pool.
67
+
### Session identifiers
69
68
70
-
The session identifier is a string that you define that is unique within the session pool. If you're building a web application, you can use the user's ID. If you're building a chatbot, you can use the conversation ID.
69
+
To send an HTTP request to a session, you must provide a session identifier in the request. You pass the session identifier in a query parameter named `identifier` in the URL when you make a request to a session.
71
70
72
-
The identifier must be a string that is 4 to 128 characters long and can contain only alphanumeric characters and special characters from this list: `|`, `-`, `&`, `^`, `%`, `$`, `#`, `(`, `)`, `{`, `}`, `[`, `]`, `;`, `<`, and `>`.
71
+
* If a session with the identifier already exists, the request is sent to the existing session.
72
+
* If a session with the identifier doesn't exist, a new session is automatically allocated before the request is sent to it.
73
+
74
+
:::image type="content" source="media/sessions/sessions-overview.png" alt-text="Screenshot of session pool and sessions usage.":::
75
+
76
+
#### Identifier format
73
77
74
-
You pass the session identifier in a query parameter named `identifier` in the URL when you make a request to a session.
78
+
The session identifier is a free-form string, meaning you can define it in any way that suits your application's needs.
75
79
76
-
For code interpreter sessions, you can also use an integration with an [LLM framework](./sessions-code-interpreter.md#llm-framework-integrations). The framework handles the token generation and management for you. Ensure that the application is configured with a managed identity that has the necessary role assignments on the session pool.
80
+
The session identifier is a string that you define that is unique within the session pool. If you're building a web application, you can use the user's ID as the session identifier. If you're building a chatbot, you can use the conversation ID.
77
81
78
-
##### Protecting session identifiers
82
+
The identifier must be a string that is 4 to 128 characters long and can contain only alphanumeric characters and special characters from this list: `|`, `-`, `&`, `^`, `%`, `$`, `#`, `(`, `)`, `{`, `}`, `[`, `]`, `;`, `<`, and `>`.
83
+
84
+
#### Protecting session identifiers
79
85
80
-
The session identifier is sensitive information which requires a secure process as you create and manage its value. To protect this value, your application must ensure each user or tenant only has access to their own sessions.
86
+
The session identifier is sensitive information which you must manage securely. Your application needs to ensure each user or tenant only has access to their own sessions.
81
87
82
88
The specific strategies that prevent misuse of session identifiers differ depending on the design and architecture of your app. However, your app must always have complete control over the creation and use of session identifiers so that a malicious user can't access another user's session.
83
89
@@ -89,22 +95,17 @@ Example strategies include:
89
95
> [!IMPORTANT]
90
96
> Failure to secure access to sessions may result in misuse or unauthorized access to data stored in your users' sessions.
91
97
92
-
### Authentication
98
+
### <aname="authentication"></a>Authentication and authorization
93
99
94
-
Authentication is handled using Microsoft Entra (formerly Azure Active Directory) tokens. Valid Microsoft Entra tokens are generated by an identity belonging to the *Azure ContainerApps Session Executor*and *Contributor* roles on the session pool.
100
+
When you send requests to a session using the pool management API, authentication is handled using Microsoft Entra (formerly Azure Active Directory) tokens. Only Microsoft Entra tokens from an identity belonging to the *Azure ContainerApps Session Executor*role on the session pool are authorized to call the pool management API.
95
101
96
-
To assign the roles to an identity, use the following Azure CLI commands:
102
+
To assign the role to an identity, use the following Azure CLI command:
97
103
98
104
```bash
99
105
az role assignment create \
100
106
--role "Azure ContainerApps Session Executor" \
101
107
--assignee <PRINCIPAL_ID> \
102
108
--scope <SESSION_POOL_RESOURCE_ID>
103
-
104
-
az role assignment create \
105
-
--role "Contributor" \
106
-
--assignee <PRINCIPAL_ID> \
107
-
--scope <SESSION_POOL_RESOURCE_ID>
108
109
```
109
110
110
111
If you're using an [LLM framework integration](sessions-code-interpreter.md#llm-framework-integrations), the framework handles the token generation and management for you. Ensure that the application is configured with a managed identity with the necessary role assignments on the session pool.
@@ -177,7 +178,7 @@ access_token = token.token
177
178
---
178
179
179
180
> [!IMPORTANT]
180
-
> A valid token can be used to create and access any session in the pool. Keep your tokens secure and don't share them with untrusted parties. End users should access sessions through your application, not directly.
181
+
> A valid token can be used to create and access any session in the pool. Keep your tokens secure and don't share them with untrusted parties. End users should access sessions through your application, not directly. They should never have access to the tokens used to authenticate requests to the session pool.
181
182
182
183
#### Lifecycle
183
184
@@ -195,6 +196,10 @@ The Container Apps runtime automatically manages the lifecycle for each session
195
196
196
197
Azure Container Apps dynamic sessions are built to run untrusted code and applications in a secure and isolated environment. While sessions are isolated from one another, anything within a single session, including files and environment variables, is accessible by users of the session. You should only configure or upload sensitive data to a session if you trust the users of the session.
197
198
199
+
By default, sessions are prevented from making outbound network requests. You can control network access by configuring network status settings on the session pool.
200
+
201
+
In addition, follow the guidance in the [authentication and authorization](#authentication) section to ensure that only authorized users can access sessions and in the [protecting session identifiers](#protecting-session-identifiers) section to ensure that session identifiers are secure.
202
+
198
203
## Preview limitations
199
204
200
205
Azure Container Apps dynamic sessions is currently in preview. The following limitations apply:
@@ -211,8 +216,6 @@ Azure Container Apps dynamic sessions is currently in preview. The following lim
211
216
| North Central US | ✔ | - |
212
217
| North Europe | ✔ | ✔ |
213
218
| West US 2 | ✔ | ✔ |
214
-
215
-
* Logging isn't supported. Your application can log requests to the session pool management API and its responses.
0 commit comments