更新时间:2024-04-02 GMT+08:00
分享

对接后二次开发

用户可根据需要进行二次开发,当前提供以下样例:

  • 自定义认证信息获取类:用于获取访问LakeFormation服务的IAM认证信息。
  • 自定义用户信息获取类:用于获取当前访问LakeFormation的用户。

自定义认证信息获取类

认证信息获取类(IdentityGenerator)用于获取访问LakeFormation服务的IAM认证信息(Token、永久AK/SK,临时AK/SK+securityToken)。

LakeFormation提供了默认的认证信息获取类,通过从配置文件中获取AKSK生成认证信息。

除LakeFormation提供的默认认证信息获取类外,可选择自行实现默认认证信息获取类。

  1. 代码开发。

    实现工程参考如下,在Maven工程pom文件中添加lakeformation-lakecat-client依赖:

    <dependency>
    <groupId>com.huawei.lakeformation</groupId>
    <artifactId>lakeformation-lakecat-client</artifactId>
    <version>${lakeformation.version}</version>
    </dependency>
    新增认证信息获取类,实现IdentityGenerator接口
    
    /*
    * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved.
    */
    
    package com.huawei.cloud.dalf.lakecat.examples;
    
    import com.huawei.cloud.dalf.lakecat.client.ConfigCenter;
    import com.huawei.cloud.dalf.lakecat.client.identity.Identity;
    import com.huawei.cloud.dalf.lakecat.client.identity.IdentityGenerator;
    
    import java.util.Collections;
    
    /**
    * 身份信息生成器样例
    *
    */
    public class LakeFormationExampleIdentityGenerator implements IdentityGenerator {
    public String token;
    
    @Override
    public void initialize(ConfigCenter configCenter) {
    //初始化
    }
    
    @Override
    public Identity generateIdentity() {
    //返回IAM认证信息
    }
    }
  2. 集成配置。

    代码通过Maven打包后将jar包放置在“spark/jars”目录下。

    根据对接方式不同,补充以下配置:

    • 使用SparkCatalogPlugin方式对接时,在spark-default.conf配置文件中补充以下配置:
      # 认证信息获取类,根据实现类路径填写,此处配置值仅作为参考
      spark.sql.catalog.catalog_name.lakecat.auth.identity.util.class=com.huawei.cloud.dalf.lakecat.client.spark.v31.impl.SparkDefaultIdentityGenerator
    • 使用MetastoreClient方式对接时,选择以下配置方式。

      在spark-default.conf补充以下配置:

      # 认证信息获取类,根据实现类路径填写,此处配置值仅作为参考
      spark.hadoop.lakecat.auth.identity.util.class=com.huawei.cloud.dalf.lakecat.client.spark.v31.impl.SparkDefaultIdentityGenerator

      或在hive-site.xml补充以下配置:

      <!--认证信息获取类,此处配置值仅作为参考-->
      <property>
      <name>lakecat.auth.identity.util.class</name>
      <value>com.huawei.cloud.dalf.lakecat.examples.LakeFormationExampleIdentityGenerator</value>
      </property>

自定义用户信息获取类

用户信息获取类(AuthenticationManager)用于获取当前访问LakeFormation的用户,可能为IAM用户或本地LDAP用户。默认用户信息获取类通过UserGroupInformation.getCurrentUser()获取当前用户。

除默认用户信息获取类外,服务可选择自行实现用户信息获取类。

如使用用户认证信息访问LakeFormation,用户信息和用户身份信息需要保持一致(即用户名、来源需要保持一致)。

  1. 代码开发。

    实现工程参考如下,在Maven工程pom文件中添加lakeformation-lakecat-client依赖:

    <dependency>
    <groupId>com.huawei.lakeformation</groupId>
    <artifactId>lakeformation-lakecat-client</artifactId>
    <version>${lakeformation.version}</version>
    </dependency>
    用户信息获取类,实现AuthenticationManager接口
    
    /*
    * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved.
    */
    
    package com.huawei.cloud.dalf.lakecat.examples;
    
    import com.huawei.cloud.dalf.lakecat.client.ConfigCenter;
    import com.huawei.cloud.dalf.lakecat.client.identity.AuthenticationManager;
    import com.huawei.cloud.dalf.lakecat.client.model.Principal;
    
    public class ExampleAuthenticationManager implements AuthenticationManager {
    @Override
    public void initialize(ConfigCenter configCenter) {
    //初始化
    }
    
    @Override
    public Principal getCurrentUser() {
    //返回当前用户信息
    }
    }
  2. 集成配置。

    代码通过Maven打包后将jar包放置在“spark/jars”目录下。

    根据对接方式不同,补充以下配置:

    • 使用SparkCatalogPlugin方式对接时,在spark-default.conf配置文件中补充以下配置:
      # 可选参数,认证管理器实现类,用于获取当前用户,此处配置值仅作为参考
      spark.sql.catalog.catalog_name.lakeformation.authentication.manager.class=com.huawei.cloud.dalf.lakecat.examples.ExampleAuthenticationManager
      # 可选参数,是否开启owner指定,开启后创建资源时将使用当前用户作为资源owner,默认为false
      spark.sql.catalog.catalog_name.lakeformation.owner.designate=true
    • 使用MetastoreClient方式对接时,可选择以下配置方式:

      在spark-default.conf补充以下配置:

      # 可选参数,认证管理器实现类,用于获取当前用户,此处配置值仅作为参考
      spark.hadoop.lakeformation.authentication.manager.class=com.huawei.cloud.dalf.lakecat.examples.ExampleAuthenticationManager
      # 可选参数,是否开启owner指定,开启后创建资源时将使用当前用户作为资源owner,默认为false
      spark.hadoop.lakeformation.owner.designate=true

      或在hive-site.xml补充以下配置:

      <!--可选参数,认证管理器实现类,用于获取当前用户,此处配置值仅作为参考-->
      <property>
      <name>lakeformation.authentication.manager.class</name>
      <value>com.huawei.cloud.dalf.lakecat.examples.ExampleAuthenticationManager</value>
      </property>
      <!--可选参数,是否开启owner指定,开启后创建资源时将使用当前用户作为资源owner,默认为false-->
      <property>
      <name>lakeformation.owner.designate</name>
      <value>true</value>
      </property>
      </configuration>
分享:

    相关文档

    相关产品