Spark adls 从一个容器读取并使用不同的 SPN 写入另一个容器

问题描述 投票:0回答:1

在 pyspark 中,我使用 Azure 服务原则 (SPN) 访问 ADLS Gen2。我正在使用 Spark conf 设置 SPN 凭据。

spark.conf.set("fs.azure.account.auth.type.<storage-account>.dfs.core.windows.net", "OAuth")
spark.conf.set("fs.azure.account.oauth.provider.type.<storage-account>.dfs.core.windows.net", "org.apache.hadoop.fs.azurebfs.oauth2.ClientCredsTokenProvider")
spark.conf.set("fs.azure.account.oauth2.client.id.<storage-account>.dfs.core.windows.net", "<application-id>")
spark.conf.set("fs.azure.account.oauth2.client.secret.<storage-account>.dfs.core.windows.net", service_credential)
spark.conf.set("fs.azure.account.oauth2.client.endpoint.<storage-account>.dfs.core.windows.net", "https://login.microsoftonline.com/<directory-id>/oauth2/token")

我拥有的 SPN 非常精细,提供容器级别的访问权限,而不是存储帐户级别的访问权限。这意味着对于容器 abcd 和 wxyz(在同一存储帐户中),我将有 2 个不同的 SPN。

当我配置spark conf时,我可以在存储帐户级别设置SPN。如何在容器级别设置 SPN 凭据?我的目标是以某种方式将 SPN 凭据添加到两个容器的 Sparkconf 中,并跨容器执行读/写操作。

我的用例是从一个容器读取数据以写入同一存储帐户中的另一个容器。由于SPN不同,并且我只能在spark conf中同时设置1,所以我无法做到这一点。

任何帮助将不胜感激。

azure apache-spark hadoop pyspark databricks
1个回答
0
投票

您可以在查询级别获取这些访问详细信息,并将相关选项传递给 DataFrameReader:

def credsFor(tenantId: String, clientId: String, clientSecret: String) = Map(
  "fs.azure.account.auth.type.<STORAGE_ACCOUNT>.dfs.core.windows.net" -> "OAuth",
  "fs.azure.account.oauth.provider.type.<STORAGE_ACCOUNT>.dfs.core.windows.net" -> "org.apache.hadoop.fs.azurebfs.oauth2.ClientCredsTokenProvider",
  "fs.azure.account.oauth2.client.id.<STORAGE_ACCOUNT>.dfs.core.windows.net" -> clientId,
  "fs.azure.account.oauth2.client.secret.<STORAGE_ACCOUNT>.dfs.core.windows.net" -> clientSecret,
  "fs.azure.account.oauth2.client.endpoint.<STORAGE_ACCOUNT>.dfs.core.windows.net" -> s"https://login.microsoftonline.com/$tenantId/oauth2/token"
)

val df1 = spark.read
  .format("delta")
  .options(credsFor("<TENANT>", "<APP1>", "<SECRET1>"))
  .load("<CONTAINER1>@<STORAGE_ACCOUNT>.dfs.core.windows.net/<PATH1>")

val df2 = spark.read
  .format("delta")
  .options(credsFor("<TENANT>", "<APP2>", "<SECRET2>"))
  .load("<CONTAINER2>@<STORAGE_ACCOUNT>.dfs.core.windows.net/<PATH2>")

© www.soinside.com 2019 - 2024. All rights reserved.