|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.spark.sql.hive.thriftserver |
| 19 | + |
| 20 | +import org.apache.hadoop.hive.conf.HiveConf |
| 21 | +import org.apache.hadoop.hive.conf.HiveConf.ConfVars |
| 22 | +import org.apache.hive.service.auth.HiveAuthFactory.AuthTypes |
| 23 | + |
| 24 | +import org.apache.spark.SparkFunSuite |
| 25 | +import org.apache.spark.sql.internal.StaticSQLConf |
| 26 | + |
| 27 | +/** |
| 28 | + * Tests for the SPARK-59118 startup warning: `hive.server2.enable.doAs` is accepted but |
| 29 | + * impersonation does not reach executor-side data access. Spark 5.0 is expected to refuse |
| 30 | + * to start instead, on the same configuration and with the same opt-out conf. |
| 31 | + */ |
| 32 | +class HiveThriftServer2DoAsSuite extends SparkFunSuite { |
| 33 | + |
| 34 | + private def hiveConf(authType: String, doAs: Boolean): HiveConf = { |
| 35 | + val conf = new HiveConf() |
| 36 | + conf.setVar(ConfVars.HIVE_SERVER2_AUTHENTICATION, authType) |
| 37 | + conf.setBoolVar(ConfVars.HIVE_SERVER2_ENABLE_DOAS, doAs) |
| 38 | + conf |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * The warning text (if any) that checking `conf` would log. These tests assert on the |
| 43 | + * returned entry rather than captured log output, which is hostage to JVM-global logging |
| 44 | + * state when the whole module shares one forked JVM (SERIAL_SBT_TESTS=1 in CI). |
| 45 | + */ |
| 46 | + private def doAsWarnings(conf: HiveConf, allowIneffectiveDoAs: Boolean = false): Seq[String] = { |
| 47 | + HiveThriftServer2.ineffectiveDoAsWarning(conf, allowIneffectiveDoAs).map(_.message).toSeq |
| 48 | + } |
| 49 | + |
| 50 | + // The auth types that establish a user identity worth impersonating. |
| 51 | + private val verifyingAuthTypes = |
| 52 | + AuthTypes.values().filterNot(Set(AuthTypes.NONE, AuthTypes.NOSASL)).map(_.getAuthName) |
| 53 | + |
| 54 | + test("SPARK-5159 / SPARK-59118 warn when doAs is enabled but not enforced") { |
| 55 | + val warnings = doAsWarnings(hiveConf("KERBEROS", doAs = true)) |
| 56 | + assert(warnings.length == 1) |
| 57 | + assert(warnings.head.contains("SPARK-5159")) |
| 58 | + // Auth type matching is case-insensitive. |
| 59 | + assert(doAsWarnings(hiveConf("kerberos", doAs = true)).length == 1) |
| 60 | + } |
| 61 | + |
| 62 | + test("SPARK-59118 allowIneffectiveDoAs=true silences an otherwise-warned config") { |
| 63 | + assert(doAsWarnings(hiveConf("KERBEROS", doAs = true), allowIneffectiveDoAs = true).isEmpty) |
| 64 | + } |
| 65 | + |
| 66 | + test("SPARK-59118 the warning names the conf that silences it") { |
| 67 | + val warning = doAsWarnings(hiveConf("KERBEROS", doAs = true)).head |
| 68 | + assert(warning.contains(StaticSQLConf.HIVE_THRIFT_SERVER_ALLOW_INEFFECTIVE_DOAS.key)) |
| 69 | + } |
| 70 | + |
| 71 | + test("SPARK-59118 warn for every auth type that verifies the user") { |
| 72 | + // Guards against a new AuthTypes value silently landing on the quiet side. |
| 73 | + assert(verifyingAuthTypes.nonEmpty) |
| 74 | + verifyingAuthTypes.foreach { authType => |
| 75 | + assert(doAsWarnings(hiveConf(authType, doAs = true)).length == 1, s"no warning: $authType") |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + test("SPARK-59118 does not warn when auth type establishes no user identity") { |
| 80 | + Seq("NONE", "NOSASL", "none", "noSasl").foreach { authType => |
| 81 | + assert(doAsWarnings(hiveConf(authType, doAs = true)).isEmpty, s"warned: $authType") |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + test("SPARK-59118 does not warn when doAs is disabled") { |
| 86 | + verifyingAuthTypes.foreach { authType => |
| 87 | + assert(doAsWarnings(hiveConf(authType, doAs = false)).isEmpty, s"warned: $authType") |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + test("SPARK-59118 does not warn on an untouched Hive config") { |
| 92 | + // Hive defaults doAs to true and auth to NONE, so a stock config must stay quiet. |
| 93 | + assert(doAsWarnings(new HiveConf()).isEmpty) |
| 94 | + } |
| 95 | + |
| 96 | + test("SPARK-59118 an unrecognized or empty auth type is left to Hive's own error") { |
| 97 | + // HiveAuthFactory rejects these with "Unsupported authentication type", where the |
| 98 | + // warning's advice would not help. getVar returns "" (never null) for an explicitly |
| 99 | + // empty value, so this must not NPE. |
| 100 | + Seq("NOT_AN_AUTH_TYPE", "").foreach { authType => |
| 101 | + assert(doAsWarnings(hiveConf(authType, doAs = true)).isEmpty, s"warned: $authType") |
| 102 | + } |
| 103 | + } |
| 104 | +} |
0 commit comments