Repository navigation
Reject non-IMPLICIT authentication for HADOOP, HIVE and BIGQUERY connections #6145
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
youngrae81
wants to merge
1
commit into
apache:main
Choose a base branch
from
youngrae81:fix/federation-auth-type-validation
base: main
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.
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| ### Fixes | ||
|
|
||
| - Creating an external catalog with a `HADOOP`, `HIVE` or `BIGQUERY` connection and an | ||
| authentication type other than `IMPLICIT` now returns `400 Bad Request`. These connection types | ||
| only support `IMPLICIT` authentication; previously such a catalog was created, its secret was | ||
| stored, and every later request against it failed with `500 Internal Server Error`. A catalog | ||
| that was created with such a combination before this change cannot serve any request and is now | ||
| also rejected when updated; drop and recreate it with `IMPLICIT` authentication. |
65 changes: 65 additions & 0 deletions
65
...rvice/src/main/java/org/apache/polaris/service/admin/ImplicitOnlyConnectionValidator.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,65 @@ | ||
| /* | ||
| * 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.polaris.service.admin; | ||
|
|
||
| import jakarta.enterprise.context.ApplicationScoped; | ||
| import java.util.Set; | ||
| import org.apache.polaris.core.admin.model.AuthenticationParameters; | ||
| import org.apache.polaris.core.admin.model.Catalog; | ||
| import org.apache.polaris.core.admin.model.ConnectionConfigInfo; | ||
| import org.apache.polaris.core.admin.model.ExternalCatalog; | ||
|
|
||
| /** | ||
| * Rejects federated catalogs whose connection type only works with {@code IMPLICIT} authentication | ||
| * but that request another authentication type. The Hadoop, Hive and BigQuery Metastore federation | ||
| * factories refuse any other type when the catalog is first used, so such a catalog could be | ||
| * created but never used. | ||
| */ | ||
| @ApplicationScoped | ||
| public class ImplicitOnlyConnectionValidator implements CatalogConfigValidator { | ||
|
|
||
| private static final Set<ConnectionConfigInfo.ConnectionTypeEnum> IMPLICIT_ONLY = | ||
| Set.of( | ||
| ConnectionConfigInfo.ConnectionTypeEnum.HADOOP, | ||
| ConnectionConfigInfo.ConnectionTypeEnum.HIVE, | ||
| ConnectionConfigInfo.ConnectionTypeEnum.BIGQUERY); | ||
|
|
||
| @Override | ||
| public void validate(Catalog catalog) { | ||
| if (!(catalog instanceof ExternalCatalog externalCatalog)) { | ||
| return; | ||
| } | ||
| ConnectionConfigInfo connection = externalCatalog.getConnectionConfigInfo(); | ||
| if (connection == null || !IMPLICIT_ONLY.contains(connection.getConnectionType())) { | ||
| return; | ||
| } | ||
| // A missing value is reported by the request validation that requires it. | ||
| AuthenticationParameters authentication = connection.getAuthenticationParameters(); | ||
| if (authentication == null | ||
| || authentication.getAuthenticationType() | ||
| == AuthenticationParameters.AuthenticationTypeEnum.IMPLICIT) { | ||
| return; | ||
| } | ||
| throw new IllegalArgumentException( | ||
| connection.getConnectionType().name() | ||
| + " connections only support IMPLICIT authentication, but " | ||
| + authentication.getAuthenticationType().name() | ||
| + " was requested"); | ||
| } | ||
| } | ||
125 changes: 125 additions & 0 deletions
125
...e/src/test/java/org/apache/polaris/service/admin/ImplicitOnlyConnectionValidatorTest.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,125 @@ | ||
| /* | ||
| * 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.polaris.service.admin; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThatCode; | ||
| import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
|
||
| import java.util.List; | ||
| import org.apache.polaris.core.admin.model.AuthenticationParameters; | ||
| import org.apache.polaris.core.admin.model.BearerAuthenticationParameters; | ||
| import org.apache.polaris.core.admin.model.Catalog; | ||
| import org.apache.polaris.core.admin.model.CatalogProperties; | ||
| import org.apache.polaris.core.admin.model.ConnectionConfigInfo; | ||
| import org.apache.polaris.core.admin.model.ExternalCatalog; | ||
| import org.apache.polaris.core.admin.model.FileStorageConfigInfo; | ||
| import org.apache.polaris.core.admin.model.HadoopConnectionConfigInfo; | ||
| import org.apache.polaris.core.admin.model.IcebergRestConnectionConfigInfo; | ||
| import org.apache.polaris.core.admin.model.ImplicitAuthenticationParameters; | ||
| import org.apache.polaris.core.admin.model.PolarisCatalog; | ||
| import org.apache.polaris.core.admin.model.StorageConfigInfo; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class ImplicitOnlyConnectionValidatorTest { | ||
| private final ImplicitOnlyConnectionValidator validator = new ImplicitOnlyConnectionValidator(); | ||
|
|
||
| @Test | ||
| void implicitAuthenticationIsAccepted() { | ||
| assertThatCode(() -> validator.validate(hadoopCatalog(implicit()))).doesNotThrowAnyException(); | ||
| } | ||
|
|
||
| @Test | ||
| void otherAuthenticationIsRejected() { | ||
| assertThatThrownBy(() -> validator.validate(hadoopCatalog(bearer()))) | ||
| .isInstanceOf(IllegalArgumentException.class) | ||
| .hasMessage( | ||
| "HADOOP connections only support IMPLICIT authentication, but BEARER was requested"); | ||
| } | ||
|
|
||
| @Test | ||
| void missingAuthenticationIsLeftToRequestValidation() { | ||
| assertThatCode(() -> validator.validate(hadoopCatalog(null))).doesNotThrowAnyException(); | ||
| } | ||
|
|
||
| @Test | ||
| void otherConnectionTypesAreNotRestricted() { | ||
| Catalog catalog = | ||
| externalCatalog( | ||
| IcebergRestConnectionConfigInfo.builder( | ||
| ConnectionConfigInfo.ConnectionTypeEnum.ICEBERG_REST) | ||
| .setUri("https://remote.example.com/api/catalog") | ||
| .setRemoteCatalogName("remote") | ||
| .setAuthenticationParameters(bearer()) | ||
| .build()); | ||
|
|
||
| assertThatCode(() -> validator.validate(catalog)).doesNotThrowAnyException(); | ||
| } | ||
|
|
||
| @Test | ||
| void catalogsWithoutConnectionAreIgnored() { | ||
| Catalog internal = | ||
| PolarisCatalog.builder() | ||
| .setType(Catalog.TypeEnum.INTERNAL) | ||
| .setName("internal") | ||
| .setProperties(new CatalogProperties("file:///tmp/internal")) | ||
| .setStorageConfigInfo(fileStorage()) | ||
| .build(); | ||
|
|
||
| assertThatCode(() -> validator.validate(internal)).doesNotThrowAnyException(); | ||
| assertThatCode(() -> validator.validate(externalCatalog(null))).doesNotThrowAnyException(); | ||
| } | ||
|
|
||
| private static Catalog hadoopCatalog(AuthenticationParameters authenticationParameters) { | ||
| return externalCatalog( | ||
| HadoopConnectionConfigInfo.builder(ConnectionConfigInfo.ConnectionTypeEnum.HADOOP) | ||
| .setWarehouse("file:///tmp/warehouse") | ||
| .setAuthenticationParameters(authenticationParameters) | ||
| .build()); | ||
| } | ||
|
|
||
| private static Catalog externalCatalog(ConnectionConfigInfo connection) { | ||
| return ExternalCatalog.builder() | ||
| .setType(Catalog.TypeEnum.EXTERNAL) | ||
| .setName("external") | ||
| .setProperties(new CatalogProperties("file:///tmp/external")) | ||
| .setStorageConfigInfo(fileStorage()) | ||
| .setConnectionConfigInfo(connection) | ||
| .build(); | ||
| } | ||
|
|
||
| private static StorageConfigInfo fileStorage() { | ||
| return FileStorageConfigInfo.builder() | ||
| .setStorageType(StorageConfigInfo.StorageTypeEnum.FILE) | ||
| .setAllowedLocations(List.of("file:///tmp/")) | ||
| .build(); | ||
| } | ||
|
|
||
| private static AuthenticationParameters implicit() { | ||
| return ImplicitAuthenticationParameters.builder() | ||
| .setAuthenticationType(AuthenticationParameters.AuthenticationTypeEnum.IMPLICIT) | ||
| .build(); | ||
| } | ||
|
|
||
| private static AuthenticationParameters bearer() { | ||
| return BearerAuthenticationParameters.builder() | ||
| .setAuthenticationType(AuthenticationParameters.AuthenticationTypeEnum.BEARER) | ||
| .setBearerToken("some-token") | ||
| .build(); | ||
| } | ||
| } |
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.
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.
This set restates the rule the Hadoop/Hive/BigQuery factories enforce at first use. Fine today, but if one of them later gains BEARER support, this validator will keep rejecting it at create time and nobody will notice until a user does. Can we drop a one-line comment next to the IMPLICIT check in each factory pointing back here?
🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.