-
Notifications
You must be signed in to change notification settings - Fork 638
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Azure Fusion env misses credentials when no key or SAS provided (#…
…5328) Signed-off-by: Paolo Di Tommaso <[email protected]>
- Loading branch information
1 parent
6e10c37
commit e11382c
Showing
3 changed files
with
140 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,47 +17,72 @@ | |
|
||
package nextflow.cloud.azure.fusion | ||
|
||
import groovy.util.logging.Slf4j | ||
import nextflow.Global | ||
import nextflow.cloud.azure.batch.AzHelper | ||
import groovy.transform.CompileStatic | ||
import nextflow.cloud.azure.config.AzConfig | ||
import nextflow.fusion.FusionConfig | ||
import nextflow.fusion.FusionEnv | ||
import org.pf4j.Extension | ||
|
||
/** | ||
* Implement environment provider for Azure specific variables | ||
* | ||
* | ||
* @author Paolo Di Tommaso <[email protected]> | ||
*/ | ||
@Extension | ||
@CompileStatic | ||
@Slf4j | ||
class AzFusionEnv implements FusionEnv { | ||
|
||
@Override | ||
Map<String, String> getEnvironment(String scheme, FusionConfig config) { | ||
if (scheme != 'az') | ||
if (scheme != 'az') { | ||
return Collections.<String, String> emptyMap() | ||
} | ||
|
||
final cfg = AzConfig.config | ||
final result = new LinkedHashMap(10) | ||
|
||
if (!cfg.storage().accountName) | ||
if (!cfg.storage().accountName) { | ||
throw new IllegalArgumentException("Missing Azure Storage account name") | ||
} | ||
|
||
if (cfg.storage().accountKey && cfg.storage().sasToken) | ||
if (cfg.storage().accountKey && cfg.storage().sasToken) { | ||
throw new IllegalArgumentException("Azure Storage Access key and SAS token detected. Only one is allowed") | ||
} | ||
|
||
// the account name is always required | ||
result.AZURE_STORAGE_ACCOUNT = cfg.storage().accountName | ||
// TODO: In theory, generating an impromptu SAS token for authentication methods other than | ||
// `azure.storage.sasToken` should not be necessary, because those methods should already allow sufficient | ||
// access for normal operation. Nevertheless, #5287 heavily implies that failing to do so causes the Azure | ||
// Storage plugin or Fusion to fail. In any case, it may be possible to remove this in the future. | ||
result.AZURE_STORAGE_SAS_TOKEN = getOrCreateSasToken() | ||
|
||
// If a Managed Identity or Service Principal is configured, Fusion only needs to know the account name | ||
if (cfg.managedIdentity().isConfigured() || cfg.activeDirectory().isConfigured()) { | ||
return result | ||
} | ||
return result | ||
} | ||
|
||
/** | ||
* Return the SAS token if it is defined in the configuration, otherwise generate one based on the requested | ||
* authentication method. | ||
*/ | ||
synchronized String getOrCreateSasToken() { | ||
|
||
final cfg = AzConfig.config | ||
|
||
// If a SAS token is configured, instead, Fusion also requires the token value | ||
// If a SAS token is already defined in the configuration, just return it | ||
if (cfg.storage().sasToken) { | ||
result.AZURE_STORAGE_SAS_TOKEN = cfg.storage().getOrCreateSasToken() | ||
return cfg.storage().sasToken | ||
} | ||
|
||
return result | ||
// For Active Directory and Managed Identity, we cannot generate an *account* SAS token, but we can generate | ||
// a *container* SAS token for the work directory. | ||
if (cfg.activeDirectory().isConfigured() || cfg.managedIdentity().isConfigured()) { | ||
return AzHelper.generateContainerSasWithActiveDirectory(Global.session.workDir, cfg.storage().tokenDuration) | ||
} | ||
|
||
// Shared Key authentication can use an account SAS token | ||
return AzHelper.generateAccountSasWithAccountKey(Global.session.workDir, cfg.storage().tokenDuration) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters