Skip to content

Commit b7528c7

Browse files
committed
Allow users to provide implicit managed identity to Azure Batch when pool identity is set to true
It turns out Fusion can automatically pick up a managed identity that is available, however in the first iteration we insisted users provide an explicit identity. If we avoid setting FUSION_AZ_MSI_CLIENT_ID fusion will pick up this identity and authenticate to Azure Storage automatically, with no details shared externally. I've overloaded the config item to allow users to set it to 'true', which will avoid setting FUSION_AZ_MSI_CLIENT_ID and enable Fusion to do this. This isn't a great implementation, it should probably use a dedicated config item like AzManagedIdentityOpts does for Nextflow itself, but it's a POC that allows me to test the methods. Signed-off-by: adamrtalbot <12817534+adamrtalbot@users.noreply.github.com>
1 parent 37981a5 commit b7528c7

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

docs/reference/config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ The following settings are available:
417417
`azure.batch.poolIdentityClientId`
418418
: :::{versionadded} 25.05.0-edge
419419
:::
420-
: Specify the client ID for an Azure [managed identity](https://learn.microsoft.com/en-us/entra/identity/managed-identities-azure-resources/overview) that is available on all Azure Batch node pools. This identity will be used for task-level authentication to Azure services. See {ref}`azure-managed-identities` for more details.
420+
: Specify the client ID for an Azure [managed identity](https://learn.microsoft.com/en-us/entra/identity/managed-identities-azure-resources/overview) that is available on all Azure Batch node pools. This identity will be used by Fusion to authenticate to Azure storage. If set to 'true', Fusion will use the first available managed identity.
421421

422422
`azure.managedIdentity.clientId`
423423
: Specify the client ID for an Azure [managed identity](https://learn.microsoft.com/en-us/entra/identity/managed-identities-azure-resources/overview). See {ref}`azure-managed-identities` for more details. Defaults to environment variable `AZURE_MANAGED_IDENTITY_USER`.

plugins/nf-azure/src/main/nextflow/cloud/azure/fusion/AzFusionEnv.groovy

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,13 @@ class AzFusionEnv implements FusionEnv {
6464
// If pool has a managed identity, ONLY add the MSI client ID
6565
// DO NOT add any SAS token or reference cfg.storage().sasToken
6666
if (managedIdentityId) {
67-
result.FUSION_AZ_MSI_CLIENT_ID = managedIdentityId
67+
// Fusion will try and pick up a managed identity that is available.
68+
// We recommend explicitly setting the config item to the managed ID so you know which one is being used.
69+
// However if set to 'true' it will use whichever is available.
70+
// This can be helpful if the pools have different managed identities.
71+
if (managedIdentityId != 'true') {
72+
result.FUSION_AZ_MSI_CLIENT_ID = managedIdentityId
73+
}
6874
// No SAS token is added or generated
6975
return result
7076
}

plugins/nf-azure/src/test/nextflow/cloud/azure/fusion/AzFusionEnvTest.groovy

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,26 @@ class AzFusionEnvTest extends Specification {
243243
env.size() == 2 // Only account name and managed identity
244244
}
245245

246+
def 'should not provide explicit managed identity when pool identity is set to true'() {
247+
given:
248+
def NAME = 'myaccount'
249+
Global.session = Mock(Session) {
250+
getConfig() >> [azure: [
251+
storage: [accountName: NAME],
252+
batch: [poolIdentityClientId: 'true']
253+
]]
254+
}
255+
256+
when:
257+
def config = Mock(FusionConfig)
258+
def fusionEnv = new AzFusionEnv()
259+
def env = fusionEnv.getEnvironment('az', config)
260+
261+
then:
262+
env.AZURE_STORAGE_ACCOUNT == NAME
263+
!env.FUSION_AZ_MSI_CLIENT_ID
264+
!env.AZURE_STORAGE_SAS_TOKEN // SAS token should NOT be present
265+
env.size() == 1 // Only account name
266+
}
267+
246268
}

0 commit comments

Comments
 (0)