okumin commented on code in PR #6458: URL: https://github.com/apache/hive/pull/6458#discussion_r3176189891
########## standalone-metastore/metastore-rest-catalog/src/main/java/org/apache/iceberg/rest/IcebergVendedCredentialProvider.java: ########## @@ -0,0 +1,173 @@ +/* + * 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.rest; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Preconditions; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hive.conf.HiveConf; +import org.apache.hadoop.hive.metastore.credential.CompositeVendedCredentialProvider; +import org.apache.hadoop.hive.metastore.credential.StorageAccessRequest; +import org.apache.hadoop.hive.metastore.credential.StorageOperation; +import org.apache.hadoop.hive.metastore.credential.VendedCredentialProvider; +import org.apache.hadoop.hive.metastore.utils.MetaStoreUtils; +import org.apache.hadoop.hive.ql.metadata.HiveException; +import org.apache.hadoop.hive.ql.metadata.HiveUtils; +import org.apache.hadoop.hive.ql.security.authorization.plugin.*; +import org.apache.hadoop.security.UserGroupInformation; +import org.apache.iceberg.catalog.TableIdentifier; +import org.apache.iceberg.rest.credentials.Credential; +import org.apache.iceberg.rest.credentials.ImmutableCredential; + +import java.io.IOException; +import java.io.UncheckedIOException; +import java.util.Collections; +import java.util.EnumSet; +import java.util.List; +import java.util.Set; +import java.util.function.Supplier; + +/** + * This class provides vended credentials for Iceberg. + */ +public class IcebergVendedCredentialProvider { + private final String catalog; + private final VendedCredentialProvider vendedCredentialProvider; + private final Supplier<HiveAuthorizer> authorizerSupplier; + + public IcebergVendedCredentialProvider(Configuration conf) { + this.catalog = MetaStoreUtils.getDefaultCatalog(conf); + this.vendedCredentialProvider = new CompositeVendedCredentialProvider(conf); + this.authorizerSupplier = () -> { + try { + final var hiveConf = HiveConf.cloneConf(conf); + final var authorizerFactory = HiveUtils.getAuthorizerFactory(hiveConf, + HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER); + if (authorizerFactory == null) { + throw new IllegalStateException("Iceberg's Credential Vending requires Hive's Authorization Manager"); + } + + final var authenticator = HiveUtils.getAuthenticator(hiveConf, + HiveConf.ConfVars.HIVE_METASTORE_AUTHENTICATOR_MANAGER); + authenticator.setConf(hiveConf); + + final var authzContextBuilder = new HiveAuthzSessionContext.Builder(); + authzContextBuilder.setClientType(HiveAuthzSessionContext.CLIENT_TYPE.HIVEMETASTORE); + authzContextBuilder.setSessionString("IcebergRESTCatalog"); + return authorizerFactory.createHiveAuthorizer( + new HiveMetastoreClientFactoryImpl(hiveConf), hiveConf, authenticator, authzContextBuilder.build()); + } catch (HiveException e) { + throw new IllegalStateException("Failed to initialize Hive authorizer for Iceberg credential vending", e); + } + }; + } + + @VisibleForTesting + IcebergVendedCredentialProvider(String catalog, VendedCredentialProvider vendedCredentialProvider, + Supplier<HiveAuthorizer> authorizerSupplier) { + this.catalog = catalog; + this.vendedCredentialProvider = vendedCredentialProvider; + this.authorizerSupplier = authorizerSupplier; + } + + /** + * Vends credentials for the given table identifier. + * + * @param identifier the table identifier + * @param location the table location + * @return the vended credentials + */ + public List<Credential> vend(TableIdentifier identifier, String location) { Review Comment: The set of operations has not yet been concluded. Let's say an Iceberg client tries to add a new data file. The whole steps are as follows. 1. The Iceberg client issues a LoadTable request 2. The Iceberg client parses the LoadTable response and adds a new data file to the proper location 3. The Icdberg client commits the change As S3 operations follow LoadTable, we need to return credentials based on their privilege. https://docs.google.com/document/d/1zJedKkYdxulquj34sHMhyLn7D-AiGPcelADiK-AnPNo/edit?tab=t.0#heading=h.iw01gdw7g1hb -- 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]
