通过移动设备管理(MDM)部署编码代理

Important

此功能在 Beta 版中。 要使用它,工作区管理员必须从预览页面开启 Unity Gateway 托管配置。 请参阅 Manage Azure Databricks 预览版。

使用移动设备管理 (MDM) 和 Unity Gateway CLI 来分发团队的编码智能体配置。 管理员在工作区中发布配置,开发人员则使用他们熟悉的智能体,并采用已配置的模型、MCP 服务器和技能。

支持的 MDM 软件:

  • Jamf Pro(macOS),配备可直接使用的配置脚本

你的MDM软件会在每个设备上以管理员权限运行一个配置脚本。 脚本会先 ug安装 、 Databricks CLI 和编码代理,然后运行 ug configure 以应用您工作区的编码代理配置,适用于设备上的每个开发者。 开发者随后在没有管理员权限的情况下启动代理,并用自己的 Azure Databricks 账户登录。

Note

MDM 预配会配置 Claude Code 和 Codex,这些都具有计算机范围的设置。 它不会在 Visual Studio Code 中配置 GitHub Copilot CLI 或 GitHub Copilot。 开发人员使用 ug configure --agents copilot 自行设置 GitHub Copilot。

使用 MDM 推出

配置编码智能体

启用团队使用的代理,并在工作区发布配置。 参见 配置编程代理。

每个已启用的代理都需要在配置中至少有一个可供下一步的服务主体使用的模型。 例如,Claude Code 需要 Claude 模型。 ug configure 跳过没有模型的任何代理。

创建预配服务主体

MDM策略仅使用服务主体在运行时读取已发布的配置。 开发者以他们自己的身份进行认证。 脚本会暂时使用服务主体的凭据,以便其 ug 连接到工作区并下载编码代理配置。

  1. 在你的工作区中ug-mdm-provisioning,例如。

  2. 只启用 工作区访问权限 。 服务主体不需要其他权限。 请参阅管理权限。

  3. 授予服务主体对已发布配置中的模型、MCP服务器和技能的访问权限,包括所需的Unity Catalog权限。 参见 向模型、MCP 服务器和技能授予访问权限。

  4. 在服务主体的机密选项卡上,点击生成机密。 选择与你的轮换策略相匹配的生存期。 在 范围中,点击 其他 API,添加 ai-gateway 和 unity-catalog 范围,并将每个范围都设置为 读取。 请参阅 步骤 1:创建 OAuth 机密。

    生成 OAuth 密钥对话框,在“其他 API”下添加 ai-gateway 和 unity-catalog 范围,并将每个范围都设置为“读取”

  5. 复制客户端 ID 和密钥。 关闭对话框后,你无法再次查看密钥。

用你的MDM软件部署

Important

安装 ug 在设备上每个用户都能运行的共享位置,而不是在root用户的主目录里。 ug configure 会在整台计算机的智能体设置中记录 ug 的路径,每位开发人员的智能体会从该路径运行 ug 以进行身份验证。

Jamf Pro(macOS)

这些步骤介绍了如何使用 Jamf Pro 将 Claude Code 和 Codex 部署到 macOS 设备上。 每个设备需要:

  • 对工作区 URL 的网络访问权限、PyPI(pypi.org 和 github.com)、GitHub(nodejs.org 和 raw.githubusercontent.com)、registry.npmjs.org、astral.sh 和 files.pythonhosted.org。
  • Xcode 的命令行工具,或允许脚本使用 softwareupdate 安装这些工具的权限。 ug从GitHub安装,需要git。

添加脚本

  1. 在 Jamf Pro 中,前往 设置 > 计算机管理 > 脚本 > 新建,并将该脚本命名为 Unity Gateway provision。

    Jamf Pro 新脚本页面,在“通用”标签页上,显示名称为 Unity Gateway provision

  2. 在 脚本 标签页,粘贴以下脚本:

    查看配置脚本
    #!/bin/bash
    #
    # macOS MDM provisioning script, written for Jamf Pro policies: install
    # ug, the Databricks CLI, Claude Code and Codex machine-wide and run
    # `ug configure` as root, which installs the workspace policy at
    # /etc/unitygateway/managed-settings.json. It also adds `claude` and
    # `codex` aliases to /etc/zshrc and /etc/bashrc, so users launch with
    # `claude` or `codex` in a new terminal, with no sudo.
    #
    # Jamf parameters ($1-$3 are reserved by Jamf):
    #   $4  Databricks workspace URL, starting with https://
    #   $5  Service principal OAuth client id
    #   $6  Service principal OAuth client secret
    #
    # The token is used for this run only; developers sign in with their own
    # OAuth. Needs access to PyPI, GitHub, astral.sh, nodejs.org and npmjs.org.
    
    set -euo pipefail
    umask 022
    export HOME=/var/root
    export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
    WORKSPACE="${4%/}"
    PREFIX=/usr/local/unity-gateway
    NODE_VERSION=22.23.5
    NODE_SHA256=89fadefd7798158d8990ca9ed7dbb58f8ca7593adb92fe3da8a445db99415533
    UG_REPO=https://github.com/databricks/unity-gateway
    UV_URL=https://astral.sh/uv/install.sh
    CLI_URL=https://raw.githubusercontent.com
    CLI_URL="$CLI_URL/databricks/setup-cli/main/install.sh"
    CLT_MARKER=/tmp/.com.apple.dt.CommandLineTools
    CLT_MARKER="$CLT_MARKER.installondemand.in-progress"
    
    # ug must be in a shared path: the machine-wide agent settings
    # run it by absolute path for every user.
    export UV_TOOL_DIR="$PREFIX/tools"
    export UV_TOOL_BIN_DIR=/usr/local/bin
    export UV_PYTHON_INSTALL_DIR="$PREFIX/python"
    export UV_PYTHON_PREFERENCE=only-managed
    # ug's npm installer must put agents on every user's PATH, not in root's home.
    export npm_config_prefix=/usr/local
    mkdir -p /usr/local/bin
    
    # Get ug from git
    if ! xcode-select -p >/dev/null 2>&1; then
      touch "$CLT_MARKER"
      clt="$(softwareupdate -l 2>/dev/null \
        | sed -n 's/^\* Label: \(Command Line Tools.*\)$/\1/p' \
        | tail -n1)"
      softwareupdate -i "$clt"
      rm -f "$CLT_MARKER"
    fi
    
    if ! command -v uv >/dev/null; then
      curl -LsSf "$UV_URL" \
        | env UV_INSTALL_DIR=/usr/local/bin UV_NO_MODIFY_PATH=1 sh
    fi
    uv tool install --force "git+$UG_REPO"
    
    if [ ! -x /usr/local/bin/databricks ]; then
      curl -fsSL "$CLI_URL" | sh
    fi
    
    # ug configure installs missing agents with npm; provide a shared Node.js runtime.
    if ! command -v node >/dev/null || ! command -v npm >/dev/null; then
      tmp="$(mktemp -d)"
      trap 'rm -rf "$tmp"' EXIT
      package="node-v$NODE_VERSION.pkg"
      /usr/bin/curl -fsSL -o "$tmp/$package" \
        "https://nodejs.org/dist/v$NODE_VERSION/$package"
      printf '%s  %s\n' "$NODE_SHA256" "$tmp/$package" | /usr/bin/shasum -a 256 -c -
      /usr/sbin/installer -pkg "$tmp/$package" -target /
    fi
    
    # Get short lived credential; curl reads the client id and secret from
    # stdin (-K -) so they don't appear in its arguments.
    resp="$(printf 'user = "%s:%s"\n' "$5" "$6" \
      | curl -sS -K - \
          -d grant_type=client_credentials \
          --data-urlencode 'scope=ai-gateway:read unity-catalog:read' \
          "$WORKSPACE/oidc/v1/token")"
    if ! DATABRICKS_BEARER="$(printf '%s' "$resp" \
        | plutil -extract access_token raw -o - -)"; then
      echo "Token request to $WORKSPACE failed: $resp" >&2
      exit 1
    fi
    export DATABRICKS_BEARER
    
    /usr/local/bin/ug configure --global --mdm --workspace "$WORKSPACE" \
      --agents claude,codex </dev/null
    unset DATABRICKS_BEARER resp
    
    # Aliases for every user's interactive zsh and bash shells. The block is
    # rewritten on each run, which restores it if a macOS update resets
    # the file.
    for rc in /etc/zshrc /etc/bashrc; do
      [ -f "$rc" ] || continue
      sed -i '' '/^# BEGIN unity-gateway/,/^# END unity-gateway/d' "$rc"
      cat >>"$rc" <<'ALIASES'
    # BEGIN unity-gateway (managed by MDM)
    alias claude='UG_SKIP_OS_SETTINGS=1 ug claude'
    alias codex='UG_SKIP_OS_SETTINGS=1 ug codex'
    # END unity-gateway
    ALIASES
    done
    
  3. 在 选项 标签页中,标记 参数4Workspace URL、 参数5Client ID和 参数6Client secret。

    Jamf Pro 脚本选项选项卡中,参数 4 标记为 Workspace URL,参数 5 标记为客户端 ID,参数 6 标记为客户端密钥

  4. 单击“ 保存”。

脚本会在每次运行时重新安装 ug,并且仅在缺失时才安装 Databricks CLI。 如果缺少 Node.js 或 npm,脚本会在检查其固定的 SHA-256 校验码后安装官方 Node.js 22.23.5 包。 ug configure 然后在共享 PATH 上重复使用现有代理,或通过 npm 使用 Unity Gateway 内置安装程序安装 Claude Code 和 Codex。 工作区未启用的代理不会被安装。 脚本不会以其他方式更新 Node.js、代理或 CLI;为了使它们保持最新状态,请修改脚本,使其与你在设备上更新软件的方式相匹配。

配置了早期版本脚本的 Mac 会保留其原生代理安装;运行新脚本并不等于迁移到 npm。 要将这些 Mac 迁移到 npm,请使用软件管理程序删除旧的原生安装,然后再次运行该策略。

创建策略

  1. 转到计算机 > 策略 > 新建。

  2. 在常规中,将触发器设置为定期签入,并将执行频率设置为每天一次。 每个设备每天运行ug configure,该程序会应用你在工作区发布的配置更新。

    选中“定期签入”触发器并将执行频率设置为“每日一次”的 Jamf Pro 新策略一般选项

  3. 在脚本中,添加Unity Gateway provision,并将优先级设为之后。 输入参数:

    Parameter Value
    4(工作区网址) 你的工作区 URL,以 https://. 开头。
    5(客户端ID) 服务主体的客户端 ID。
    6(客户端密钥) 服务主体的机密。

    Jamf Pro 策略脚本选项显示 Unity Gateway 配置脚本,优先级设置为 After,并占位符显示工作区 URL、客户端 ID 和客户端密钥

  4. 在范围中,选择作为目标的设备。 先从一小组试点设备开始。

  5. 单击“ 保存”。 Jamf Pro 在每个目标设备下一次签到时执行该策略。

告诉你的开发人员

策略在设备上运行后,开发人员打开一个新终端并按常规运行claudecodex。 第一次启动会打开一个浏览器,开发者登录 Azure Databricks。 这样,编码智能体活动就会归属于各个开发人员,而不是服务主体。

推出 Claude 桌面版

同一 ug configure 运行还为设备上的每个用户配置 Claude 桌面应用。 要支持Claude桌面,建议在脚本运行 ug configure前先在配置脚本中安装它。 上面的 Jamf Pro 脚本不能安装 Claude 桌面版。

用户首次打开 Claude 桌面时,会用自己的 Azure Databricks 账户登录。 用户还可以 导入 claude.ai 项目和聊天内容。

验证推出

在试验设备上,用开发者的操作系统账户登录并检查:

  • 智能体使用配置的模型打开并响应。
  • 配置好的MCP服务器和技能已可用,开发者可以使用它们。
  • 请求会出现在 Unity Gateway 使用跟踪中,启用追踪时会显示跟踪。 参见 监控编码代理活动。

在更改预配脚本或已发布的配置后重复这些检查。

维护凭证和配置

要轮换服务主体的机密:

  1. 为服务主体生成新机密。
  2. 更新你的 MDM 策略中的机密。
  3. 策略在你的设备上运行后,删除旧的机密。

要更新配置,请在工作区发布更改。 设备会在策略下次运行时应用它们。 参见 同步配置更新。

Troubleshooting

错误 Cause
Token request to ... failed: {"error":"invalid_client"...} MDM策略中的客户端 ID 或客户端密钥错误,或者客户端密钥已过期。
Token request ... failed: ... Scopes ... are not assigned to the client 该机密不具备 ai-gateway:read 和 unity-catalog:read 范围。
None of the coding agents enabled by your workspace configuration are available 没有已启用的代理程序拥有服务主体可以使用的模型,例如未配置 Claude 模型的 Claude Code。