Skip to content

Commit 6ed52fb

Browse files
Make Azure auth params match between Java and Python (#630)
* Make Azure storage auth params match between Java and Python * Update auth mechanism comments for Azure storage
1 parent 30dc008 commit 6ed52fb

File tree

2 files changed

+50
-11
lines changed

2 files changed

+50
-11
lines changed

tracdap-plugins/azure-storage/src/main/java/org/finos/tracdap/plugins/azure/storage/AzureBlobStorage.java

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,22 @@
6060

6161
public class AzureBlobStorage extends CommonFileStorage {
6262

63+
// Supported authentication mechanisms are "default" and "account_key" and "sas_token"
64+
// The "default" mechanism will try environment, CLI, managed identity and workload identity
65+
6366
public static final String STORAGE_ACCOUNT_PROPERTY = "storageAccount";
6467
public static final String CONTAINER_PROPERTY = "container";
6568
public static final String PREFIX_PROPERTY = "prefix";
6669

6770
public static final String CREDENTIALS_PROPERTY = "credentials";
6871
public static final String CREDENTIALS_DEFAULT = "default";
69-
public static final String CREDENTIALS_ACCESS_KEY = "accessKey";
70-
public static final String ACCESS_KEY_PROPERTY = "accessKey";
72+
public static final String CREDENTIALS_ACCOUNT_KEY = "account_key";
73+
public static final String CREDENTIALS_ACCESS_KEY = "access_key"; // synonym for backwards compatability
74+
public static final String CREDENTIALS_SAS_TOKEN = "sas_token";
75+
76+
public static final String ACCOUNT_KEY_PROPERTY = "accountKey";
77+
public static final String ACCESS_KEY_PROPERTY = "accessKey"; // synonym for backwards compatability
78+
public static final String SAS_TOKEN_PROPERTY = "sasToken";
7179

7280
public static final String BLOB_ENDPOINT_TEMPLATE = "https://%s.blob.core.windows.net/";
7381
public static final Duration STARTUP_TIMEOUT = Duration.of(1, ChronoUnit.MINUTES);
@@ -118,16 +126,50 @@ private CredentialsProvider prepareCredentials(Properties properties) {
118126
return builder -> builder.credential(credentials);
119127
}
120128

121-
if (CREDENTIALS_ACCESS_KEY.equalsIgnoreCase(mechanism)) {
129+
if (CREDENTIALS_ACCOUNT_KEY.equalsIgnoreCase(mechanism) || CREDENTIALS_ACCESS_KEY.equalsIgnoreCase(mechanism)) {
130+
131+
if (CREDENTIALS_ACCESS_KEY.equalsIgnoreCase(mechanism)) {
132+
log.warn("Credentials mechanism [{}] is non-standard ans has been deprecated, please use [{}] instead",
133+
CREDENTIALS_ACCESS_KEY, CREDENTIALS_ACCOUNT_KEY);
134+
}
122135

123-
log.info("Using [{}] credentials mechanism", CREDENTIALS_ACCESS_KEY);
136+
log.info("Using [{}] credentials mechanism", CREDENTIALS_ACCOUNT_KEY);
124137

125-
var accessKey = properties.getProperty(ACCESS_KEY_PROPERTY);
126-
var credentials = new StorageSharedKeyCredential(storageAccount, accessKey);
138+
var accountKey = CREDENTIALS_ACCOUNT_KEY.equalsIgnoreCase(mechanism)
139+
? properties.getProperty(ACCOUNT_KEY_PROPERTY)
140+
: properties.getProperty(ACCESS_KEY_PROPERTY);
141+
142+
if (accountKey == null || accountKey.isEmpty()) {
143+
var message = String.format("Missing required config property [%s] for Azure blob storage", ACCOUNT_KEY_PROPERTY);
144+
log.error(message);
145+
throw new EStartup(message);
146+
}
147+
148+
var credentials = new StorageSharedKeyCredential(storageAccount, accountKey);
127149

128150
return builder -> builder.credential(credentials);
129151
}
130152

153+
if (CREDENTIALS_SAS_TOKEN.equalsIgnoreCase(mechanism)) {
154+
155+
log.info("Using [{}] credentials mechanism", CREDENTIALS_SAS_TOKEN);
156+
157+
var rawSasToken = properties.getProperty(SAS_TOKEN_PROPERTY);
158+
159+
if (rawSasToken == null || rawSasToken.isEmpty()) {
160+
var message = String.format("Missing required config property [%s] for Azure blob storage", SAS_TOKEN_PROPERTY);
161+
log.error(message);
162+
throw new EStartup(message);
163+
}
164+
165+
// SAS token should be a URL query param string, including the initial "?"
166+
var sasToken = rawSasToken.startsWith("?")
167+
? rawSasToken
168+
: "?" + rawSasToken;
169+
170+
return builder -> builder.sasToken(sasToken);
171+
}
172+
131173
var message = String.format("Unrecognised credentials mechanism: [%s]", mechanism);
132174
log.error(message);
133175
throw new EStartup(message);

tracdap-runtime/python/src/tracdap/rt/_plugins/storage_azure.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,8 @@ def _azure_fsspec_available():
4646

4747
class AzureBlobStorageProvider(IStorageProvider):
4848

49-
# This client depends on the Azure fsspec implementation, since there is no native implementation from Arrow
50-
# To enable it, the tracdap package must be installed with the optional [azure] feature
51-
52-
# Current supported authentication mechanisms are "default" and "access_key"
53-
# Client always uses location mode = primary, version aware = False
49+
# Supported authentication mechanisms are "default" and "account_key" and "sas_token"
50+
# The "default" mechanism will try environment, CLI, managed identity and workload identity
5451

5552
STORAGE_ACCOUNT_PROPERTY = "storageAccount"
5653
CONTAINER_PROPERTY = "container"

0 commit comments

Comments
 (0)