Skip to content

Commit c57f932

Browse files
authored
HADOOP-17912. ABFS: Support for Encryption Context (#6221)
Contributed by Pranav Saxena and others.
1 parent 4c08ca2 commit c57f932

33 files changed

Lines changed: 1808 additions & 1227 deletions

hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/AbfsConfiguration.java

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import org.apache.hadoop.fs.azurebfs.diagnostics.StringConfigurationBasicValidator;
5050
import org.apache.hadoop.fs.azurebfs.enums.Trilean;
5151
import org.apache.hadoop.fs.azurebfs.extensions.CustomTokenProviderAdaptee;
52+
import org.apache.hadoop.fs.azurebfs.extensions.EncryptionContextProvider;
5253
import org.apache.hadoop.fs.azurebfs.extensions.SASTokenProvider;
5354
import org.apache.hadoop.fs.azurebfs.oauth2.AccessTokenProvider;
5455
import org.apache.hadoop.fs.azurebfs.oauth2.ClientCredsTokenProvider;
@@ -337,6 +338,10 @@ public class AbfsConfiguration{
337338
FS_AZURE_ABFS_RENAME_RESILIENCE, DefaultValue = DEFAULT_ENABLE_ABFS_RENAME_RESILIENCE)
338339
private boolean renameResilience;
339340

341+
private String clientProvidedEncryptionKey;
342+
343+
private String clientProvidedEncryptionKeySHA;
344+
340345
public AbfsConfiguration(final Configuration rawConfig, String accountName)
341346
throws IllegalAccessException, InvalidConfigurationValueException, IOException {
342347
this.rawConfig = ProviderUtils.excludeIncompatibleCredentialProviders(
@@ -957,6 +962,32 @@ public SASTokenProvider getSASTokenProvider() throws AzureBlobFileSystemExceptio
957962
}
958963
}
959964

965+
public EncryptionContextProvider createEncryptionContextProvider() {
966+
try {
967+
String configKey = FS_AZURE_ENCRYPTION_CONTEXT_PROVIDER_TYPE;
968+
if (get(configKey) == null) {
969+
return null;
970+
}
971+
Class<? extends EncryptionContextProvider> encryptionContextClass =
972+
getAccountSpecificClass(configKey, null,
973+
EncryptionContextProvider.class);
974+
Preconditions.checkArgument(encryptionContextClass != null, String.format(
975+
"The configuration value for %s is invalid, or config key is not account-specific",
976+
configKey));
977+
978+
EncryptionContextProvider encryptionContextProvider =
979+
ReflectionUtils.newInstance(encryptionContextClass, rawConfig);
980+
Preconditions.checkArgument(encryptionContextProvider != null,
981+
String.format("Failed to initialize %s", encryptionContextClass));
982+
983+
LOG.trace("{} init complete", encryptionContextClass.getName());
984+
return encryptionContextProvider;
985+
} catch (Exception e) {
986+
throw new IllegalArgumentException(
987+
"Unable to load encryption context provider class: ", e);
988+
}
989+
}
990+
960991
public boolean isReadAheadEnabled() {
961992
return this.enabledReadAhead;
962993
}
@@ -1068,9 +1099,22 @@ public boolean enableAbfsListIterator() {
10681099
return this.enableAbfsListIterator;
10691100
}
10701101

1071-
public String getClientProvidedEncryptionKey() {
1072-
String accSpecEncKey = accountConf(FS_AZURE_CLIENT_PROVIDED_ENCRYPTION_KEY);
1073-
return rawConfig.get(accSpecEncKey, null);
1102+
public String getEncodedClientProvidedEncryptionKey() {
1103+
if (clientProvidedEncryptionKey == null) {
1104+
String accSpecEncKey = accountConf(
1105+
FS_AZURE_ENCRYPTION_ENCODED_CLIENT_PROVIDED_KEY);
1106+
clientProvidedEncryptionKey = rawConfig.get(accSpecEncKey, null);
1107+
}
1108+
return clientProvidedEncryptionKey;
1109+
}
1110+
1111+
public String getEncodedClientProvidedEncryptionKeySHA() {
1112+
if (clientProvidedEncryptionKeySHA == null) {
1113+
String accSpecEncKey = accountConf(
1114+
FS_AZURE_ENCRYPTION_ENCODED_CLIENT_PROVIDED_KEY_SHA);
1115+
clientProvidedEncryptionKeySHA = rawConfig.get(accSpecEncKey, null);
1116+
}
1117+
return clientProvidedEncryptionKeySHA;
10741118
}
10751119

10761120
@VisibleForTesting

0 commit comments

Comments
 (0)