Skip to content

Commit de62c0f

Browse files
authored
Merge pull request #286418 from wiboris/patch-2
Update Batch Documents to improve best practices for security
2 parents 62e44ec + 981e17c commit de62c0f

File tree

2 files changed

+115
-118
lines changed

2 files changed

+115
-118
lines changed

articles/batch/batch-docker-container-workloads.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,7 @@ ImageReference imageReference = new ImageReference(
245245

246246
ContainerRegistry containerRegistry = new ContainerRegistry(
247247
registryServer: "https://hub.docker.com",
248-
userName: "UserName",
249-
password: "YourPassword"
248+
identityReference: new ComputeNodeIdentityReference() { ResourceId = "/subscriptions/SUB/resourceGroups/RG/providers/Microsoft.ManagedIdentity/userAssignedIdentities/identity-name" }
250249
);
251250

252251
// Specify container configuration, prefetching Docker images
@@ -286,10 +285,14 @@ image_ref_to_use = batch.models.ImageReference(
286285
version='latest')
287286

288287
# Specify a container registry
288+
subscription_id = "yyyy-yyy-yyy-yyy-yyy"
289+
resource_group_name = "TestRG"
290+
user_assigned_identity_name = "testUMI"
291+
resource_id = f"/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{user_assigned_identity_name}"
292+
289293
container_registry = batch.models.ContainerRegistry(
290294
registry_server="myRegistry.azurecr.io",
291-
user_name="myUsername",
292-
password="myPassword")
295+
identity_reference = ComputeNodeIdentityReference(resource_id = resource_id))
293296

294297
# Create container configuration, prefetching Docker images from the container registry
295298
container_conf = batch.models.ContainerConfiguration(
@@ -310,8 +313,8 @@ new_pool = batch.models.PoolAddParameter(
310313
// Specify a container registry
311314
ContainerRegistry containerRegistry = new ContainerRegistry(
312315
registryServer: "myContainerRegistry.azurecr.io",
313-
userName: "myUserName",
314-
password: "myPassword");
316+
identityReference: new ComputeNodeIdentityReference() { ResourceId = "/subscriptions/SUB/resourceGroups/RG/providers/Microsoft.ManagedIdentity/userAssignedIdentities/identity-name" }
317+
);
315318

316319
// Create container configuration, prefetching Docker images from the container registry
317320
ContainerConfiguration containerConfig = new ContainerConfiguration();
@@ -337,7 +340,7 @@ CloudPool pool = batchClient.PoolOperations.CreatePool(
337340
### Managed identity support for ACR
338341

339342
When you access containers stored in [Azure Container Registry](https://azure.microsoft.com/services/container-registry),
340-
either a username/password or a managed identity can be used to authenticate with the service. To use a managed identity,
343+
a managed identity can be used to authenticate with the service. To use a managed identity,
341344
first ensure that the identity has been [assigned to the pool](managed-identity-pools.md) and that the identity has the
342345
`AcrPull` role assigned for the container registry you wish to access. Then, instruct Batch with which identity to use
343346
when authenticating with ACR.

0 commit comments

Comments
 (0)