-
Notifications
You must be signed in to change notification settings - Fork 4.8k
HIVE-29359: Support Credential Vending in Hive Iceberg REST Catalog Client #6474
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
difin
wants to merge
2
commits into
apache:master
Choose a base branch
from
difin:vended_credentials_client
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,433
−184
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
iceberg/iceberg-catalog/src/main/java/org/apache/iceberg/hive/RestAccessDelegationMode.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
74 changes: 74 additions & 0 deletions
74
...g/iceberg-catalog/src/test/java/org/apache/iceberg/hive/TestRestAccessDelegationMode.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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) intoJobConffor Tez/LLAP, and vended credentials onFileIOtypically 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 indeserializeTableviaapplyFromJobConf.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:9000when 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 IcebergFileIOand 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 onFileIOfrom loadTable).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this tested? I presume it is part of serializable objects
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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: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 haveTableDesc, not the final taskJobConf, so vended credentials are staged injobPropertiesandjobSecretsper HIVE-20651. At job submit, those maps are merged intoJobConf/ Hadoop Credentials and sent to executors before tasks run.Iceberg FileIO endpoint override.
applyFromJobConfinHiveTableUtil.deserializeTableis 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) vendss3.endpoint=http://minio:9000, which tasks on the host cannot reach; session config sets a reachable endpoint (http://<host>:9000).applyFromJobConftakes vended credentials (from job conf orFileIO.properties()), replaces endpoint and path-style with session values, leaves access keys unchanged, and installs the result on the FileIO viasetCredentials(). In my debug, deserializedtable.io().properties()still hadhttp://minio:9000, so this step is required even when vended keys survive ser/de.