简体   繁体   English

使用 AAD 令牌在 Databricks 中创建 Azure Key Vault 支持的机密 scope

[英]Create Azure Key Vault backed secret scope in Databricks with AAD Token

My ultimate goal is to mount ADLS gen2 containers into my Databricks workspace as part of my Terraform-managed deployment under the auspices of an Azure Service Principal.我的最终目标是在 Azure 服务委托人的支持下,将 ADLS gen2 容器安装到我的 Databricks 工作区中,作为我的 Terraform 管理部署的一部分。 This is a single deployment that creates all the Azure resources .networking, firewall, storage accounts, Databricks workspaces, etc.) and then configures the Databricks workspace, using the Databricks Terraform provider.这是创建所有 Azure 资源(网络、防火墙、存储帐户、Databricks 工作区等)然后使用 Databricks Terraform 提供程序配置 Databricks 工作区的单一部署。

This answer says I cannot do AAD passthrough mounting with a Service Principal, which means I have to use OAuth2 authentication.这个答案说我不能使用服务主体进行 AAD 直通安装,这意味着我必须使用 OAuth2 身份验证。 For which, I need an Azure Key Vault backed secret scope in Databricks.为此,我需要 Databricks 中的 Azure Key Vault 支持的秘密 scope。 The Terraform documentation says I can only do this with user-based authentication, not with my Service Principal. Terraform 文档说我只能使用基于用户的身份验证来执行此操作,而不能使用我的服务主体。

So I thought maybe I could implement a hack: Create a Databricks PAT in Terraform (again, always as the Service Principal), then use the Terraform external resource to "shell out" to the Databricks CLI, authenticating with this PAT.所以我想也许我可以实施一个 hack:在 Terraform 中创建一个 Databricks PAT(同样,始终作为服务主体),然后使用 Terraform external资源“退出”到 Databricks CLI,使用此 PAT 进行身份验证。 I tried this manually and got this error:我手动尝试了这个并得到了这个错误:

{
  "error_code": "INVALID_PARAMETER_VALUE",
  "message": "Scope with Azure KeyVault must have userAADToken defined!"
}

This stands to reason, because the PAT is created for the Service Principal.这是有道理的,因为 PAT 是为 Service Principal 创建的。 However, as an alternative, this answer suggests using Azure AD token authentication, rather than the PAT.但是,作为替代方案,此答案建议使用 Azure AD 令牌身份验证,而不是 PAT。 So down that rabbit hole, I go!所以在那个兔子洞里,我走了!

I can get the Azure AD token following Microsoft's documentation , then use that to authenticate for the Databricks CLI:我可以按照Microsoft 的文档获取 Azure AD 令牌,然后使用它对 Databricks CLI 进行身份验证:

export ARM_TENANT_ID="..."
export ARM_CLIENT_ID="..."
export ARM_CLIENT_SECRET="..."

export DATABRICKS_AAD_TOKEN="$(curl -X POST \
                                    -H 'Content-Type: application/x-www-form-urlencoded' \
                                    -d "client_id=${ARM_CLIENT_ID}" \
                                    -d 'grant_type=client_credentials' \
                                    -d 'scope=2ff814a6-3304-4ab8-85cb-cd0e6f879c1d%2F.default' \
                                    -d "client_secret=${ARM_CLIENT_SECRET}" \
                                    https://login.microsoftonline.com/${ARM_TENANT_ID}/oauth2/v2.0/token \
                             | jq -r .access_token)"

databricks configure --aad-token --host https://my-databricks-host.com

This authentication works: I can run various CLI commands (eg, databricks tokens list ) that return the expected result.此身份验证有效:我可以运行返回预期结果的各种 CLI 命令(例如, databricks tokens list )。 However, now when I try to create the secret scope, it gives me a completely different error:但是,现在当我尝试创建秘密 scope 时,它给了我一个完全不同的错误:

databricks secrets create-scope --scope "test" \
                                --scope-backend-type AZURE_KEYVAULT \
                                --resource-id "/subscriptions/my/key/vault/resource/id" \
                                --dns-name "https://my-vault-name.vault.azure.net/"

Error: Your authentication information may be incorrect. Please reconfigure with ``dbfs configure``

My first question would be: Is my hack even going to work?我的第一个问题是:我的 hack 是否有效? If it is, where am I going wrong with the AAD token authentication?如果是,AAD 令牌身份验证哪里出错了? If it isn't going to work, is my ultimate goal even possible, or would I have to run several Terraform deployments -- each with their own state -- in phases, under different AAD identities (Service Principal and regular user)?如果它不起作用,我的最终目标是否可能,或者我是否必须在不同的 AAD 身份(服务主体和普通用户)下分阶段运行多个 Terraform 部署——每个部署都有自己的 state?

Yes, you can't do that using AAD token issued for a service principal - it works only with AAD token of real user.是的,您不能使用为服务主体颁发的 AAD 令牌来执行此操作 - 它仅适用于真实用户的 AAD 令牌。 It's well known and well documented limitation of Azure, hopefully it will be fixed in future.这是 Azure 的众所周知且有据可查的限制,希望将来会得到修复。

This is one of the major roadblocks on the way of implementing end-to-end automated provisioning of Azure Databricks workspaces这是实现 Azure Databricks 工作区端到端自动配置的主要障碍之一

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Azure Key-vault 中哪里可以找到秘密的 scope - Where to find the scope of a secret in Azure Key-vault 尝试使用 Azure 函数在 Azure Key Vault 中创建秘密 - Trying to create secret in Azure Key Vault using Azure Functions Azure Databricks 自动化 databricks-cli 身份验证问题 aad 令牌 - Azure Databricks automation databricks-cli authentication issue aad token Azure 从密钥库中检索机密 - Azure Retrieve Secret from key vault 使用 go azure sdk 处理禁用的 azure 密钥保管库机密? - Handling a disabled azure key vault secret using go azure sdk? 通过参数文件将 Azure Key Vault secret 读入 ARM 模板 - Reading Azure Key Vault secret into ARM template via parameter file Azure Python SDK 检索存储帐户的 Key Vault 秘密 - Azure Python SDK retrieve Key Vault secret for storage account 如何使用 Azure 密钥保管库将 SQL 服务器的连接字符串作为秘密存储在 Azure 数据工厂中 - How to use Azure key vault for storing connection string of SQL Server as secret in Azure Data Factory 如何使用 powerShell 在 Azure 密钥库机密上存储 json 文件内容(密钥)? - How to store json file content(Secret Key) on Azure key-vault secrets, using powerShell? Azure 应用程序配置抛出异常,并且当禁用的 Key Vault 机密作为 KV 参考时不加载配置 - Azure app configuration throws exception & does not load the configuration when a disabled key vault secret is present as KV reference
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM