aboutsummaryrefslogtreecommitdiff
path: root/core/src/test/scala/org/apache/spark/deploy/SparkHadoopUtilSuite.scala
diff options
context:
space:
mode:
authorjerryshao <sshao@hortonworks.com>2017-04-20 16:02:09 -0700
committerMarcelo Vanzin <vanzin@cloudera.com>2017-04-20 16:02:09 -0700
commit592f5c89349f3c5b6ec0531c6514b8f7d95ad8da (patch)
tree11a60e8bf35212ff0980dbe288fb687b71c6bbfd /core/src/test/scala/org/apache/spark/deploy/SparkHadoopUtilSuite.scala
parent033206355339677812a250b2b64818a261871fd2 (diff)
downloadspark-592f5c89349f3c5b6ec0531c6514b8f7d95ad8da.tar.gz
spark-592f5c89349f3c5b6ec0531c6514b8f7d95ad8da.tar.bz2
spark-592f5c89349f3c5b6ec0531c6514b8f7d95ad8da.zip
[SPARK-20172][CORE] Add file permission check when listing files in FsHistoryProvider
## What changes were proposed in this pull request? In the current Spark's HistoryServer we expected to get `AccessControlException` during listing all the files, but unfortunately it was not worked because we actually doesn't check the access permission and no other calls will throw such exception. What was worse is that this check will be deferred until reading files, which is not necessary and quite verbose, since it will be printed out the exception in every 10 seconds when checking the files. So here with this fix, we actually check the read permission during listing the files, which could avoid unnecessary file read later on and suppress the verbose log. ## How was this patch tested? Add unit test to verify. Author: jerryshao <sshao@hortonworks.com> Closes #17495 from jerryshao/SPARK-20172.
Diffstat (limited to 'core/src/test/scala/org/apache/spark/deploy/SparkHadoopUtilSuite.scala')
-rw-r--r--core/src/test/scala/org/apache/spark/deploy/SparkHadoopUtilSuite.scala97
1 files changed, 97 insertions, 0 deletions
diff --git a/core/src/test/scala/org/apache/spark/deploy/SparkHadoopUtilSuite.scala b/core/src/test/scala/org/apache/spark/deploy/SparkHadoopUtilSuite.scala
new file mode 100644
index 0000000000..ab24a76e20
--- /dev/null
+++ b/core/src/test/scala/org/apache/spark/deploy/SparkHadoopUtilSuite.scala
@@ -0,0 +1,97 @@
+/*
+ * 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.spark.deploy
+
+import java.security.PrivilegedExceptionAction
+
+import scala.util.Random
+
+import org.apache.hadoop.fs.FileStatus
+import org.apache.hadoop.fs.permission.{FsAction, FsPermission}
+import org.apache.hadoop.security.UserGroupInformation
+import org.scalatest.Matchers
+
+import org.apache.spark.SparkFunSuite
+
+class SparkHadoopUtilSuite extends SparkFunSuite with Matchers {
+ test("check file permission") {
+ import FsAction._
+ val testUser = s"user-${Random.nextInt(100)}"
+ val testGroups = Array(s"group-${Random.nextInt(100)}")
+ val testUgi = UserGroupInformation.createUserForTesting(testUser, testGroups)
+
+ testUgi.doAs(new PrivilegedExceptionAction[Void] {
+ override def run(): Void = {
+ val sparkHadoopUtil = new SparkHadoopUtil
+
+ // If file is owned by user and user has access permission
+ var status = fileStatus(testUser, testGroups.head, READ_WRITE, READ_WRITE, NONE)
+ sparkHadoopUtil.checkAccessPermission(status, READ) should be(true)
+ sparkHadoopUtil.checkAccessPermission(status, WRITE) should be(true)
+
+ // If file is owned by user but user has no access permission
+ status = fileStatus(testUser, testGroups.head, NONE, READ_WRITE, NONE)
+ sparkHadoopUtil.checkAccessPermission(status, READ) should be(false)
+ sparkHadoopUtil.checkAccessPermission(status, WRITE) should be(false)
+
+ val otherUser = s"test-${Random.nextInt(100)}"
+ val otherGroup = s"test-${Random.nextInt(100)}"
+
+ // If file is owned by user's group and user's group has access permission
+ status = fileStatus(otherUser, testGroups.head, NONE, READ_WRITE, NONE)
+ sparkHadoopUtil.checkAccessPermission(status, READ) should be(true)
+ sparkHadoopUtil.checkAccessPermission(status, WRITE) should be(true)
+
+ // If file is owned by user's group but user's group has no access permission
+ status = fileStatus(otherUser, testGroups.head, READ_WRITE, NONE, NONE)
+ sparkHadoopUtil.checkAccessPermission(status, READ) should be(false)
+ sparkHadoopUtil.checkAccessPermission(status, WRITE) should be(false)
+
+ // If file is owned by other user and this user has access permission
+ status = fileStatus(otherUser, otherGroup, READ_WRITE, READ_WRITE, READ_WRITE)
+ sparkHadoopUtil.checkAccessPermission(status, READ) should be(true)
+ sparkHadoopUtil.checkAccessPermission(status, WRITE) should be(true)
+
+ // If file is owned by other user but this user has no access permission
+ status = fileStatus(otherUser, otherGroup, READ_WRITE, READ_WRITE, NONE)
+ sparkHadoopUtil.checkAccessPermission(status, READ) should be(false)
+ sparkHadoopUtil.checkAccessPermission(status, WRITE) should be(false)
+
+ null
+ }
+ })
+ }
+
+ private def fileStatus(
+ owner: String,
+ group: String,
+ userAction: FsAction,
+ groupAction: FsAction,
+ otherAction: FsAction): FileStatus = {
+ new FileStatus(0L,
+ false,
+ 0,
+ 0L,
+ 0L,
+ 0L,
+ new FsPermission(userAction, groupAction, otherAction),
+ owner,
+ group,
+ null)
+ }
+}