0
votes

Using C# I can delete Azure Batch Pools and Jobs using Client ID and Client Secret - but currently we want to delete them by using Azure Functions using Managed Identity. Here is my current code:

internal async Task<string> GetAuthenticationTokenAsync()
{
    var authContext = new AuthenticationContext(AuthorityUri);
    var authResult = await authContext.AcquireTokenAsync(BatchResourceUri, new ClientCredential(BatchCredentials["ClientId"], BatchCredentials["ClientKey"])).ConfigureAwait(false);
    return authResult.AccessToken;
}

Task<string> TokenProvider() => GetAuthenticationTokenAsync();
using (var Batch = BatchClient.Open(new BatchTokenCredentials(BatchCredentials["BatchAccountURL"], TokenProvider)))
{
    var CloudPools = Batch.PoolOperations.ListPools();
    var JobList = Batch.JobOperations.ListJobs();
    foreach (var pool in CloudPools)
    {
        pool.DeleteAsync();
    }
    foreach (var job in JobList)
    {
        job.DeleteAsync();
    }
}

I see that in msdn social that there is no support for MSI currently in Azure Batch, so is there any alternative to just delete the Azure Batch Pools and Jobs ?

note: if it is not possible in C#, I am comfortable using Rest API or PowerShell also for deleting the pools and jobs of the batch account

1
Have you referred to docs.microsoft.com/en-us/azure/batch/…? It tells me we can use service principal to manage Azure batch resources(such as pools, nodes) and Managed Identity is also a service principal.Jim Xu

1 Answers

1
votes

2021-02-17 Updated Answer:

Managed Identity on Batch pools is now in public preview in select regions. Please see this doc.

Original Answer:

Managed Identity is not supported on Azure Batch compute nodes, however, you can use Managed Identities on other Azure resources that support it to authenticate with the Azure Batch resource provider. Please see this doc.