You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Databricks资产包作业Git认证问题:GIT源无法使用AAD鉴权

问题

通过Azure DevOps管道使用databricks bundle deploy -t <target_env>部署Databricks资产包成功,但作业运行时无法向Azure Git完成认证拉取代码。具体情况如下:

  • 当notebook_task的source设为GIT(Git引用方式)时,无法配置Microsoft Entra ID认证
  • 尝试将git_provider设为azureDevOpsServicesAad,但Azure DevOps仅支持有效值azureDevOpsServices
  • 作业已配置为拥有Azure Git仓库读写权限的服务主体运行
  • 已知可通过服务主体访问令牌调用Databricks REST API创建Git凭证,但资产包YAML的git_source部分无git_credential_id属性可指定凭证ID

作业YAML配置如下:

resources:
  jobs:
    my_job_name:
      name: my_job_name

      run_as:
        service_principal_name: ${var.run_as_user}

      permissions:
        - group_name: ${var.workspace_user_group}
          level: CAN_MANAGE_RUN
        - group_name: ${var.workspace_admin_group}
          level: CAN_MANAGE

      deployment_config:
        no_package: true

      git_source:
        git_provider: azureDevOpsServices
        git_url: https://dev.azure.com/<org-name>/<proj-name>/_git/${var.source_repo_name}
        git_branch: ${var.source_branch_name}

      max_concurrent_runs: 10
      tasks:
        - task_key: Run_All_Notebooks
          notebook_task:
            notebook_path: ${bundle.name}/_run_all_notebooks
            source: GIT
          existing_cluster_id: ${var.shared_autoscaling_cluster_id}

运行作业时报错:

Task Run_All_Notebooks failed with message: Failed to checkout Git repository: PERMISSION_DENIED: Encountered an error with your Azure Active Directory credentials. Please try logging out of Azure Active Directory and logging back in. This caused all downstream tasks to get skipped.

请问是否可以为git_provider显式设置AAD认证,或为作业运行的服务主体指定Git凭证?

解决方案

方法1:通过Databricks REST API关联Git凭证与服务主体

虽然资产包YAML的git_source不支持直接指定git_credential_id,但可通过以下步骤完成凭证关联:

  1. 创建Git凭证:调用Databricks REST API的/api/2.0/git/credentials接口,使用服务主体的访问令牌创建Azure DevOps类型的Git凭证,传入服务主体的PAT或AAD令牌
  2. 更新作业配置:调用/api/2.1/jobs/update接口,在作业的git_source中添加git_credential_id字段,关联刚创建的凭证ID

方法2:将服务主体PAT嵌入Git URL

把服务主体的Azure DevOps个人访问令牌(PAT)直接嵌入Git URL,格式如下:

git_source:
  git_provider: azureDevOpsServices
  git_url: https://<service-principal-id>:<pat-token>@dev.azure.com/<org-name>/<proj-name>/_git/${var.source_repo_name}
  git_branch: ${var.source_branch_name}

注意:需确保PAT拥有仓库读取权限,且通过管道安全变量管理PAT,禁止硬编码。

方法3:配置集群级Git凭证

如果作业使用现有集群,可在集群的Git集成设置中配置服务主体的凭证,集群上运行的所有Git源任务会自动使用该凭证:

  • 进入Databricks UI的集群配置页面
  • 找到「Git integration」区域,添加Azure DevOps的Git凭证并关联服务主体

关于git_provider的AAD认证设置

目前Databricks资产包的git_provider仅支持azureDevOpsServices作为有效值,无法显式指定AAD认证模式。但通过上述方法,服务主体仍可通过PAT或API创建的凭证完成认证。

内容的提问来源于stack exchange,提问作者Emil

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 07:38:34