-
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
base: master
Are you sure you want to change the base?
Changes from all commits
3ee0502
e6e1ce2
4c3214e
ba04e4d
6a4ba0c
0f6a059
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /* | ||
| * 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.client; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.stream.Collectors; | ||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.apache.iceberg.hive.IcebergCatalogProperties; | ||
|
|
||
| /** | ||
| * 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 { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we introduce new module we can handle refactor in another PR, meanwhile could you please move
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Create a new ticket https://issues.apache.org/jira/browse/HIVE-29727 for the refactor. Moved |
||
| 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,75 @@ | ||
| /* | ||
| * 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.client; | ||
|
|
||
| import org.apache.iceberg.hive.IcebergCatalogProperties; | ||
| 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(); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.