You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by ma...@apache.org on 2018/09/23 03:24:37 UTC

[40/45] hadoop git commit: HADOOP-15719. Fail-fast when using OAuth over http. Contributed by Da Zhou.

HADOOP-15719. Fail-fast when using OAuth over http.
Contributed by Da Zhou.


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/df2166a6
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/df2166a6
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/df2166a6

Branch: refs/heads/trunk
Commit: df2166a6435b4b62011a363ea24dfcc9bc44181c
Parents: 51d3689
Author: Steve Loughran <st...@apache.org>
Authored: Tue Sep 18 12:20:52 2018 +0100
Committer: Steve Loughran <st...@apache.org>
Committed: Tue Sep 18 12:20:52 2018 +0100

----------------------------------------------------------------------
 .../hadoop/fs/azurebfs/AzureBlobFileSystem.java | 13 +++--
 .../fs/azurebfs/AzureBlobFileSystemStore.java   |  7 +++
 .../ConfigurationPropertyNotFoundException.java |  2 +-
 .../services/TestOauthFailOverHttp.java         | 55 ++++++++++++++++++++
 4 files changed, 69 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/df2166a6/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/AzureBlobFileSystem.java
----------------------------------------------------------------------
diff --git a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/AzureBlobFileSystem.java b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/AzureBlobFileSystem.java
index 2e8de78..5605e36 100644
--- a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/AzureBlobFileSystem.java
+++ b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/AzureBlobFileSystem.java
@@ -101,12 +101,11 @@ public class AzureBlobFileSystem extends FileSystem {
     this.userGroupInformation = UserGroupInformation.getCurrentUser();
     this.user = userGroupInformation.getUserName();
     this.abfsStore = new AzureBlobFileSystemStore(uri, this.isSecure(), configuration, userGroupInformation);
-
-    LOG.debug("Initializing NativeAzureFileSystem for {}", uri);
+    final AbfsConfiguration abfsConfiguration = abfsStore.getAbfsConfiguration();
 
     this.setWorkingDirectory(this.getHomeDirectory());
 
-    if (abfsStore.getAbfsConfiguration().getCreateRemoteFileSystemDuringInitialization()) {
+    if (abfsConfiguration.getCreateRemoteFileSystemDuringInitialization()) {
       if (!this.fileSystemExists()) {
         try {
           this.createFileSystem();
@@ -116,7 +115,7 @@ public class AzureBlobFileSystem extends FileSystem {
       }
     }
 
-    if (!abfsStore.getAbfsConfiguration().getSkipUserGroupMetadataDuringInitialization()) {
+    if (!abfsConfiguration.getSkipUserGroupMetadataDuringInitialization()) {
       this.primaryUserGroup = userGroupInformation.getPrimaryGroupName();
     } else {
       //Provide a default group name
@@ -124,15 +123,15 @@ public class AzureBlobFileSystem extends FileSystem {
     }
 
     if (UserGroupInformation.isSecurityEnabled()) {
-      this.delegationTokenEnabled = abfsStore.getAbfsConfiguration().isDelegationTokenManagerEnabled();
+      this.delegationTokenEnabled = abfsConfiguration.isDelegationTokenManagerEnabled();
 
       if (this.delegationTokenEnabled) {
         LOG.debug("Initializing DelegationTokenManager for {}", uri);
-        this.delegationTokenManager = abfsStore.getAbfsConfiguration().getDelegationTokenManager();
+        this.delegationTokenManager = abfsConfiguration.getDelegationTokenManager();
       }
     }
     
-    AbfsClientThrottlingIntercept.initializeSingleton(abfsStore.getAbfsConfiguration().isAutoThrottlingEnabled());
+    AbfsClientThrottlingIntercept.initializeSingleton(abfsConfiguration.isAutoThrottlingEnabled());
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/hadoop/blob/df2166a6/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/AzureBlobFileSystemStore.java
----------------------------------------------------------------------
diff --git a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/AzureBlobFileSystemStore.java b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/AzureBlobFileSystemStore.java
index d16cf36..cf7387b 100644
--- a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/AzureBlobFileSystemStore.java
+++ b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/AzureBlobFileSystemStore.java
@@ -88,6 +88,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.AZURE_ABFS_ENDPOINT;
+import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_ACCOUNT_AUTH_TYPE_PROPERTY_NAME;
 import static org.apache.hadoop.util.Time.now;
 
 /**
@@ -130,6 +131,12 @@ public class AzureBlobFileSystemStore {
     this.azureAtomicRenameDirSet = new HashSet<>(Arrays.asList(
         abfsConfiguration.getAzureAtomicRenameDirs().split(AbfsHttpConstants.COMMA)));
 
+    if (AuthType.OAuth == abfsConfiguration.getEnum(FS_AZURE_ACCOUNT_AUTH_TYPE_PROPERTY_NAME, AuthType.SharedKey)
+            && !FileSystemUriSchemes.ABFS_SECURE_SCHEME.equals(uri.getScheme())) {
+      throw new IllegalArgumentException(
+              String.format("Incorrect URI %s, URI scheme must be abfss when authenticating using Oauth.", uri));
+    }
+
     initializeClient(uri, fileSystemName, accountName, isSecure);
   }
 

http://git-wip-us.apache.org/repos/asf/hadoop/blob/df2166a6/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/contracts/exceptions/ConfigurationPropertyNotFoundException.java
----------------------------------------------------------------------
diff --git a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/contracts/exceptions/ConfigurationPropertyNotFoundException.java b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/contracts/exceptions/ConfigurationPropertyNotFoundException.java
index bf3b2f3..43a71ab 100644
--- a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/contracts/exceptions/ConfigurationPropertyNotFoundException.java
+++ b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/contracts/exceptions/ConfigurationPropertyNotFoundException.java
@@ -27,6 +27,6 @@ import org.apache.hadoop.classification.InterfaceStability;
 @InterfaceStability.Evolving
 public class ConfigurationPropertyNotFoundException extends AzureBlobFileSystemException {
   public ConfigurationPropertyNotFoundException(String property) {
-    super("Configuration property " + property + "not found.");
+    super("Configuration property " + property + " not found.");
   }
 }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/df2166a6/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestOauthFailOverHttp.java
----------------------------------------------------------------------
diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestOauthFailOverHttp.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestOauthFailOverHttp.java
new file mode 100644
index 0000000..de07c4b
--- /dev/null
+++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestOauthFailOverHttp.java
@@ -0,0 +1,55 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.fs.azurebfs.services;
+
+import java.net.URI;
+
+import org.junit.Test;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.azurebfs.constants.FileSystemUriSchemes;
+
+import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_ACCOUNT_AUTH_TYPE_PROPERTY_NAME;
+import static org.apache.hadoop.fs.azurebfs.constants.TestConfigurationKeys.FS_AZURE_ABFS_ACCOUNT_NAME;
+import static org.apache.hadoop.test.LambdaTestUtils.intercept;
+
+/**
+ * Test Oauth fail fast when uri scheme is incorrect.
+ */
+public class TestOauthFailOverHttp {
+
+  @Test
+  public void testOauthFailWithSchemeAbfs() throws Exception {
+    Configuration conf = new Configuration();
+    final String account = "fakeaccount.dfs.core.windows.net";
+    conf.set(FS_AZURE_ABFS_ACCOUNT_NAME, account);
+    conf.setEnum(FS_AZURE_ACCOUNT_AUTH_TYPE_PROPERTY_NAME, AuthType.OAuth);
+    URI defaultUri = new URI(FileSystemUriSchemes.ABFS_SCHEME,
+            "fakecontainer@" + account,
+            null,
+            null,
+            null);
+    conf.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, defaultUri.toString());
+    // IllegalArgumentException is expected
+    // when authenticating using Oauth and scheme is not abfss
+    intercept(IllegalArgumentException.class, "Incorrect URI",
+        () -> FileSystem.get(conf));
+  }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org