Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d186091
fail fs init if cpk config on non hns account
saxenapranav Apr 19, 2024
2d3a5dd
check condition after checking fileSystem exist
saxenapranav Apr 19, 2024
f712d0d
ITestAbfsCustomEncryption can still work with non hns config, proper …
saxenapranav Apr 19, 2024
fa6be2b
unused import removal
saxenapranav Apr 19, 2024
794685c
test fixes
saxenapranav Apr 19, 2024
1536675
Revert "test fixes"
saxenapranav Apr 19, 2024
d3cb3a1
revert of namespace checking
saxenapranav Apr 19, 2024
9290858
deleted NamespaceUtil as the other usage is removed; checkstyle
saxenapranav Apr 19, 2024
60853e0
small refactor
saxenapranav Apr 19, 2024
54b9698
exception message as a constant; test refactor
saxenapranav Apr 22, 2024
5d09597
Merge branch 'trunk' into saxenapranav/failFsInitOnCpkNonHns
saxenapranav Apr 23, 2024
255b62d
Merge branch 'trunk' into saxenapranav/failFsInitOnCpkNonHns
saxenapranav May 6, 2024
d4cdd7e
Merge branch 'trunk' into saxenapranav/failFsInitOnCpkNonHns
saxenapranav May 10, 2024
3c8b712
Merge branch 'trunk' into saxenapranav/failFsInitOnCpkNonHns
saxenapranav May 13, 2024
c7e4358
review comment: message_const; test for no getAcl call if hns config …
saxenapranav May 13, 2024
c0dc108
Merge branch 'trunk' into saxenapranav/failFsInitOnCpkNonHns
saxenapranav May 28, 2024
39e8c5d
review comments
saxenapranav May 28, 2024
18eed9e
review commments
saxenapranav May 31, 2024
cd1d52f
test fix
saxenapranav May 31, 2024
5c9a103
javadocs param missing
saxenapranav May 31, 2024
0e2bceb
CPK full form correction
saxenapranav Jun 10, 2024
5309829
string correction
saxenapranav Jun 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

import javax.annotation.Nullable;

import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.classification.VisibleForTesting;
import org.apache.hadoop.fs.impl.BackReference;
import org.apache.hadoop.security.ProviderUtils;
Expand Down Expand Up @@ -115,6 +116,7 @@
import static org.apache.hadoop.fs.CommonConfigurationKeys.IOSTATISTICS_LOGGING_LEVEL_DEFAULT;
import static org.apache.hadoop.fs.Options.OpenFileOptions.FS_OPTION_OPENFILE_STANDARD_OPTIONS;
import static org.apache.hadoop.fs.azurebfs.AbfsStatistic.*;
import static org.apache.hadoop.fs.azurebfs.constants.AbfsHttpConstants.FS_INIT_FAILED_CPK_CONFIG_IN_NON_HNS_ACCOUNT;
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.DATA_BLOCKS_BUFFER;
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_BLOCK_UPLOAD_ACTIVE_BLOCKS;
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_BLOCK_UPLOAD_BUFFER_DIR;
Expand Down Expand Up @@ -223,6 +225,21 @@ public void initialize(URI uri, Configuration configuration)
}
}

if ((abfsConfiguration.createEncryptionContextProvider() != null
|| StringUtils.isNotEmpty(
abfsConfiguration.getEncodedClientProvidedEncryptionKey()))
&& !getIsNamespaceEnabled(
new TracingContext(clientCorrelationId, fileSystemId,
FSOperationType.CREATE_FILESYSTEM, tracingHeaderFormat, listener))) {
/*
* Close the filesystem gracefully before throwing exception. Graceful close
* will ensure that all resources are released properly.
*/
close();
throw new PathIOException(uri.getPath(),
FS_INIT_FAILED_CPK_CONFIG_IN_NON_HNS_ACCOUNT);
}

LOG.trace("Initiate check for delegation token manager");
if (UserGroupInformation.isSecurityEnabled()) {
this.delegationTokenEnabled = abfsConfiguration.isDelegationTokenManagerEnabled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
import org.apache.hadoop.fs.azurebfs.security.ContextEncryptionAdapter;
import org.apache.hadoop.fs.azurebfs.security.NoContextEncryptionAdapter;
import org.apache.hadoop.fs.azurebfs.utils.EncryptionType;
import org.apache.hadoop.fs.azurebfs.utils.NamespaceUtil;
import org.apache.hadoop.fs.impl.BackReference;
import org.apache.hadoop.fs.PathIOException;

Expand Down Expand Up @@ -373,7 +372,21 @@ public boolean getIsNamespaceEnabled(TracingContext tracingContext)
+ " getAcl server call", e);
}

isNamespaceEnabled = Trilean.getTrilean(NamespaceUtil.isNamespaceEnabled(client, tracingContext));
try {
LOG.debug("Get root ACL status");
client.getAclStatus(AbfsHttpConstants.ROOT_PATH, tracingContext);
isNamespaceEnabled = Trilean.getTrilean(true);
} catch (AbfsRestOperationException ex) {
// Get ACL status is a HEAD request, its response doesn't contain
// errorCode
// So can only rely on its status code to determine its account type.
if (HttpURLConnection.HTTP_BAD_REQUEST != ex.getStatusCode()) {
throw ex;
}
isNamespaceEnabled = Trilean.getTrilean(false);
} catch (AzureBlobFileSystemException ex) {
throw ex;
}
return isNamespaceEnabled.toBoolean();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,8 @@ public static ApiVersion getCurrentVersion() {
*/
public static final Integer HTTP_STATUS_CATEGORY_QUOTIENT = 100;

public static final String FS_INIT_FAILED_CPK_CONFIG_IN_NON_HNS_ACCOUNT =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This is an error message right??
Should it be named to reflect that??
CPK_IN_NON_HNS_ACCOUNT_ERROR_MESSAGE

Just a thought

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

taken.

"Non HNS account can not have CPK configs enabled.";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. please use Client Provided Keys, maybe Non Hierarchical Storage too. We cannot assume users know these acronyms.
  2. please add a javadoc with an {@value} clause for IDE assistance

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense. Taken.


private AbfsHttpConstants() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.apache.hadoop.fs.azurebfs.contracts.exceptions.AbfsInvalidChecksumException;
import org.apache.hadoop.fs.azurebfs.contracts.exceptions.AbfsDriverException;
import org.apache.hadoop.fs.azurebfs.contracts.services.AzureServiceErrorCode;
import org.apache.hadoop.fs.azurebfs.utils.NamespaceUtil;
import org.apache.hadoop.fs.store.LogExactlyOnce;
import org.apache.hadoop.fs.azurebfs.AzureBlobFileSystemStore.Permissions;
import org.apache.hadoop.fs.azurebfs.extensions.EncryptionContextProvider;
Expand Down Expand Up @@ -120,7 +119,6 @@ public class AbfsClient implements Closeable {
private final AbfsThrottlingIntercept intercept;

private final ListeningScheduledExecutorService executorService;
private Boolean isNamespaceEnabled;

private boolean renameResilience;

Expand Down Expand Up @@ -305,9 +303,6 @@ private void addEncryptionKeyRequestHeaders(String path,
List<AbfsHttpHeader> requestHeaders, boolean isCreateFileRequest,
ContextEncryptionAdapter contextEncryptionAdapter, TracingContext tracingContext)
throws AzureBlobFileSystemException {
if (!getIsNamespaceEnabled(tracingContext)) {
return;
}
String encodedKey, encodedKeySHA256;
switch (encryptionType) {
case GLOBAL_KEY:
Expand Down Expand Up @@ -1486,15 +1481,6 @@ public synchronized String getAccessToken() throws IOException {
}
}

private synchronized Boolean getIsNamespaceEnabled(TracingContext tracingContext)
throws AzureBlobFileSystemException {
if (isNamespaceEnabled == null) {
setIsNamespaceEnabled(NamespaceUtil.isNamespaceEnabled(this,
tracingContext));
}
return isNamespaceEnabled;
}

protected Boolean getIsPaginatedDeleteEnabled() {
return abfsConfiguration.isPaginatedDeleteEnabled();
}
Expand Down Expand Up @@ -1684,11 +1670,6 @@ void setEncryptionContextProvider(EncryptionContextProvider provider) {
encryptionContextProvider = provider;
}

@VisibleForTesting
void setIsNamespaceEnabled(final Boolean isNamespaceEnabled) {
this.isNamespaceEnabled = isNamespaceEnabled;
}

/**
* Getter for abfsCounters from AbfsClient.
* @return AbfsCounters instance.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.apache.hadoop.fs.azurebfs.oauth2.AccessTokenProvider;
import org.apache.hadoop.fs.azurebfs.security.AbfsDelegationTokenManager;
import org.apache.hadoop.fs.azurebfs.services.AbfsClient;
import org.apache.hadoop.fs.azurebfs.services.AbfsClientUtils;
import org.apache.hadoop.fs.azurebfs.services.AbfsOutputStream;
import org.apache.hadoop.fs.azurebfs.services.AuthType;
import org.apache.hadoop.fs.azurebfs.services.ITestAbfsClient;
Expand Down Expand Up @@ -209,8 +208,6 @@ public void setup() throws Exception {
wasb = new NativeAzureFileSystem(azureNativeFileSystemStore);
wasb.initialize(wasbUri, rawConfig);
}
// Todo: To be fixed in HADOOP-19137
AbfsClientUtils.setIsNamespaceEnabled(abfs.getAbfsClient(), true);
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import org.apache.hadoop.fs.azurebfs.services.AbfsClientUtils;
import org.apache.hadoop.fs.azurebfs.utils.TracingContext;
import org.assertj.core.api.Assertions;
import org.junit.Assume;
import org.assertj.core.api.Assumptions;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
Expand All @@ -60,6 +60,7 @@
import org.apache.hadoop.test.LambdaTestUtils;
import org.apache.hadoop.util.Lists;

import static org.apache.hadoop.fs.azurebfs.constants.AbfsHttpConstants.FS_INIT_FAILED_CPK_CONFIG_IN_NON_HNS_ACCOUNT;
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_ENCRYPTION_CONTEXT_PROVIDER_TYPE;
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_ENCRYPTION_ENCODED_CLIENT_PROVIDED_KEY;
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_ENCRYPTION_ENCODED_CLIENT_PROVIDED_KEY_SHA;
Expand Down Expand Up @@ -171,9 +172,6 @@ public static Iterable<Object[]> params() {
}

public ITestAbfsCustomEncryption() throws Exception {
Assume.assumeTrue("Account should be HNS enabled for CPK",
getConfiguration().getBoolean(FS_AZURE_TEST_NAMESPACE_ENABLED_ACCOUNT,
false));
new Random().nextBytes(cpk);
cpkSHAEncoded = EncodingHelper.getBase64EncodedString(
EncodingHelper.getSHA256Hash(cpk));
Expand All @@ -184,8 +182,8 @@ public void testCustomEncryptionCombinations() throws Exception {
AzureBlobFileSystem fs = getOrCreateFS();
Path testPath = path("/testFile");
String relativePath = fs.getAbfsStore().getRelativePath(testPath);
MockEncryptionContextProvider ecp =
(MockEncryptionContextProvider) createEncryptedFile(testPath);
MockEncryptionContextProvider ecp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taken.

= (MockEncryptionContextProvider) createEncryptedFile(testPath);
AbfsRestOperation op = callOperation(fs, new Path(relativePath), ecp);
if (op == null) {
return;
Expand Down Expand Up @@ -375,9 +373,7 @@ private AzureBlobFileSystem getECProviderEnabledFS() throws Exception {
+ getAccountName());
configuration.unset(FS_AZURE_ENCRYPTION_ENCODED_CLIENT_PROVIDED_KEY_SHA + "."
+ getAccountName());
AzureBlobFileSystem fs = (AzureBlobFileSystem) FileSystem.newInstance(configuration);
fileSystemsOpenedInTest.add(fs);
return fs;
return getAzureBlobFileSystem(configuration);
}

private AzureBlobFileSystem getCPKEnabledFS() throws IOException {
Expand All @@ -390,9 +386,34 @@ private AzureBlobFileSystem getCPKEnabledFS() throws IOException {
conf.set(FS_AZURE_ENCRYPTION_ENCODED_CLIENT_PROVIDED_KEY_SHA + "."
+ getAccountName(), cpkEncodedSHA);
conf.unset(FS_AZURE_ENCRYPTION_CONTEXT_PROVIDER_TYPE);
AzureBlobFileSystem fs = (AzureBlobFileSystem) FileSystem.newInstance(conf);
fileSystemsOpenedInTest.add(fs);
return fs;
return getAzureBlobFileSystem(conf);
}

private AzureBlobFileSystem getAzureBlobFileSystem(final Configuration conf) {
try {
AzureBlobFileSystem fs = (AzureBlobFileSystem) FileSystem.newInstance(
conf);
fileSystemsOpenedInTest.add(fs);
Assertions.assertThat(
getConfiguration().getBoolean(FS_AZURE_TEST_NAMESPACE_ENABLED_ACCOUNT,
false))
.describedAs("Encryption tests should run only on namespace enabled account")
.isTrue();
return fs;
} catch (IOException ex) {
Assertions.assertThat(ex.getMessage())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use GenericTestUtils.assertExceptionContains

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats nice suggestion! Taken.

.describedAs("Exception message should contain the expected message")
.contains(FS_INIT_FAILED_CPK_CONFIG_IN_NON_HNS_ACCOUNT);
Assertions.assertThat(
getConfiguration().getBoolean(FS_AZURE_TEST_NAMESPACE_ENABLED_ACCOUNT,
false))
.describedAs("Encryption tests should run only on namespace enabled account")
.isFalse();

//Skip the test
Assumptions.assumeThat(true).isFalse();
return null;
}
}

private AzureBlobFileSystem getOrCreateFS() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.azurebfs.constants.AbfsHttpConstants;
import org.apache.hadoop.fs.azurebfs.security.ContextEncryptionAdapter;
import org.apache.hadoop.fs.azurebfs.services.AbfsClientUtils;
import org.apache.hadoop.fs.permission.FsAction;
import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.hadoop.test.GenericTestUtils;
Expand Down Expand Up @@ -281,7 +280,6 @@ public void testCreateFileOverwrite(boolean enableConditionalCreateOverwrite)
final AzureBlobFileSystem fs =
(AzureBlobFileSystem) FileSystem.newInstance(currentFs.getUri(),
config);
AbfsClientUtils.setIsNamespaceEnabled(fs.getAbfsClient(), true);

long totalConnectionMadeBeforeTest = fs.getInstrumentationMap()
.get(CONNECTIONS_MADE.getStatName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ public final class AbfsClientUtils {
private AbfsClientUtils() {

}
public static void setIsNamespaceEnabled(final AbfsClient abfsClient, final Boolean isNamespaceEnabled) {
abfsClient.setIsNamespaceEnabled(isNamespaceEnabled);
}

public static void setEncryptionContextProvider(final AbfsClient abfsClient, final EncryptionContextProvider provider) {
abfsClient.setEncryptionContextProvider(provider);
Expand Down