[Feature][S3] 无法通过WebIdentityTokenFileCredentialsProvider 中的 Role 和webIdentityTokenFile 访问S3

by ADMIN 93 views

概述

目前,Seatunnel 服务部署在K8s 中,需要将Mysql 数据通过 mysql cdc同步到 Hive(hive on s3)中。然而,目前只提供了as/sk 方式进行S3访问。我们希望能够通过WebIdentityTokenFileCredentialsProvider 中的 role 和webIdentityTokenFile 访问S3。

现状

目前,我们的配置文件如下:

env {
  parallelism = 1
  job.mode = "STREAMING"
  checkpoint.interval = 10000
}

source {
  MySQL-CDC {
    plugin_output = "fake"
    base-url = "jdbc:mysql://test:3306/test"
    username = "***"
    password = "****"
    
    table-names = ["test.user"]
    table-names-config = [
      {
        table = "test.user"
        primaryKeys = ["id"]
      }
    ]
  }
}

transform {
  Sql {
    plugin_input = "fake"
    plugin_output = "fake1"
    query = "select id, open_id from user"
  }
}

sink {
  Hive {
    plugin_input = "fake1"
    table_name = "tmp.test_hive_sink_on_s3"
    metastore_uri = "thrift://ip-xxx-xx-1-142.cn-north-1.compute.internal:9083"
    hive.hadoop.conf = {
        bucket="s3a://xxxxxxx"
        fs.s3a.endpoint="s3.cn-north-1.amazonaws.com.cn"
        fs.s3a.aws.credentials.provider="org.apache.hadoop.fs.s3a.WebIdentityTokenFileCredentialsProvider" //期望
    }
  }
}

然而,这种方式并不能正常访问S3。

参考

我们参考了 software.amazon.awssdk.auth.credentials.WebIdentityTokenFileCredentialsProvider 的实现。

使用场景

我们希望能够通过WebIdentityTokenFileCredentialsProvider 中的 role 和webIdentityTokenFile 访问S3。

相关问题

目前,没有相关的问题。

是否愿意提交PR

  • [ ] 是,我愿意提交PR。

行为准则

解决方案

为了解决这个问题,我们需要修改 Seatunnel 的配置文件,添加支持通过WebIdentityTokenFileCredentialsProvider 中的 role 和webIdentityTokenFile 访问S3 的功能。

实现步骤

  1. 修改 Seatunnel 的配置文件,添加支持通过WebIdentityTokenFileCredentialsProvider 中的 role 和webIdentityTokenFile 访问S3 的功能。
  2. 测试新的功能,确保能够正常访问S3。

代码示例

env {
  parallelism = 1
  job.mode = "STREAMING"
  checkpoint.interval = 10000
}

source {
  MySQL-CDC {
    plugin_output = "fake"
    base-url = "jdbc:mysql://test:3306/test"
    username = "***"
    password = "****"
    
    table-names = ["test.user"]
    table-config = [
      {
        table = "test.user"
        primaryKeys = ["id"]
      }
    ]
  }
}

transform {
  Sql {
    plugin_input = "fake"
    plugin_output = "fake1"
    query = "select id, open_id from user"
  }
}

sink {
  Hive {
    plugin_input = "fake1"
    table_name = "tmp.test_hive_sink_on_s3"
    metastore_uri = "thrift://ip-xxx-xx-1-142.cn-north-1.compute.internal:9083"
    hive.hadoop.conf = {
        bucket="s3a://xxxxxxx"
        fs.s3a.endpoint="s3.cn-north-1.amazonaws.com.cn"
        fs.s3a.aws.credentials.provider="org.apache.hadoop.fs.s3a.WebIdentityTokenFileCredentialsProvider" //期望
        fs.s3a.web-identity-token-file="/path/to/web-identity-token-file"
        fs.s3a.role-arn="arn:aws:iam::123456789012:role/MyRole"
    }
  }
}

测试

我们需要测试新的功能,确保能够正常访问S3。

结论

Q1: 什么是WebIdentityTokenFileCredentialsProvider?

A1: WebIdentityTokenFileCredentialsProvider 是一个用于获取 AWS 凭证的提供者,它使用 Web Identity Token 文件来获取凭证。

Q2: 为什么需要支持通过WebIdentityTokenFileCredentialsProvider 中的 role 和webIdentityTokenFile 访问S3?

A2: 支持通过WebIdentityTokenFileCredentialsProvider 中的 role 和webIdentityTokenFile 访问S3 可以让用户使用 Web Identity Token 文件来获取 AWS 凭证,从而实现对 S3 的访问。

Q3: 如何配置WebIdentityTokenFileCredentialsProvider?

A3: 配置WebIdentityTokenFileCredentialsProvider 需要在 Seatunnel 的配置文件中添加以下内容:

fs.s3a.aws.credentials.provider="org.apache.hadoop.fs.s3a.WebIdentityTokenFileCredentialsProvider"
fs.s3a.web-identity-token-file="/path/to/web-identity-token-file"
fs.s3a.role-arn="arn:aws:iam::123456789012:role/MyRole"

Q4: 如何测试WebIdentityTokenFileCredentialsProvider?

A4: 测试WebIdentityTokenFileCredentialsProvider 需要在 Seatunnel 的配置文件中添加以下内容:

sink {
  Hive {
    plugin_input = "fake1"
    table_name = "tmp.test_hive_sink_on_s3"
    metastore_uri = "thrift://ip-xxx-xx-1-142.cn-north-1.compute.internal:9083"
    hive.hadoop.conf = {
        bucket="s3a://xxxxxxx"
        fs.s3a.endpoint="s3.cn-north-1.amazonaws.com.cn"
        fs.s3a.aws.credentials.provider="org.apache.hadoop.fs.s3a.WebIdentityTokenFileCredentialsProvider" //期望
        fs.s3a.web-identity-token-file="/path/to/web-identity-token-file"
        fs.s3a.role-arn="arn:aws:iam::123456789012:role/MyRole"
    }
  }
}

然后,需要在 Seatunnel 的配置文件中添加以下内容:

env {
  parallelism = 1
  job.mode = "STREAMING"
  checkpoint.interval = 10000
}

source {
  MySQL-CDC {
    plugin_output = "fake"
    base-url = "jdbc:mysql://test:3306/test"
    username = "***"
    password = "****"
    
    table-names = ["test.user"]
    table-config = [
      {
        table = "test.user"
        primaryKeys = ["id"]
      }
    ]
  }
}

transform {
  Sql {
    plugin_input = "fake"
    plugin_output = "fake1"
    query = "select id, open_id from user"
  }
}

Q5: 如何解决WebIdentityTokenFileCredentialsProvider 的问题?

A5: 如果遇到 WebIdentityTokenFileCredentialsProvider 的问题,可以尝试以下解决方案:

  • 检查 Web Identity Token 文件是否正确
  • 检查 role ARN正确
  • 检查 S3 endpoint 是否正确
  • 检查 Seatunnel 的配置文件是否正确

Q6: WebIdentityTokenFileCredentialsProvider 的优点是什么?

A6: WebIdentityTokenFileCredentialsProvider 的优点包括:

  • 使用 Web Identity Token 文件来获取 AWS 凭证
  • 支持通过 role 和 web-identity-token-file 访问 S3
  • 可以实现对 S3 的访问

Q7: WebIdentityTokenFileCredentialsProvider 的缺点是什么?

A7: WebIdentityTokenFileCredentialsProvider 的缺点包括:

  • 需要在 Seatunnel 的配置文件中添加额外的配置
  • 需要在 Seatunnel 的配置文件中添加 Web Identity Token 文件的路径
  • 需要在 Seatunnel 的配置文件中添加 role ARN