Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions common/src/java/org/apache/hadoop/hive/conf/HiveConf.java
Original file line number Diff line number Diff line change
Expand Up @@ -5580,6 +5580,7 @@ public static enum ConfVars {
+ ",fs.s3a.access.key"
+ ",fs.s3a.secret.key"
+ ",fs.s3a.proxy.password"
+ ",iceberg.mr.vended.storage.credentials"
+ ",dfs.adls.oauth2.credential"
+ ",fs.adl.oauth2.credential"
+ ",fs.azure.account.oauth2.client.secret"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class IcebergCatalogProperties {
public static final String ICEBERG_HADOOP_TABLE_NAME = "location_based_table";
public static final String ICEBERG_DEFAULT_CATALOG_NAME = "default_iceberg";
public static final String NO_CATALOG_TYPE = "no catalog";
public static final String REST_ACCESS_DELEGATION_HEADER_PROPERTY = "header.X-Iceberg-Access-Delegation";

private IcebergCatalogProperties() {

Expand Down Expand Up @@ -104,6 +105,19 @@ public static String catalogPropertyConfigKey(String catalogName, String catalog
return String.format("%s%s.%s", CATALOG_CONFIG_PREFIX, catalogName, catalogProperty);
}

/**
* Returns true when the catalog is configured to request REST vended storage credentials via
* {@link #REST_ACCESS_DELEGATION_HEADER_PROPERTY}.
*/
public static boolean requestsVendedCredentials(String catalogName, Configuration conf) {
if (conf == null || StringUtils.isEmpty(catalogName)) {
return false;
}
String headerValue =
conf.get(catalogPropertyConfigKey(catalogName, REST_ACCESS_DELEGATION_HEADER_PROPERTY));
return RestAccessDelegationMode.headerRequestsVendedCredentials(headerValue);
}

/**
* Return the catalog type based on the catalog name.
* <p>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* 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.hive;

import java.util.Arrays;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;

/**
* Values for the Iceberg REST catalog {@code X-Iceberg-Access-Delegation} request header. The header
* accepts a comma-separated list of these modes; configure via
* {@link IcebergCatalogProperties#REST_ACCESS_DELEGATION_HEADER_PROPERTY}.
*
* @see <a href="https://github.com/apache/iceberg/blob/main/open-api/rest-catalog-open-api.yaml">REST catalog spec</a>
*/
public enum RestAccessDelegationMode {
VENDED_CREDENTIALS("vended-credentials"),
REMOTE_SIGNING("remote-signing");

private final String modeName;

RestAccessDelegationMode(String modeName) {
this.modeName = modeName;
}

/** Spec-defined header token for this delegation mode. */
public String modeName() {
return modeName;
}

/** Comma-separated list suitable for {@link IcebergCatalogProperties#REST_ACCESS_DELEGATION_HEADER_PROPERTY}. */
public static String toHeaderValue(RestAccessDelegationMode... modes) {
return Arrays.stream(modes).map(RestAccessDelegationMode::modeName).collect(Collectors.joining(","));
}

/** Parses a single mode name (case-insensitive); throws if unknown. */
public static RestAccessDelegationMode fromModeName(String modeName) {
for (RestAccessDelegationMode mode : values()) {
if (mode.modeName.equalsIgnoreCase(modeName.trim())) {
return mode;
}
}
throw new IllegalArgumentException(
String.format(
"Unknown REST access delegation mode: %s. Valid values are: %s",
modeName,
Arrays.stream(values()).map(RestAccessDelegationMode::modeName).collect(Collectors.joining(", "))));
}

/** Returns true if the {@code X-Iceberg-Access-Delegation} header value includes vended credentials. */
public static boolean headerRequestsVendedCredentials(String headerValue) {
if (StringUtils.isBlank(headerValue)) {
return false;
}
for (String token : headerValue.split(",")) {
if (VENDED_CREDENTIALS.modeName.equalsIgnoreCase(token.trim())) {
return true;
}
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* 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.hive;

import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

class TestRestAccessDelegationMode {

@Test
void vendedCredentialsModeName() {
assertThat(RestAccessDelegationMode.VENDED_CREDENTIALS.modeName()).isEqualTo("vended-credentials");
}

@Test
void toHeaderValueJoinsModes() {
assertThat(
RestAccessDelegationMode.toHeaderValue(
RestAccessDelegationMode.VENDED_CREDENTIALS, RestAccessDelegationMode.REMOTE_SIGNING))
.isEqualTo("vended-credentials,remote-signing");
}

@Test
void fromModeNameParsesCaseInsensitive() {
assertThat(RestAccessDelegationMode.fromModeName("VENDED-CREDENTIALS"))
.isEqualTo(RestAccessDelegationMode.VENDED_CREDENTIALS);
}

@Test
void fromModeNameRejectsUnknown() {
assertThatThrownBy(() -> RestAccessDelegationMode.fromModeName("unknown"))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("unknown");
}

@Test
void headerRequestsVendedCredentials() {
assertThat(RestAccessDelegationMode.headerRequestsVendedCredentials(null)).isFalse();
assertThat(RestAccessDelegationMode.headerRequestsVendedCredentials("remote-signing")).isFalse();
assertThat(RestAccessDelegationMode.headerRequestsVendedCredentials("vended-credentials")).isTrue();
assertThat(RestAccessDelegationMode.headerRequestsVendedCredentials("VENDED-CREDENTIALS,remote-signing"))
.isTrue();
}

@Test
void requestsVendedCredentialsFromConfiguration() {
org.apache.hadoop.conf.Configuration conf = new org.apache.hadoop.conf.Configuration();
assertThat(IcebergCatalogProperties.requestsVendedCredentials("ice01", conf)).isFalse();

conf.set(
"iceberg.catalog.ice01.header.X-Iceberg-Access-Delegation",
RestAccessDelegationMode.VENDED_CREDENTIALS.modeName());
assertThat(IcebergCatalogProperties.requestsVendedCredentials("ice01", conf)).isTrue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ private InputFormatConfig() {

public static final String CATALOG_CONFIG_PREFIX = "iceberg.catalog.";

/**
* Base64-serialized list of {@link org.apache.iceberg.io.StorageCredential} for Tez/LLAP executors.
* Stored in {@code TableDesc#jobSecrets} (HIVE-20651), not in job properties.
*/
public static final String VENDED_STORAGE_CREDENTIALS = "iceberg.mr.vended.storage.credentials";

public static final String SORT_ORDER = "sort.order";
public static final String SORT_COLUMNS = "sort.columns";
public static final String ZORDER = "ZORDER";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ private static Multimap<OutputTable, JobContext> collectOutputs(List<JobContext>
// fall back to getting the serialized table from the config
.orElseGet(() -> HiveTableUtil.deserializeTable(jobContext.getJobConf(), output));
if (table != null) {
IcebergVendedCredentialUtil.applyFromJobConf(table, jobContext.getJobConf());
String catalogName = catalogName(jobContext.getJobConf(), output);
outputs.put(new OutputTable(catalogName, output, table), jobContext);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,21 @@ public HiveAuthorizationProvider getAuthorizationProvider() {
return null;
}

@Override
public void configureInputJobCredentials(TableDesc tableDesc, Map<String, String> secrets) {
if (!IcebergVendedCredentialUtil.requestsVendedCredentials(tableDesc.getProperties(), conf)) {
return;
}
try {
Table table =
IcebergVendedCredentialUtil.getTableWithVendedCredentials(tableDesc.getProperties(), conf);
String catalogName = tableDesc.getProperties().getProperty(InputFormatConfig.CATALOG_NAME);
IcebergVendedCredentialUtil.propagateToJob(table, catalogName, null, secrets, conf);
} catch (NoSuchTableException ex) {
// Table may not exist yet for CTAS; credentials will not be available.
}
}

@Override
public void configureInputJobProperties(TableDesc tableDesc, Map<String, String> map) {
overlayTableProperties(conf, tableDesc, map);
Expand Down Expand Up @@ -335,32 +350,10 @@ public void commitJob(JobContext originalContext) {
@Override
public void configureJobConf(TableDesc tableDesc, JobConf jobConf) {
setCommonJobConf(jobConf);
if (tableDesc != null && tableDesc.getProperties() != null &&
tableDesc.getProperties().get(InputFormatConfig.OPERATION_TYPE_PREFIX + tableDesc.getTableName()) != null) {
String tableName = tableDesc.getTableName();
String opKey = InputFormatConfig.OPERATION_TYPE_PREFIX + tableName;
// set operation type into job conf too
jobConf.set(opKey, tableDesc.getProperties().getProperty(opKey));
Preconditions.checkArgument(!tableName.contains(TABLE_NAME_SEPARATOR),
"Can not handle table " + tableName + ". Its name contains '" + TABLE_NAME_SEPARATOR + "'");
if (HiveCustomStorageHandlerUtils.getWriteOperation(tableDesc.getProperties()::getProperty, tableName) != null) {
HiveCustomStorageHandlerUtils.setWriteOperation(jobConf, tableName,
Operation.valueOf(tableDesc.getProperties().getProperty(
HiveCustomStorageHandlerUtils.WRITE_OPERATION_CONFIG_PREFIX + tableName)));
}
boolean isMergeTaskEnabled = Boolean.parseBoolean(tableDesc.getProperty(
HiveCustomStorageHandlerUtils.MERGE_TASK_ENABLED + tableName));
if (isMergeTaskEnabled) {
HiveCustomStorageHandlerUtils.setMergeTaskEnabled(jobConf, tableName, true);
}
String tables = jobConf.get(InputFormatConfig.OUTPUT_TABLES);
tables = (tables == null) ? tableName : tables + TABLE_NAME_SEPARATOR + tableName;
jobConf.set(InputFormatConfig.OUTPUT_TABLES, tables);

String catalogName = tableDesc.getProperties().getProperty(InputFormatConfig.CATALOG_NAME);
if (catalogName != null) {
jobConf.set(InputFormatConfig.TABLE_CATALOG_PREFIX + tableName, catalogName);
}
configureOutputTableJobConf(tableDesc, jobConf);
if (IcebergVendedCredentialUtil.requestsVendedCredentials(tableDesc.getProperties(), conf)) {
IcebergVendedCredentialUtil.refreshVendedCredentialsIfMissing(tableDesc, jobConf, conf);
IcebergVendedCredentialUtil.applyJobSecretsToJobConf(tableDesc, jobConf);
}
try {
if (!jobConf.getBoolean(ConfVars.HIVE_IN_TEST_IDE.varname, false)) {
Expand All @@ -373,6 +366,37 @@ public void configureJobConf(TableDesc tableDesc, JobConf jobConf) {
}
}

private static void configureOutputTableJobConf(TableDesc tableDesc, JobConf jobConf) {
if (tableDesc == null || tableDesc.getProperties() == null ||
tableDesc.getProperties().get(InputFormatConfig.OPERATION_TYPE_PREFIX + tableDesc.getTableName()) == null) {
return;
}
String tableName = tableDesc.getTableName();
String opKey = InputFormatConfig.OPERATION_TYPE_PREFIX + tableName;
// set operation type into job conf too
jobConf.set(opKey, tableDesc.getProperties().getProperty(opKey));
Preconditions.checkArgument(!tableName.contains(TABLE_NAME_SEPARATOR),
"Can not handle table " + tableName + ". Its name contains '" + TABLE_NAME_SEPARATOR + "'");
if (HiveCustomStorageHandlerUtils.getWriteOperation(tableDesc.getProperties()::getProperty, tableName) != null) {
HiveCustomStorageHandlerUtils.setWriteOperation(jobConf, tableName,
Operation.valueOf(tableDesc.getProperties().getProperty(
HiveCustomStorageHandlerUtils.WRITE_OPERATION_CONFIG_PREFIX + tableName)));
}
boolean isMergeTaskEnabled = Boolean.parseBoolean(tableDesc.getProperty(
HiveCustomStorageHandlerUtils.MERGE_TASK_ENABLED + tableName));
if (isMergeTaskEnabled) {
HiveCustomStorageHandlerUtils.setMergeTaskEnabled(jobConf, tableName, true);
}
String tables = jobConf.get(InputFormatConfig.OUTPUT_TABLES);
tables = (tables == null) ? tableName : tables + TABLE_NAME_SEPARATOR + tableName;
jobConf.set(InputFormatConfig.OUTPUT_TABLES, tables);

String catalogName = tableDesc.getProperties().getProperty(InputFormatConfig.CATALOG_NAME);
if (catalogName != null) {
jobConf.set(InputFormatConfig.TABLE_CATALOG_PREFIX + tableName, catalogName);
}
}

@Override
public boolean directInsert() {
return true;
Expand Down Expand Up @@ -1681,7 +1705,11 @@ static void overlayTableProperties(Configuration configuration, TableDesc tableD
PartitionSpec spec;
String bytes;
try {
Table table = IcebergTableUtil.getTable(configuration, props);
boolean isVendedCredentials =
IcebergVendedCredentialUtil.requestsVendedCredentials(props, configuration);
Table table = isVendedCredentials ?
IcebergVendedCredentialUtil.getTableWithVendedCredentials(props, configuration) :
IcebergTableUtil.getTable(configuration, props);
location = table.location();
// set table format-version and write-mode information from tableDesc
bytes = HiveTableUtil.serializeTable(table, configuration, props,
Expand All @@ -1691,6 +1719,11 @@ static void overlayTableProperties(Configuration configuration, TableDesc tableD
schema = table.schema();
spec = table.spec();

String catalogName = props.getProperty(InputFormatConfig.CATALOG_NAME);
if (isVendedCredentials) {
IcebergVendedCredentialUtil.propagateToJob(table, catalogName, map, null, configuration);
}

// For intra-txn read-after-write: if the table has in-memory metadata with no metadata file
// (i.e. uncommitted changes from a prior statement in the same txn), write the metadata to
// a file so the Tez side can reconstruct the table with the updated state.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ public static Table deserializeTable(Configuration config, String name) {
table = readTableObjectFromFile(location, config);
}
checkAndSetIoConfig(config, table);
IcebergVendedCredentialUtil.applyFromJobConf(table, config);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most Iceberg clients don't need to ser/de credentials on their own, probably. We need it. That's because we serialize an Iceberg table in Hadoop's configuration as an intermediate expression? I guess we should store the credentials as they are and just restore them, without refining or normalizing the content on the Hive side

@difin difin Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right that most Iceberg clients don't need to ser/de credentials themselves. Hive does, because we serialize the Iceberg Table (SerializableTable) into JobConf for Tez/LLAP, and vended credentials on FileIO typically don't survive that round-trip. Executors rebuild the table from job conf and don't re-run REST loadTable, so we propagate credentials separately (VENDED_STORAGE_CREDENTIALS + S3A bucket keys) and restore them in deserializeTable via applyFromJobConf.

The main place we mutate vended credential content is withConfigurationOverrides() method. REST catalogs can vend connectivity settings from their network view (e.g. http://minio:9000 when the catalog runs in Docker), while Hive session config sets a host-reachable endpoint (iceberg.catalog.ice01.s3.endpoint=http://host:9000). That method overrides only non-secret fields (s3.endpoint, s3.path-style-access) so Iceberg FileIO and S3A agree on connectivity; vended keys are preserved. It runs at both store time (propagateToJob, so the blob on executors is self-contained) and restore time (applyFromJobConf, e.g. when commit still has the catalog-internal endpoint on FileIO from loadTable).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vended credentials on FileIO typically don't survive that round-trip

Is this tested? I presume it is part of serializable objects

@difin difin Jun 30, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested in the Gravitino q-test: you are correct — vended credentials in table.io().properties() survive ser/de to executors. We still need to extract those credentials and stage them in Hive job configuration for two reasons:

  1. Hadoop S3A. Iceberg FileIO and Hadoop S3A do not share state; S3A only reads Configuration, and Tez/LLAP use S3A for s3:// paths. At compile time (configureInputJobProperties / configureInputJobCredentials) we have TableDesc, not the final task JobConf, so vended credentials are staged in jobProperties and jobSecrets per HIVE-20651. At job submit, those maps are merged into JobConf / Hadoop Credentials and sent to executors before tasks run.

  2. Iceberg FileIO endpoint override. applyFromJobConf in HiveTableUtil.deserializeTable is still needed when REST catalogs vend S3 connection settings for their own network while Hive runs elsewhere. In the Gravitino q-test, Gravitino (in Docker) vends s3.endpoint=http://minio:9000, which tasks on the host cannot reach; session config sets a reachable endpoint (http://<host>:9000). applyFromJobConf takes vended credentials (from job conf or FileIO.properties()), replaces endpoint and path-style with session values, leaves access keys unchanged, and installs the result on the FileIO via setCredentials(). In my debug, deserialized table.io().properties() still had http://minio:9000, so this step is required even when vended keys survive ser/de.


// For intra-txn read-after-write: if a metadata file was written for uncommitted in-txn state,
// reconstruct a BaseTable from it so the Tez side sees changes from prior statements.
Expand Down
Loading
Loading