okumin commented on code in PR #6928:
URL: https://github.com/apache/hive/pull/6928#discussion_r4420150978


##########
ql/src/test/org/apache/hadoop/hive/ql/txn/compactor/TestCompactorPropertyValidator.java:
##########
@@ -0,0 +1,296 @@
+/*
+ * 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.hive.ql.txn.compactor;
+
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class TestCompactorPropertyValidator {
+
+  @ParameterizedTest
+  @ValueSource(strings = {
+      "mapreduce.map.memory.mb",
+      "mapreduce.reduce.memory.mb",
+      "mapreduce.map.cpu.vcores",
+      "mapreduce.reduce.cpu.vcores",
+      "hive.tez.container.size",
+      "tez.task.resource.memory.mb",
+      "mapreduce.job.heap.memory-mb.ratio",
+      "mapreduce.task.io.sort.factor",
+      "mapreduce.task.io.sort.mb",
+      "yarn.app.mapreduce.am.resource.cpu-vcores",
+      "yarn.app.mapreduce.am.resource.mb",
+      "tez.am.resource.memory.mb",
+      "tez.am.resource.cpu.vcores",
+      "tez.grouping.min-size",
+      "tez.grouping.max-size",
+      "tez.grouping.split-waves"})
+  void testResourceConfigs(String key) {
+    assertTrue(allowed(new HiveConf(), key), key + " has to be settable in 
compaction job config.");
+  }
+
+  @ParameterizedTest
+  @ValueSource(strings = {
+      "hive.compactor.gather.stats",
+      "hive.mr.compactor.gather.stats",
+      "hive.compactor.compact.insert.only",
+      "hive.compactor.crud.query.based",
+      "hive.compactor.max.num.delta",
+      "hive.compactor.aborted.txn.time.threshold",
+      "hive.compactor.abortedtxn.threshold",
+      "hive.compactor.active.delta.dir.threshold",
+      "hive.compactor.delta.num.threshold",
+      "hive.compactor.obsolete.delta.dir.threshold",
+      "hive.compactor.delta.pct.threshold",
+      "hive.compactor.small.delta.dir.threshold"})
+  void testCompactorConfigs(String key) {
+    assertTrue(allowed(new HiveConf(), key), key + " has to be settable in 
compaction job config.");
+  }
+
+  @ParameterizedTest
+  @ValueSource(strings = {
+      "mapreduce.job.queuename",
+      "mapred.job.queue.name",
+      "tez.queue.name",
+      "hive.compactor.job.queue",
+      "hive.compactor.request.queue"})
+  void testQueueConfigs(String key) {
+    assertTrue(allowed(new HiveConf(), key), key + " has to be settable in 
compaction job config.");
+  }
+
+  @ParameterizedTest
+  @ValueSource(strings = {
+      "orc.compress",
+      "orc.stripe.size",
+      "orc.bloom.filter.columns",
+      "hive.exec.orc.default.buffer.size"})
+  void testOrcConfigs(String key) {
+    assertTrue(allowed(new HiveConf(), key), key + " has to be settable in 
compaction job config.");
+  }
+
+  @ParameterizedTest
+  @ValueSource(strings = {
+      "fs.defaultFS",
+      "fs.s3a.access.key",
+      "fs.AbstractFileSystem.abfs.impl",
+      "hadoop.security.authentication",
+      "hadoop.security.auth_to_local",
+      "hadoop.rpc.socket.factory.class.default",
+      "hadoop.htrace.span.receiver.classes",
+      "hadoop.ssl.enabled.protocols",
+      "hadoop.zk.kerberos.principal",
+      "hadoop.http.authentication.kerberos.principal",
+      "hive.exec.pre.hooks",
+      "hive.exec.post.hooks",
+      "hive.metastore.rawstore.impl",
+      "hadoop.zk.kerberos.keytab",
+      "hadoop.http.authentication.kerberos.keytab",
+      "hive.security.authenticator.manager",
+      "hive.server2.job.credential.provider.path",
+      "hive.intermediate.compression.codec",
+      "hive.metastore.end.function.listeners",
+      "hadoop.token.files",
+      "javax.jdo.PersistenceManagerFactoryClass",
+      "mapreduce.map.java.opts",
+      "mapred.child.java.opts",
+      "hive.tez.java.opts",
+      "hive.exim.uri.scheme.whitelist",
+      "hive.exec.script.maxerrsize",
+      "hive.script.operator.env.blacklist",
+      "hive.llap.plugin.acl",
+      "hive.exec.scratchdir",
+      "hive.metastore.event.message.factory",
+      "hive.exec.plan",
+      "hive.aux.jars.path",
+      "hive.added.jars.path",
+      "hive.exec.perf.logger",
+      "hive.log4j.file",
+      "hive.exec.script.wrapper",
+      "hive.qtest.additional.partial.mask.pattern",
+      "mapreduce.job.classloader",
+      "mapreduce.application.classpath",
+      "yarn.application.classpath",
+      "mapreduce.task.profile.params",
+      "hadoop.tmp.dir",
+      "hive.added.archives.path",
+      "hive.tez.hs2.user.access",
+      "orc.encrypt"})
+  void testParametersRejected(String key) {
+    assertFalse(allowed(new HiveConf(), key),
+        key + " has to be rejected by hive.compactor.conf.allowlist or 
hive.compactor.conf.denylist");
+  }
+
+  @ParameterizedTest
+  @ValueSource(strings = {
+      "hive.exec.pre.hooks",
+      "hive.exec.post.hooks",
+      "hive.exec.failure.hooks",
+      "hive.exec.driver.run.hooks",
+      "hive.exec.query.redactor.hooks",
+      "hive.exec.perf.logger",
+      "hive.optimize.cte.suggester.class",
+      "hive.tez.mapreduce.output.committer.class",
+      "tez.task.scale.memory.allocator.class",
+      "tez.task.scale.task.memory.allocator.class",
+      "orc.filter.plugin",
+      "orc.filter.plugin.allowlist",
+      "mapreduce.map.output.compress.codec",
+      "hive.exec.script.wrapper",
+      "hive.exec.script.trust",
+      "hive.exec.script.allow.partial.consumption",
+      "mapreduce.map.java.opts",
+      "mapreduce.reduce.java.opts",
+      "hive.tez.java.opts",
+      "mapreduce.map.env",
+      "mapreduce.reduce.env",
+      "hive.exec.scratchdir",
+      "hive.exec.local.scratchdir",
+      "hive.exec.stagingdir",
+      "hive.exec.submitviachild",
+      "hive.exec.submit.local.task.via.child",
+      "hive.exec.plan",
+      "hive.exec.log4j.file",
+      "orc.key.provider",
+      "orc.encrypt","orc.mask",

Review Comment:
   ```suggestion
         "orc.encrypt",
         "orc.mask",
   ```



##########
ql/src/test/org/apache/hadoop/hive/ql/txn/compactor/TestMRCompactorJobQueueConfiguration.java:
##########
@@ -62,6 +65,99 @@ void testCreateBaseJobConfHasCorrectJobQueue(ConfSetup 
input) {
     assertEquals(input.expectedQueue, c.getQueueName(), "Test failed for the 
following input:" + input);
   }
 
+  /**
+   * A table property must not be able to inject JVM arguments into the 
compaction map containers,
+   * since the compaction job may run as a privileged user (see 
metastore.compactor.run.as.user)
+   * while the property itself is settable by anyone owning the table.
+   */
+  @Test
+  void testCreateBaseJobConfIgnoresDeniedMRPropertyFromTableProperties() {
+    JobConf c = 
createBaseJobConf(Collections.singletonMap("compactor.mapreduce.map.java.opts",
+            "-javaagent:/tmp/evil.jar"), Collections.emptyMap(), 
Collections.emptyMap());
+    assertNull(c.get("mapreduce.map.java.opts"), "JVM options must not be 
settable via tblproperties");
+  }
+
+  /**
+   * Same as above, but through the ALTER TABLE ... COMPACT ... WITH OVERWRITE 
TBLPROPERTIES route,
+   * which reaches the same sink via a different argument.
+   */
+  @Test
+  void testCreateBaseJobConfIgnoresDeniedMRPropertyFromCompactionProperties() {
+    JobConf c = createBaseJobConf(Collections.emptyMap(), 
Collections.singletonMap("compactor.tmpjars",
+            "hdfs:///tmp/evil.jar"), Collections.emptyMap());
+    assertNull(c.get("tmpjars"), "Classpath additions must not be settable via 
ALTER TABLE COMPACT");
+  }
+
+  /**
+   * Keys on hive.conf.restricted.list are immutable at runtime and rejected by
+   * {@link HiveConf#verifyAndSet(String, String)}. The compactor writes 
through the unchecked
+   * setter, so it must apply the same policy itself.
+   */
+  @Test
+  void testCreateBaseJobConfIgnoresRestrictedListProperty() {
+    JobConf c = createBaseJobConf(
+        
Collections.singletonMap("compactor.hive.security.authenticator.manager", 
"com.attacker.Authenticator"),
+        Collections.emptyMap(), 
Collections.singletonMap(HiveConf.ConfVars.HIVE_CONF_RESTRICTED_LIST.varname,
+            "hive.security.authenticator.manager"));
+    assertNotEquals("com.attacker.Authenticator", 
c.get("hive.security.authenticator.manager"),
+        "Restricted configs must not be overridable via tblproperties");
+  }
+
+  /** Values on hive.conf.hidden.list are credentials; they must not be 
redirectable either. */
+  @Test
+  void testCreateBaseJobConfIgnoresHiddenListProperty() {
+    JobConf c = 
createBaseJobConf(Collections.singletonMap("compactor.fs.s3a.secret.key", 
"attacker-key"),
+        Collections.emptyMap(), Collections.emptyMap());
+    assertNull(c.get("fs.s3a.secret.key"), "Hidden configs must not be 
settable via tblproperties");
+  }
+
+  /** Guards against the fix being over-broad: documented resource tuning must 
keep working. */
+  @Test
+  void testCreateBaseJobConfStillAppliesLegitimateOverrides() {
+    Map<String, String> tableProperties = new HashMap<>();
+    tableProperties.put("compactor.mapreduce.map.memory.mb", "2048");
+    tableProperties.put("compactor.hive.compactor.gather.stats", "false");
+    JobConf c = createBaseJobConf(tableProperties, Collections.emptyMap(), 
Collections.emptyMap());
+    assertEquals("2048", c.get("mapreduce.map.memory.mb"));
+    assertEquals("false", c.get("hive.compactor.gather.stats"));
+  }
+
+  /**
+   * The "tblprops." prefix of ALTER TABLE ... COMPACT does not reach the job 
configuration, but it
+   * does reach the table properties handed to the ORC record writers, which 
select a key provider,
+   * an encryption or masking policy, and a filter plugin from that map.
+   */
+  @Test
+  void testCreateBaseJobConfIgnoresDeniedTblProperty() {
+    JobConf c = createBaseJobConf(Collections.emptyMap(),
+        Collections.singletonMap("tblprops.orc.key.provider", 
"kms://attacker"), Collections.emptyMap());
+    Map<String, String> tableProps = new 
StringableMap(c.get("hive.compactor.table.props"));
+    assertNull(tableProps.get("orc.key.provider"),
+        "Encryption key provider must not be settable via ALTER TABLE 
COMPACT");
+  }
+
+  /** Guards against over-blocking: ordinary ORC tuning through "tblprops." 
must still work. */
+  @Test
+  void testCreateBaseJobConfStillAppliesLegitimateTblProperty() {
+    JobConf c = createBaseJobConf(Collections.emptyMap(), 
Collections.singletonMap("tblprops.orc.compress", "ZLIB"),
+        Collections.emptyMap());
+    Map<String, String> tableProps = new 
StringableMap(c.get("hive.compactor.table.props"));
+    assertEquals("ZLIB", tableProps.get("orc.compress"));
+  }
+
+
+  private static JobConf createBaseJobConf(Map<String, String> tableProperties,
+        Map<String, String> compactionProperties, Map<String, String> 
confProperties) {
+      Table tbl = createPersonTable();
+      tbl.setParameters(new HashMap<>(tableProperties));

Review Comment:
   ```suggestion
       Table tbl = createPersonTable();
       tbl.setParameters(new HashMap<>(tableProperties));
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to