Databricks 15.4 LTS 在连接到 Azure Key Vault 时抛出错误

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

我有一个在 Databricks 15.4(ARM 集群)上的 Java 17 上运行的 scala 应用程序,当执行以下代码时

import com.azure.security.keyvault.secrets.SecretClient
import com.azure.security.keyvault.secrets.models.KeyVaultSecret
import com.azure.identity.DefaultAzureCredentialBuilder
import com.azure.security.keyvault.secrets.SecretClientBuilder

val cred = new DefaultAzureCredentialBuilder().build()

val keyVaultClient = new SecretClientBuilder()
    .vaultUrl("https://my-key-vault-name.vault.azure.net/")
    .credential(cred)
    .buildClient()

val result = keyVaultClient.getSecret("secret-name")
println(result.getValue())

它会抛出以下错误。如果我使用 AMD 集群而不是 ARM 集群,它可以正常工作。

UncheckedIOException: io.netty.channel.StacklessClosedChannelException
Caused by: StacklessClosedChannelException: 
    at com.azure.core.http.netty.NettyAsyncHttpClient.sendSync(NettyAsyncHttpClient.java:201)
    at com.azure.core.http.HttpPipelineNextSyncPolicy.processSync(HttpPipelineNextSyncPolicy.java:51)
    at com.azure.core.http.policy.HttpLoggingPolicy.processSync(HttpLoggingPolicy.java:175)
    at com.azure.core.http.HttpPipelineNextSyncPolicy.processSync(HttpPipelineNextSyncPolicy.java:53)
    at com.azure.core.implementation.http.policy.InstrumentationPolicy.processSync(InstrumentationPolicy.java:101)
    at com.azure.core.http.HttpPipelineNextSyncPolicy.processSync(HttpPipelineNextSyncPolicy.java:53)
    at com.azure.security.keyvault.secrets.implementation.KeyVaultCredentialPolicy.processSync(KeyVaultCredentialPolicy.java:386)
    at com.azure.core.http.HttpPipelineNextSyncPolicy.processSync(HttpPipelineNextSyncPolicy.java:53)
    at com.azure.core.http.policy.RetryPolicy.attemptSync(RetryPolicy.java:217)
    at com.azure.core.http.policy.RetryPolicy.attemptSync(RetryPolicy.java:233)
    at com.azure.core.http.policy.RetryPolicy.attemptSync(RetryPolicy.java:233)
    at com.azure.core.http.policy.RetryPolicy.attemptSync(RetryPolicy.java:233)
    at com.azure.core.http.policy.RetryPolicy.processSync(RetryPolicy.java:161)
    at com.azure.core.http.HttpPipelineNextSyncPolicy.processSync(HttpPipelineNextSyncPolicy.java:53)
    at com.azure.core.http.policy.AddHeadersPolicy.processSync(AddHeadersPolicy.java:66)
    at com.azure.core.http.HttpPipelineNextSyncPolicy.processSync(HttpPipelineNextSyncPolicy.java:53)
    at com.azure.core.http.policy.HttpPipelineSyncPolicy.processSync(HttpPipelineSyncPolicy.java:51)
    at com.azure.core.http.policy.UserAgentPolicy.processSync(UserAgentPolicy.java:174)
    at com.azure.core.http.HttpPipelineNextSyncPolicy.processSync(HttpPipelineNextSyncPolicy.java:53)
    at com.azure.core.http.HttpPipeline.sendSync(HttpPipeline.java:138)
    at com.azure.core.implementation.http.rest.SyncRestProxy.send(SyncRestProxy.java:62)

我保证

  • 我有权访问天蓝色资源。事实上,它适用于 Spark 3.4.2 和 Java 8 上的 Databricks 13.x 集群。
  • 安装了必要的 jar,并且类型已解决,没有问题。
  • 子网/网络没有任何禁止物理访问资源的限制。

有什么可以寻找的线索吗?

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

当我尝试你的方法时,我收到了错误

command-417994642726454:3: error: object azure is not a member of package com import com.azure.security.keyvault.secrets.SecretClient

正如您提到的,您正在使用 ARM 集群。

我在网上找到了这个,你可以使用netty进行身份验证& sdk将其包含在

pom.xml
中:

<dependency>
    <groupId>com.azure</groupId>
    <artifactId>azure-core-http-netty</artifactId>
    <version>1.12.4</version>
</dependency>

我已经使用 pyspark 尝试了以下方法。

以下是我的 Azure databricks 集群配置:

enter image description here

enter image description here

接下来我尝试了以下代码:

from azure.identity import ClientSecretCredential
from azure.keyvault.secrets import SecretClient
client_id = "<YOUR CLINET ID>"
client_secret = "<YOUR CLIENT SECRET>"
tenant_id = "<YOUR TENAT ID>"
vault_url = "https://dileeprajnarayan-kv.vault.azure.net/"
secret_name = "new1"
credential = ClientSecretCredential(tenant_id, client_id, client_secret)
secret_client = SecretClient(vault_url, credential)
secret = secret_client.get_secret(secret_name)
print(f"Secret value for the secret '{secret_name}' is: {secret.value}")

enter image description here

在上面的代码中,我使用

ClientSecretCredential
进行身份验证并创建
SecretClient
接下来找回秘密

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