Skip to content

Commit

Permalink
Fix hive.hive-views.run-as-invoker handling with legacy view translation
Browse files Browse the repository at this point in the history
Prevent ViewReaders from passing view owner to ConnectorViewDefinition constructor,
as it may fail the sanity check. The owner is added later on in HiveMetadata class

Also add product test for `hive.hive-views.run-as-invoker` config option.
Unit tests will not work here since we need to create a hive view not via Trino.

Co-authored-by: Joe Chu <5282594+joechu1@users.noreply.github.com>
  • Loading branch information
2 people authored and findepi committed Sep 20, 2022
1 parent 5ac5fdb commit 2b77883
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 2 deletions.
Expand Up @@ -49,7 +49,7 @@ public ConnectorViewDefinition decodeViewData(String viewData, Table table, Cata
.map(column -> new ConnectorViewDefinition.ViewColumn(column.getName(), TypeId.of(column.getType().getTypeSignature().toString())))
.collect(toImmutableList()),
Optional.ofNullable(table.getParameters().get(TABLE_COMMENT)),
table.getOwner(),
Optional.empty(), // will be filled in later by HiveMetadata
hiveViewsRunAsInvoker);
}
}
Expand Up @@ -227,7 +227,7 @@ public ConnectorViewDefinition decodeViewData(String viewSql, Table table, Catal
Optional.of(table.getDatabaseName()),
columns,
Optional.ofNullable(table.getParameters().get(TABLE_COMMENT)),
Optional.empty(),
Optional.empty(), // will be filled in later by HiveMetadata
hiveViewsRunAsInvoker);
}
catch (RuntimeException e) {
Expand Down
Expand Up @@ -40,6 +40,7 @@ public final class Hadoop
public static final String CONTAINER_PRESTO_HIVE_PROPERTIES = CONTAINER_PRESTO_ETC + "/catalog/hive.properties";
public static final String CONTAINER_PRESTO_HIVE_WITH_EXTERNAL_WRITES_PROPERTIES = CONTAINER_PRESTO_ETC + "/catalog/hive_with_external_writes.properties";
public static final String CONTAINER_PRESTO_HIVE_TIMESTAMP_NANOS = CONTAINER_PRESTO_ETC + "/catalog/hive_timestamp_nanos.properties";
public static final String CONTAINER_PRESTO_HIVE_RUN_VIEW_AS_INVOKER = CONTAINER_PRESTO_ETC + "/catalog/hive_with_run_view_as_invoker.properties";
public static final String CONTAINER_PRESTO_ICEBERG_PROPERTIES = CONTAINER_PRESTO_ETC + "/catalog/iceberg.properties";

private final DockerFiles dockerFiles;
Expand Down Expand Up @@ -68,6 +69,7 @@ public void extendEnvironment(Environment.Builder builder)
builder.addConnector("hive", forHostPath(dockerFiles.getDockerFilesHostPath("common/hadoop/hive.properties")), CONTAINER_PRESTO_HIVE_PROPERTIES);
builder.addConnector("hive", forHostPath(dockerFiles.getDockerFilesHostPath("common/hadoop/hive_with_external_writes.properties")), CONTAINER_PRESTO_HIVE_WITH_EXTERNAL_WRITES_PROPERTIES);
builder.addConnector("hive", forHostPath(dockerFiles.getDockerFilesHostPath("common/hadoop/hive_timestamp_nanos.properties")), CONTAINER_PRESTO_HIVE_TIMESTAMP_NANOS);
builder.addConnector("hive", forHostPath(dockerFiles.getDockerFilesHostPath("common/hadoop/hive_with_run_view_as_invoker.properties")), CONTAINER_PRESTO_HIVE_RUN_VIEW_AS_INVOKER);
builder.addConnector("iceberg", forHostPath(dockerFiles.getDockerFilesHostPath("common/hadoop/iceberg.properties")), CONTAINER_PRESTO_ICEBERG_PROPERTIES);
}

Expand Down
Expand Up @@ -26,9 +26,11 @@
import static io.trino.tests.product.launcher.env.EnvironmentContainers.COORDINATOR;
import static io.trino.tests.product.launcher.env.EnvironmentContainers.WORKER;
import static io.trino.tests.product.launcher.env.common.Hadoop.CONTAINER_PRESTO_HIVE_PROPERTIES;
import static io.trino.tests.product.launcher.env.common.Hadoop.CONTAINER_PRESTO_HIVE_RUN_VIEW_AS_INVOKER;
import static io.trino.tests.product.launcher.env.common.Hadoop.CONTAINER_PRESTO_HIVE_TIMESTAMP_NANOS;
import static io.trino.tests.product.launcher.env.common.Hadoop.CONTAINER_PRESTO_HIVE_WITH_EXTERNAL_WRITES_PROPERTIES;
import static io.trino.tests.product.launcher.env.common.Hadoop.CONTAINER_PRESTO_ICEBERG_PROPERTIES;
import static io.trino.tests.product.launcher.env.common.Standard.CONTAINER_PRESTO_ETC;
import static io.trino.tests.product.launcher.env.common.Standard.CONTAINER_PRESTO_JVM_CONFIG;
import static java.util.Objects.requireNonNull;
import static org.testcontainers.utility.MountableFile.forHostPath;
Expand All @@ -37,6 +39,8 @@
public final class EnvMultinode
extends EnvironmentProvider
{
public static final String CONTAINER_PRESTO_HIVE_ACCESS_CONTROL = CONTAINER_PRESTO_ETC + "/catalog/hive.properties";

private final DockerFiles dockerFiles;
private final DockerFiles.ResourceProvider configDir;

Expand All @@ -59,6 +63,7 @@ public void extendEnvironment(Environment.Builder builder)
.withCopyFileToContainer(forHostPath(dockerFiles.getDockerFilesHostPath("common/hadoop/hive.properties")), CONTAINER_PRESTO_HIVE_PROPERTIES)
.withCopyFileToContainer(forHostPath(dockerFiles.getDockerFilesHostPath("common/hadoop/hive_with_external_writes.properties")), CONTAINER_PRESTO_HIVE_WITH_EXTERNAL_WRITES_PROPERTIES)
.withCopyFileToContainer(forHostPath(dockerFiles.getDockerFilesHostPath("common/hadoop/hive_timestamp_nanos.properties")), CONTAINER_PRESTO_HIVE_TIMESTAMP_NANOS)
.withCopyFileToContainer(forHostPath(dockerFiles.getDockerFilesHostPath("common/hadoop/hive_with_run_view_as_invoker.properties")), CONTAINER_PRESTO_HIVE_RUN_VIEW_AS_INVOKER)
.withCopyFileToContainer(forHostPath(dockerFiles.getDockerFilesHostPath("common/hadoop/iceberg.properties")), CONTAINER_PRESTO_ICEBERG_PROPERTIES));
}
}
@@ -0,0 +1,8 @@
connector.name=hive
hive.metastore.uri=thrift://hadoop-master:9083
hive.config.resources=/docker/presto-product-tests/conf/presto/etc/hive-default-fs-site.xml
hive.metastore-cache-ttl=0s
hive.fs.cache.max-size=10
hive.hive-views.enabled=true
hive.hive-views.run-as-invoker=true
hive.security=sql-standard
Expand Up @@ -688,6 +688,26 @@ public void testViewWithColumnAliasesDifferingInCase()
onHive().executeQuery("DROP VIEW test_namesake_column_names_view");
}

@Test(groups = HIVE_VIEWS)
public void testRunAsInvoker()
{
onTrino().executeQuery("DROP TABLE IF EXISTS run_as_invoker");
onTrino().executeQuery("DROP VIEW IF EXISTS run_as_invoker_view");

onTrino().executeQuery("CREATE TABLE run_as_invoker (a INTEGER)");
onHive().executeQuery("CREATE VIEW run_as_invoker_view AS SELECT * FROM run_as_invoker");
onTrino().executeQuery("GRANT SELECT ON hive_with_run_view_as_invoker.default.run_as_invoker_view TO hive");

String definerQuery = "SELECT * FROM hive.default.run_as_invoker_view";
String invokerQuery = "SELECT * FROM hive_with_run_view_as_invoker.default.run_as_invoker_view";
assertThat(connectToTrino("alice@presto").executeQuery(definerQuery)).hasNoRows(); // Allowed
assertThatThrownBy(() -> connectToTrino("alice@presto").executeQuery(invokerQuery))
.hasMessageContaining("Access Denied");

onHive().executeQuery("DROP VIEW run_as_invoker_view");
onTrino().executeQuery("DROP TABLE run_as_invoker");
}

protected static void assertViewQuery(String query, Consumer<QueryAssert> assertion)
{
// Ensure Hive and Presto view compatibility by comparing the results
Expand Down

0 comments on commit 2b77883

Please sign in to comment.