Skip to content

Commit 57c99c9

Browse files
author
Jill Grant
authored
Merge pull request #289845 from anthonychu/20241104-sessions-update
[Container Apps] General updates to sessions docs
2 parents 8afc72d + 419fd7f commit 57c99c9

File tree

4 files changed

+179
-24
lines changed

4 files changed

+179
-24
lines changed
95.7 KB
Loading

articles/container-apps/sessions-code-interpreter.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,14 @@ Authorization: Bearer <TOKEN>
257257
}
258258
```
259259

260+
## Logging
261+
262+
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.
267+
260268
## Next steps
261269

262270
> [!div class="nextstepaction"]

articles/container-apps/sessions-custom-container.md

Lines changed: 146 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ az containerapp sessionpool create \
6363
--registry-username <USER_NAME> \
6464
--registry-password <PASSWORD> \
6565
--container-type CustomContainer \
66-
--image myregistry.azurecr.io/my-container-image:1.0 \
66+
--image myregistry.azurecr.io/my-container-image:1.0 \
6767
--cpu 0.25 --memory 0.5Gi \
6868
--target-port 80 \
6969
--cooldown-period 300 \
@@ -96,6 +96,16 @@ This command creates a session pool with the following settings:
9696
| `--env-vars` | `"key1=value1" "key2=value2"` | The environment variables to set in the container. |
9797
| `--location` | `"Supported Location"` | The location of the session pool. |
9898

99+
To check on the status of the session pool, use the `az containerapp sessionpool show` command:
100+
101+
```bash
102+
az containerapp sessionpool show \
103+
--name <SESSION_POOL_NAME> \
104+
--resource-group <RESOURCE_GROUP> \
105+
--query "properties.poolManagementEndpoint" \
106+
--output tsv
107+
```
108+
99109
To update the session pool, use the `az containerapp sessionpool update` command.
100110

101111
# [Azure Resource Manager](#tab/arm)
@@ -107,7 +117,7 @@ Before you send the request, replace the placeholders between the `<>` brackets
107117
```json
108118
{
109119
"type": "Microsoft.App/sessionPools",
110-
"apiVersion": "2024-02-02-preview",
120+
"apiVersion": "2024-08-02-preview",
111121
"name": "my-session-pool",
112122
"location": "westus2",
113123
"properties": {
@@ -122,7 +132,18 @@ Before you send the request, replace the placeholders between the `<>` brackets
122132
"executionType": "Timed",
123133
"cooldownPeriodInSeconds": 600
124134
},
135+
"secrets": [
136+
{
137+
"name": "registrypassword",
138+
"value": "<REGISTRY_PASSWORD>"
139+
}
140+
],
125141
"customContainerTemplate": {
142+
"registryCredentials": {
143+
"server": "myregistry.azurecr.io",
144+
"username": "myregistry",
145+
"passwordSecretRef": "registrypassword"
146+
},
126147
"containers": [
127148
{
128149
"image": "myregistry.azurecr.io/my-container-image:1.0",
@@ -174,6 +195,10 @@ This template creates a session pool with the following settings:
174195
| `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. |
175196
| `dynamicPoolConfiguration.executionType` | `Timed` | The type of execution for the session pool. Must be `Timed` for custom container sessions. |
176197
| `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. |
177202
| `customContainerTemplate.containers[0].image` | `myregistry.azurecr.io/my-container-image:1.0` | The container image to use for the session pool. |
178203
| `customContainerTemplate.containers[0].name` | `mycontainer` | The name of the container. |
179204
| `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:
189214
> [!IMPORTANT]
190215
> 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.
191216
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+
192223
### Working with sessions
193224

194225
Your application interacts with a session using the session pool's management API.
195226

196227
A pool management endpoint for custom container sessions follows this format: `https://<SESSION_POOL>.<ENVIRONMENT_ID>.<REGION>.azurecontainerapps.io`.
197228

198229
To retrieve the session pool's management endpoint, use the `az containerapp sessionpool show` command:
230+
199231
```bash
200232
az containerapp sessionpool show \
201233
--name <SESSION_POOL_NAME> \
@@ -240,6 +272,118 @@ This request is forwarded to the custom container session with the identifier fo
240272

241273
In the example, the session's container receives the request at `http://0.0.0.0:<INGRESS_PORT>/<API_PATH_EXPOSED_BY_CONTAINER>`.
242274

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.
299+
300+
```json
301+
{
302+
"type": "Microsoft.App/sessionPools",
303+
"apiVersion": "2024-08-02-preview",
304+
"name": "my-session-pool",
305+
"location": "westus2",
306+
"properties": {
307+
"environmentId": "/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/providers/Microsoft.ContainerApps/environments/<ENVIRONMENT_NAME>",
308+
"poolManagementType": "Dynamic",
309+
"containerType": "CustomContainer",
310+
"scaleConfiguration": {
311+
"maxConcurrentSessions": 10,
312+
"readySessionInstances": 5
313+
},
314+
"dynamicPoolConfiguration": {
315+
"executionType": "Timed",
316+
"cooldownPeriodInSeconds": 600
317+
},
318+
"customContainerTemplate": {
319+
"registryCredentials": {
320+
"server": "myregistry.azurecr.io",
321+
"identity": "<IDENTITY_RESOURCE_ID>"
322+
},
323+
"containers": [
324+
{
325+
"image": "myregistry.azurecr.io/my-container-image:1.0",
326+
"name": "mycontainer",
327+
"resources": {
328+
"cpu": 0.25,
329+
"memory": "0.5Gi"
330+
},
331+
"command": [
332+
"/bin/sh"
333+
],
334+
"args": [
335+
"-c",
336+
"while true; do echo hello; sleep 10;done"
337+
],
338+
"env": [
339+
{
340+
"name": "key1",
341+
"value": "value1"
342+
},
343+
{
344+
"name": "key2",
345+
"value": "value2"
346+
}
347+
]
348+
}
349+
],
350+
"ingress": {
351+
"targetPort": 80
352+
}
353+
},
354+
"sessionNetworkConfiguration": {
355+
"status": "EgressEnabled"
356+
},
357+
"managedIdentitySettings": [
358+
{
359+
"identity": "<IDENTITY_RESOURCE_ID>",
360+
"lifecycle": "None"
361+
}
362+
]
363+
},
364+
"identity": {
365+
"type": "UserAssigned",
366+
"userAssignedIdentities": {
367+
"<IDENTITY_RESOURCE_ID>": {}
368+
}
369+
}
370+
}
371+
```
372+
373+
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+
243387
## Billing
244388

245389
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).

articles/container-apps/sessions.md

Lines changed: 25 additions & 22 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: conceptual
8-
ms.date: 04/04/2024
8+
ms.date: 11/04/2024
99
ms.author: cshoe
1010
ms.custom: references_regions
1111
---
@@ -60,24 +60,30 @@ You can configure pools to set the maximum number of sessions that can be alloca
6060

6161
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.
6262

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.
6464

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).
6666

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
6968

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.
7170

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
7377

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.
7579

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.
7781

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
7985

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.
8187

8288
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.
8389

@@ -89,22 +95,17 @@ Example strategies include:
8995
> [!IMPORTANT]
9096
> Failure to secure access to sessions may result in misuse or unauthorized access to data stored in your users' sessions.
9197
92-
### Authentication
98+
### <a name="authentication"></a>Authentication and authorization
9399

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.
95101

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:
97103

98104
```bash
99105
az role assignment create \
100106
--role "Azure ContainerApps Session Executor" \
101107
--assignee <PRINCIPAL_ID> \
102108
--scope <SESSION_POOL_RESOURCE_ID>
103-
104-
az role assignment create \
105-
--role "Contributor" \
106-
--assignee <PRINCIPAL_ID> \
107-
--scope <SESSION_POOL_RESOURCE_ID>
108109
```
109110

110111
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
177178
---
178179

179180
> [!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.
181182
182183
#### Lifecycle
183184

@@ -195,6 +196,10 @@ The Container Apps runtime automatically manages the lifecycle for each session
195196

196197
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.
197198

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+
198203
## Preview limitations
199204

200205
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
211216
| North Central US || - |
212217
| North Europe |||
213218
| West US 2 |||
214-
215-
* Logging isn't supported. Your application can log requests to the session pool management API and its responses.
216219

217220
## Next steps
218221

0 commit comments

Comments
 (0)