Skip to content

Commit 17a407f

Browse files
committed
Update inaccurate Batch task user account isolation
1 parent 48a1747 commit 17a407f

File tree

2 files changed

+32
-24
lines changed

2 files changed

+32
-24
lines changed

articles/batch/batch-user-accounts.md

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Run tasks under user accounts
33
description: Learn the types of user accounts and how to configure them.
44
ms.topic: how-to
5-
ms.date: 08/27/2024
5+
ms.date: 02/28/2025
66
ms.custom:
77
ms.devlang: csharp
88
# ms.devlang: csharp, java, python
@@ -13,16 +13,14 @@ ms.devlang: csharp
1313
> The user accounts discussed in this article are different from user accounts used for Remote Desktop Protocol (RDP) or Secure Shell (SSH), for security reasons.
1414
>
1515
> To connect to a node running the Linux virtual machine configuration via SSH, see [Install and configure xrdp to use Remote Desktop with Ubuntu](/azure/virtual-machines/linux/use-remote-desktop). To connect to nodes running Windows via RDP, see [How to connect and sign on to an Azure virtual machine running Windows](/azure/virtual-machines/windows/connect-logon).
16-
>
17-
> To connect to a node running the via RDP, see [Enable Remote Desktop Connection for a Role in Azure Cloud Services](../cloud-services/cloud-services-role-enable-remote-desktop-new-portal.md).
1816
1917
A task in Azure Batch always runs under a user account. By default, tasks run under standard user accounts, without administrator permissions. For certain scenarios, you may want to configure the user account under which you want a task to run. This article discusses the types of user accounts and how to configure them for your scenario.
2018

2119
## Types of user accounts
2220

2321
Azure Batch provides two types of user accounts for running tasks:
2422

25-
- **Auto-user accounts.** Auto-user accounts are built-in user accounts that are created automatically by the Batch service. By default, tasks run under an auto-user account. You can configure the auto-user specification for a task to indicate under which auto-user account a task should run. The auto-user specification allows you to specify the elevation level and scope of the auto-user account that will run the task.
23+
- **Auto-user accounts.** Auto-user accounts are built-in user accounts that are created automatically by the Batch service. By default, tasks run under an auto-user account. You can configure the auto-user specification for a task to indicate under which auto-user account a task should run. The auto-user specification allows you to specify the elevation level and scope of the auto-user account that runs the task.
2624

2725
- **A named user account.** You can specify one or more named user accounts for a pool when you create the pool. Each user account is created on each node of the pool. In addition to the account name, you specify the user account password, elevation level, and, for Linux pools, the SSH private key. When you add a task, you can specify the named user account under which that task should run.
2826

@@ -35,6 +33,12 @@ Both an auto-user account and a named user account have read/write access to the
3533

3634
If a task runs under the same account that was used for running a start task, the task has read-write access to the start task directory. Similarly, if a task runs under the same account that was used for running a job preparation task, the task has read-write access to the job preparation task directory. If a task runs under a different account than the start task or job preparation task, then the task has only read access to the respective directory.
3735

36+
> [!IMPORTANT]
37+
> Distinct task users in Batch aren't a sufficient security boundary for isolation between tasks and its associated task data.
38+
> In Batch, the security isolation boundary is at the pool level. However improper access control of the Batch
39+
> API can lead to access of all pools under a Batch account with sufficient permission. Refer to best practices about
40+
> [pool security](best-practices.md#pool-security).
41+
3842
For more information on accessing files and directories from a task, see [Files and directories](files-and-directories.md).
3943

4044
## Elevated access for tasks
@@ -57,15 +61,18 @@ There are four possible configurations for the auto-user specification, each of
5761
- Non-admin access with pool scope
5862
- Admin access with pool scope
5963

60-
> [!IMPORTANT]
61-
> Tasks running under task scope do not have de facto access to other tasks on a node. However, a malicious user with access to the account could work around this restriction by submitting a task that runs with administrator privileges and accesses other task directories. A malicious user could also use RDP or SSH to connect to a node. It's important to protect access to your Batch account keys to prevent such a scenario. If you suspect your account may have been compromised, be sure to regenerate your keys.
64+
> [!NOTE]
65+
> Auto-user accounts with elevated admin access have direct write access to all other task directories on the compute node executing
66+
> the task. Consider running your tasks with the least privilege required for successful execution.
6267
6368
### Run a task as an auto-user with elevated access
6469

6570
You can configure the auto-user specification for administrator privileges when you need to run a task with elevated access. For example, a start task may need elevated access to install software on the node.
6671

6772
> [!NOTE]
68-
> Use elevated access only when necessary. Best practices recommend granting the minimum privilege necessary to achieve the desired outcome. For example, if a start task installs software for the current user, instead of for all users, you may be able to avoid granting elevated access to tasks. You can configure the auto-user specification for pool scope and non-admin access for all tasks that need to run under the same account, including the start task.
73+
> Use elevated access only when necessary. A typical use case for using elevated admin access is for a start task that must install
74+
> software on the compute node before other tasks can be scheduled. For subsequent tasks, you should use the installed software
75+
> as a task user without elevation.
6976
7077
The following code snippets show how to configure the auto-user specification. The examples set the elevation level to `Admin` and the scope to `Task`.
7178

@@ -106,14 +113,12 @@ When a node is provisioned, two pool-wide auto-user accounts are created on each
106113

107114
When you specify pool scope for the auto-user, all tasks that run with administrator access run under the same pool-wide auto-user account. Similarly, tasks that run without administrator permissions also run under a single pool-wide auto-user account.
108115

109-
> [!NOTE]
110-
> The two pool-wide auto-user accounts are separate accounts. Tasks running under the pool-wide administrative account can't share data with tasks running under the standard account, and vice versa.
111-
112-
The advantage to running under the same auto-user account is that tasks are able to share data with other tasks running on the same node.
116+
The advantage to running under the same auto-user account is that tasks are able to easily share data with other tasks running
117+
on the same node. There are also performance benefits to user account reuse.
113118

114119
Sharing secrets between tasks is one scenario where running tasks under one of the two pool-wide auto-user accounts is useful. For example, suppose a start task needs to provision a secret onto the node that other tasks can use. You could use the Windows Data Protection API (DPAPI), but it requires administrator privileges. Instead, you can protect the secret at the user level. Tasks running under the same user account can access the secret without elevated access.
115120

116-
Another scenario where you may want to run tasks under an auto-user account with pool scope is a Message Passing Interface (MPI) file share. An MPI file share is useful when the nodes in the MPI task need to work on the same file data. The head node creates a file share that the child nodes can access if they are running under the same auto-user account.
121+
Another scenario where you may want to run tasks under an auto-user account with pool scope is a Message Passing Interface (MPI) file share. An MPI file share is useful when the nodes in the MPI task need to work on the same file data. The head node creates a file share that the child nodes can access if they're running under the same auto-user account.
117122

118123
The following code snippet sets the auto-user's scope to pool scope for a task in Batch .NET. The elevation level is omitted, so the task runs under the standard pool-wide auto-user account.
119124

@@ -146,13 +151,13 @@ Console.WriteLine("Creating pool [{0}]...", poolId);
146151
// Create a pool using Virtual Machine Configuration.
147152
pool = batchClient.PoolOperations.CreatePool(
148153
poolId: poolId,
149-
targetDedicatedComputeNodes: 3,
150-
virtualMachineSize: "standard_d1_v2",
154+
targetDedicatedComputeNodes: 2,
155+
virtualMachineSize: "standard_d2s_v3",
151156
VirtualMachineConfiguration: new VirtualMachineConfiguration(
152157
imageReference: new ImageReference(
153158
publisher: "MicrosoftWindowsServer",
154159
offer: "WindowsServer",
155-
sku: "2019-datacenter-core",
160+
sku: "2022-datacenter-core",
156161
version: "latest"),
157162
nodeAgentSkuId: "batch.node.windows amd64");
158163

@@ -177,19 +182,18 @@ List<NodeAgentSku> nodeAgentSkus =
177182
batchClient.PoolOperations.ListNodeAgentSkus().ToList();
178183

179184
// Define a delegate specifying properties of the VM image to use.
180-
Func<ImageReference, bool> isUbuntu1804 = imageRef =>
185+
Func<ImageReference, bool> isUbuntu2404 = imageRef =>
181186
imageRef.Publisher == "Canonical" &&
182-
imageRef.Offer == "UbuntuServer" &&
183-
imageRef.Sku.Contains("20.04-LTS");
187+
imageRef.Offer == "ubuntu-24_04-lts" &&
188+
imageRef.Sku.Contains("server");
184189

185190
// Obtain the first node agent SKU in the collection that matches
186-
// Ubuntu Server 20.04.
187191
NodeAgentSku ubuntuAgentSku = nodeAgentSkus.First(sku =>
188-
sku.VerifiedImageReferences.Any(isUbuntu2004));
192+
sku.VerifiedImageReferences.Any(isUbuntu2404));
189193

190194
// Select an ImageReference from those available for node agent.
191195
ImageReference imageReference =
192-
ubuntuAgentSku.VerifiedImageReferences.First(isUbuntu2004);
196+
ubuntuAgentSku.VerifiedImageReferences.First(isUbuntu2404);
193197

194198
// Create the virtual machine configuration to use to create the pool.
195199
VirtualMachineConfiguration virtualMachineConfiguration =
@@ -200,8 +204,8 @@ Console.WriteLine("Creating pool [{0}]...", poolId);
200204
// Create the unbound pool.
201205
pool = batchClient.PoolOperations.CreatePool(
202206
poolId: poolId,
203-
targetDedicatedComputeNodes: 3,
204-
virtualMachineSize: "Standard_A1",
207+
targetDedicatedComputeNodes: 2,
208+
virtualMachineSize: "Standard_d2s_v3",
205209
virtualMachineConfiguration: virtualMachineConfiguration);
206210
// Add named user accounts.
207211
pool.UserAccounts = new List<UserAccount>

articles/batch/best-practices.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Best practices
33
description: Learn best practices and useful tips for developing your Azure Batch solutions.
4-
ms.date: 06/27/2024
4+
ms.date: 02/28/2025
55
ms.topic: conceptual
66
---
77

@@ -65,6 +65,10 @@ supported indefinitely. An EOL date may be added or updated in the future at any
6565

6666
For the purposes of isolation, if your scenario requires isolating jobs or tasks from each other, do so by having them in separate pools. A pool is the security isolation boundary in Batch, and by default, two pools aren't visible or able to communicate with each other. Avoid using separate Batch accounts as a means of security isolation unless the larger environment from which the Batch account operates in requires isolation.
6767

68+
If desired, proper access control must be applied on the Batch account and APIs to prevent access to all pools under the Batch account.
69+
It's recommended to disable shared key access and only allow Entra-based authentication to enable
70+
[role-based access control](batch-role-based-access-control.md).
71+
6872
#### Batch Node Agent updates
6973

7074
Batch node agents aren't automatically upgraded for pools that have nonzero compute nodes. To ensure your Batch pools receive the latest security fixes and updates to the Batch node agent, you need to either resize the pool to zero compute nodes or recreate the pool. It's recommended to monitor the [Batch Node Agent release notes](https://github.com/Azure/Batch/blob/master/changelogs/nodeagent/CHANGELOG.md) to understand changes to new Batch node agent versions. Checking regularly for updates when they were released enables you to plan upgrades to the latest agent version.

0 commit comments

Comments
 (0)