okumin commented on code in PR #6474: URL: https://github.com/apache/hive/pull/6474#discussion_r3428674517
########## iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/TestIcebergVendedCredentialUtil.java: ########## @@ -0,0 +1,431 @@ +/* + * 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.iceberg.mr.hive; + +import java.util.List; +import java.util.Map; +import java.util.Properties; +import org.apache.hadoop.conf.Configuration; +import org.apache.iceberg.BaseTable; +import org.apache.iceberg.PartitionSpec; +import org.apache.iceberg.Schema; +import org.apache.iceberg.StaticTableOperations; +import org.apache.iceberg.Table; +import org.apache.iceberg.TableMetadata; +import org.apache.iceberg.io.FileIO; +import org.apache.iceberg.io.StorageCredential; +import org.apache.iceberg.io.SupportsStorageCredentials; +import org.apache.iceberg.mr.InputFormatConfig; +import org.apache.iceberg.relocated.com.google.common.collect.Maps; +import org.apache.iceberg.types.Types; +import org.apache.iceberg.util.SerializationUtil; +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link IcebergVendedCredentialUtil}: copying REST-vended storage credentials into Hive + * job configuration at plan time and re-applying them on executors. + */ +public class TestIcebergVendedCredentialUtil { + + /** + * Tests {@link IcebergVendedCredentialUtil#requestsVendedCredentials(Properties, Configuration)}. + * + * <p><b>Setup:</b> table properties name catalog {@code ice01}; session {@code conf} has no + * delegation header, then gains {@code vended-credentials}. + * + * <p><b>Expects:</b> {@code false} without the header, {@code true} with it — propagation and + * apply logic must not run for ordinary REST catalogs. + * + * <p><b>Why:</b> Iceberg REST only vends storage credentials when the client sends + * {@code X-Iceberg-Access-Delegation: vended-credentials}; Hive mirrors that opt-in via catalog + * config so static catalog keys are not replaced unnecessarily. + */ + @Test + public void requestsVendedCredentialsRequiresDelegationHeader() { + Configuration conf = new Configuration(); + Properties props = new java.util.Properties(); + props.setProperty(InputFormatConfig.CATALOG_NAME, "ice01"); + + assertThat(IcebergVendedCredentialUtil.requestsVendedCredentials(props, conf)).isFalse(); + + conf.set( + "iceberg.catalog.ice01.header.X-Iceberg-Access-Delegation", + "vended-credentials"); + assertThat(IcebergVendedCredentialUtil.requestsVendedCredentials(props, conf)).isTrue(); + } + + /** + * Tests {@link IcebergVendedCredentialUtil#propagateToJob} when both {@code jobProperties} and + * {@code jobSecrets} are non-null (full compile-time path after both storage-handler hooks). + * + * <p><b>Setup:</b> vended credential with internal endpoint {@code http://minio:9000}; session + * {@code conf} sets {@code iceberg.catalog.ice01.s3.endpoint} to {@code http://host:9000}. + * + * <p><b>Expects:</b> endpoint and path-style in {@code jobProps} (Iceberg catalog keys and S3A + * per-bucket keys) with host endpoint; access/secret and serialized blob in {@code jobSecrets} + * only; blob endpoint also host; no secret material in {@code jobProps}. + * + * <p><b>Why:</b> HIVE-20651 keeps secrets in {@code TableDesc#jobSecrets} (later Hadoop + * {@code Credentials}) and non-secrets in job conf. Catalogs often vend an internal S3 endpoint; + * HS2 overrides with a reachable host endpoint at propagation time so Tez tasks and Iceberg FileIO + * agree on connectivity while still using vended keys. + */ + @Test + public void propagateToJobMapsIcebergAndS3aProperties() { + Configuration conf = new Configuration(); + conf.set("iceberg.catalog.ice01." + IcebergVendedCredentialUtil.ENDPOINT, "http://host:9000"); + + CredentialFileIO fileIO = new CredentialFileIO(); + fileIO.setCredentials( + List.of( + StorageCredential.create( + "s3://my-bucket/", + Map.of( + IcebergVendedCredentialUtil.ACCESS_KEY_ID, "access", + IcebergVendedCredentialUtil.SECRET_ACCESS_KEY, "secret", + IcebergVendedCredentialUtil.ENDPOINT, "http://minio:9000", + IcebergVendedCredentialUtil.PATH_STYLE_ACCESS, "true")))); + + Table table = + new BaseTable(new StaticTableOperations("s3://my-bucket/t", fileIO), "db.t"); + Map<String, String> jobProps = Maps.newHashMap(); + Map<String, String> jobSecrets = Maps.newHashMap(); + + IcebergVendedCredentialUtil.propagateToJob(table, "ice01", jobProps, jobSecrets, conf); + + assertThat(jobProps) + .containsEntry( + "iceberg.catalog.ice01." + IcebergVendedCredentialUtil.ENDPOINT, + "http://host:9000") + .containsEntry( + "fs.s3a.bucket.my-bucket.endpoint", + "http://host:9000") + .containsEntry( + "fs.s3a.bucket.my-bucket.path.style.access", + "true") + .doesNotContainKey(InputFormatConfig.VENDED_STORAGE_CREDENTIALS) + .doesNotContainKey("fs.s3a.bucket.my-bucket.access.key") + .doesNotContainKey( + "iceberg.catalog.ice01." + IcebergVendedCredentialUtil.ACCESS_KEY_ID); + + assertThat(jobSecrets) + .containsEntry("fs.s3a.bucket.my-bucket.access.key", "access") + .containsEntry("fs.s3a.bucket.my-bucket.secret.key", "secret") + .doesNotContainKey( + "iceberg.catalog.ice01." + IcebergVendedCredentialUtil.ACCESS_KEY_ID) + .doesNotContainKey( + "iceberg.catalog.ice01." + IcebergVendedCredentialUtil.SECRET_ACCESS_KEY) + .satisfies(map -> + assertThat(map.get(InputFormatConfig.VENDED_STORAGE_CREDENTIALS)) + .isNotBlank()); Review Comment: I am feeling the prefix information is gone. -- 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]
