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 el...@apache.org on 2011/04/22 18:19:47 UTC

svn commit: r1095958 - in /hadoop/common/trunk: CHANGES.txt src/java/org/apache/hadoop/io/SecureIOUtils.java src/test/core/org/apache/hadoop/io/TestSecureIOUtils.java

Author: eli
Date: Fri Apr 22 16:19:46 2011
New Revision: 1095958

URL: http://svn.apache.org/viewvc?rev=1095958&view=rev
Log:
HADOOP-7172. SecureIO should not check owner on non-secure clusters that have no native support. Contributed by Todd Lipcon

Modified:
    hadoop/common/trunk/CHANGES.txt
    hadoop/common/trunk/src/java/org/apache/hadoop/io/SecureIOUtils.java
    hadoop/common/trunk/src/test/core/org/apache/hadoop/io/TestSecureIOUtils.java

Modified: hadoop/common/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/CHANGES.txt?rev=1095958&r1=1095957&r2=1095958&view=diff
==============================================================================
--- hadoop/common/trunk/CHANGES.txt (original)
+++ hadoop/common/trunk/CHANGES.txt Fri Apr 22 16:19:46 2011
@@ -596,6 +596,9 @@ Release 0.22.0 - Unreleased
     HADOOP-7229. Do not default to an absolute path for kinit in Kerberos
     auto-renewal thread. (Aaron T. Myers via todd)
 
+    HADOOP-7172. SecureIO should not check owner on non-secure
+    clusters that have no native support. (todd via eli)
+
 Release 0.21.1 - Unreleased
 
   IMPROVEMENTS

Modified: hadoop/common/trunk/src/java/org/apache/hadoop/io/SecureIOUtils.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/io/SecureIOUtils.java?rev=1095958&r1=1095957&r2=1095958&view=diff
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/io/SecureIOUtils.java (original)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/io/SecureIOUtils.java Fri Apr 22 16:19:46 2011
@@ -91,23 +91,32 @@ public class SecureIOUtils {
 
   /**
    * Open the given File for read access, verifying the expected user/group
-   * constraints.
+   * constraints if security is enabled.
+   *
+   * Note that this function provides no additional checks if Hadoop
+   * security is disabled, since doing the checks would be too expensive
+   * when native libraries are not available.
+   *
    * @param f the file that we are trying to open
    * @param expectedOwner the expected user owner for the file
    * @param expectedGroup the expected group owner for the file
-   * @throws IOException if an IO Error occurred, or the user/group does not 
-   * match
+   * @throws IOException if an IO Error occurred, or security is enabled and
+   * the user/group does not match
    */
   public static FileInputStream openForRead(File f, String expectedOwner, 
       String expectedGroup) throws IOException {
-    if (skipSecurity) {
-      // Subject to race conditions but this is the best we can do
-      FileStatus status =
-        rawFilesystem.getFileStatus(new Path(f.getAbsolutePath()));
-      checkStat(f, status.getOwner(), status.getGroup(),
-          expectedOwner, expectedGroup);
+    if (!UserGroupInformation.isSecurityEnabled()) {
       return new FileInputStream(f);
     }
+    return forceSecureOpenForRead(f, expectedOwner, expectedGroup);
+  }
+
+  /**
+   * Same as openForRead() except that it will run even if security is off.
+   * This is used by unit tests.
+   */
+  static FileInputStream forceSecureOpenForRead(File f, String expectedOwner,
+      String expectedGroup) throws IOException {
 
     FileInputStream fis = new FileInputStream(f);
     boolean success = false;

Modified: hadoop/common/trunk/src/test/core/org/apache/hadoop/io/TestSecureIOUtils.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/io/TestSecureIOUtils.java?rev=1095958&r1=1095957&r2=1095958&view=diff
==============================================================================
--- hadoop/common/trunk/src/test/core/org/apache/hadoop/io/TestSecureIOUtils.java (original)
+++ hadoop/common/trunk/src/test/core/org/apache/hadoop/io/TestSecureIOUtils.java Fri Apr 22 16:19:46 2011
@@ -64,11 +64,20 @@ public class TestSecureIOUtils {
       .openForRead(testFilePath, realOwner, realGroup).close();
   }
 
-  @Test(expected=IOException.class)
+  @Test
   public void testReadIncorrectlyRestrictedWithSecurity() throws IOException {
-    SecureIOUtils
-      .openForRead(testFilePath, "invalidUser", null).close();
-    fail("Didn't throw expection for wrong ownership!");
+    // this will only run if libs are available
+    assumeTrue(NativeIO.isAvailable());
+
+    System.out.println("Running test with native libs...");
+
+    try {
+      SecureIOUtils
+        .forceSecureOpenForRead(testFilePath, "invalidUser", null).close();
+      fail("Didn't throw expection for wrong ownership!");
+    } catch (IOException ioe) {
+      // expected
+    }
   }
 
   @Test