在 Azure Foundry 部署 Claude Code 的企业级工程指南
An engineering guide to Claude Code on Microsoft Foundry with Azure API Management
给企业做 AI 落地基建的同学参考,这篇把 Claude Code 接入 Azure 管控的详细架构图和分步部署脚本都给了,直接能照着搭。
How do you give developers Claude Code while keeping identity, model access, budgets and private networking under enterprise control? I built Claude Code on Foundry (CCOF) to address that challenge, and I have taken this implementation live in multiple enterprises using this architecture.
如何在让开发者使用 Claude Code 的同时,由企业掌控身份、模型访问权限、预算和私有网络?我构建了基于 Foundry 的 Claude Code(CCOF)以应对这一挑战,并已在多家企业中使用该架构将其投入生产环境。
This guide explains what developers and administrators get, how the components fit together, and how to deploy and test one user before expanding. CCOF is my implementation, available in my GitHub repository; it is not a Microsoft product.
本指南说明了开发者和管理员能获得什么、各组件如何协同工作,以及如何先部署并测试单个用户再逐步扩展。CCOF 是我的实现方案,托管在我的 GitHub 仓库中;它并非微软产品。
The screenshots below are from recorded lab runs, not customer production environments. Names and identifiers have been replaced or masked. Enterprise deployment experience does not establish a verified capacity for every workload.
以下截图来自录制的实验室运行过程,而非客户的生产环境。名称和标识符已替换或遮蔽。企业部署经验并不能证明对每种工作负载都具备经过验证的能力。
1. What developers and administrators get
1. 开发者和管理员能获得什么
| For a developer | For an administrator |
|---|---|
| Claude Code with an organisation-approved model | Onboard an existing Entra security group |
| Microsoft Entra sign-in, without a shared Foundry key | Set models, per-person budgets and token limits |
| Claude Code CLI and the Claude Code VS Code extension | Give each group a cost code and tag people for chargeback |
| Their own CCOF budget through the installed usage skill | View spend by group, developer and model |
| An optional budget status line | Export usage for reporting and use an Azure Monitor workbook |
| A supported, build-checked Claude Desktop configuration on Windows | Keep backends private and reuse an existing APIM where appropriate |
| 对于开发者 | 对于管理员 |
|---|---|
| 带有组织批准模型的 Claude Code | 加入现有的 Entra 安全组 |
| Microsoft Entra 登录,无需共享 Foundry 密钥 | 设置模型、每人预算和令牌限制 |
| Claude Code CLI 和 Claude Code VS Code 扩展 | 为每个组分配成本代码并对人员进行计费标记 |
| 通过安装的 usage skill 获得各自的 CCOF 预算 | 按组、开发人员和模型查看支出 |
| 可选的预算状态行 | 导出用量用于报告并使用 Azure Monitor workbook |
| 在 Windows 上受支持且经过构建检查的 Claude Desktop 配置 | 保持后端私有并在适当时复用现有的 APIM |
Access comes from group membership. A client configuration file does not grant access by itself.
访问权限来自组成员资格。客户端配置文件本身并不授予访问权限。
Figure 1. The group-only console in a live lab. Group identifiers and resource names are replacements; this is not a customer directory.
图 1. 实时实验室中的仅群组控制台。群组标识符和资源名称均为替换值;这不是客户目录。
2. Architecture: one gateway, separate responsibilities
2. 架构:一个网关,职责分离
Figure 2. The supplied design: a single-region CCOF stack with zone-redundant APIM and Functions, ZRS storage, and primary/standby Foundry accounts. Cosmos is non-zonal in both regions in this illustration; enabling its zone option is a separate capacity and deployment decision.
图 2. 提供的架构设计:单区域 CCOF 堆栈,包含区域冗余的 APIM 和 Functions、ZRS 存储以及主/备用 Foundry 账户。在此示例中,两个区域的 Cosmos 均非区域冗余;启用其区域选项是单独的能力和部署决策。
| Component | Its job |
|---|---|
| API Management | Validate the caller's token, enforce admission and token limits, route to the approved Foundry backend |
| Resolver Function App | Read the caller's entitlement and budget; return a group, exact model permissions and backend ID |
| Sync Function App | Read direct Entra group members and update the Cosmos entitlement projection |
| Reconciler Function App | Read usage on a schedule and write budget state |
| Admin Function App | Group onboarding, configuration and reporting |
| Cosmos DB | Store groups, entitlements, budget state and optional daily chargeback history |
| Log Analytics and Application Insights | Request/accounting telemetry and operational logs |
| Storage | Function packages and optional gateway log archive |
| Microsoft Foundry | Host the Claude deployments |
| 组件 | 职责 |
|---|---|
| API Management(API 管理) | 验证调用者的令牌,执行准入控制及令牌限制,路由至已批准的 Foundry 后端 |
| Resolver Function App(解析器函数应用) | 读取调用者的权限和预算;返回组、精确的模型权限及后端 ID |
| Sync Function App(同步函数应用) | 读取 Entra 组的直接成员并更新 Cosmos 权限投影 |
| Reconciler Function App(对账函数应用) | 按计划读取使用情况并写入预算状态 |
| Admin Function App(管理函数应用) | 组入职、配置和报告 |
| Cosmos DB | 存储组、权限、预算状态及可选的每日费用分摊历史记录 |
| Log Analytics and Application Insights(日志分析和应用洞察) | 请求/计费遥测数据和操作日志 |
| Storage(存储) | 函数包及可选的网关日志归档 |
| Microsoft Foundry | 托管 Claude 部署 |
The resolver is not a developer endpoint. It accepts the gateway's managed identity. APIM also uses its managed identity to call Foundry, with the account-scoped Cognitive Services User role (the current Azure built-in RBAC role name used by this implementation).
解析器并非开发者端点。它接受网关的托管标识。APIM 也使用其托管标识调用 Foundry,并具备账户范围的 Cognitive Services User 角色(此实现所使用的当前 Azure 内置 RBAC 角色名称)。
The normal request path is:
正常请求路径如下:
- The user signs in to Entra. A helper gives Claude Code a short-lived token for the gateway.
- APIM validates tenant, audience, client application and delegated scope.
- On a cache miss, APIM calls the resolver to determine the authorised group and models.
- APIM applies the configured person/group limits and forwards to Foundry.
- Usage telemetry carries the person, group, model and cost attribution. Background reconciliation updates budgets.
- 用户登录 Entra。辅助工具为 Claude Code 提供网关的短期令牌。
- APIM 验证租户、受众、客户端应用程序及委派范围。
- 在缓存未命中时,APIM 调用解析器以确定授权的组和模型。
- APIM 应用配置的人员/组限制,并转发至 Foundry。
- 使用遥测数据包含人员、组、模型和成本归属信息。后台对账过程会更新预算。
The baseline allow cache is 120 seconds; it is configurable. A person in multiple groups can select a group by its Object ID in x-ccof-project. Without a selector, the configured selection rule chooses the group with the most recorded spend this month, then the lower priority number.
基础允许缓存时间为 120 秒;该值可配置。若某人属于多个组,可通过 x-ccof-project 中的 Object ID 选择组。若无选择器,则根据配置的规则选择本月记录支出最多的组,其次选择优先级编号较低的组。
See the architecture and trust boundaries.
请参阅架构和信任边界。
3. Prepare the Azure and Entra prerequisites
3. 准备 Azure 和 Entra 先决条件
Before starting, the platform, network and Entra owners agree on:
开始前,平台、网络和 Entra 负责人需就以下内容达成一致:
- The Azure subscription, resource group and regions.
- APIM tier, network access and capacity. A private backend needs a reachable private network path.
- Primary and standby Foundry deployments, exact deployment names and inference geography.
- Cosmos zone capacity where requested, plus throughput for the pilot.
- Network subnet delegation, DNS, routing and outbound access.
- Existing Entra group Object IDs, test members and budgets.
- Who can create Azure role assignments and grant Microsoft Graph application permissions.
- Azure 订阅、资源组和区域。
- APIM 层级、网络访问和容量。私有后端需要可达的专用网络路径。
- 主用和备用 Foundry 部署、确切的部署名称及推理地理区域。
- 按需的 Cosmos 区域容量,以及试点阶段的吞吐量。
- 网络子网委托、DNS、路由和出站访问。
- 现有的 Entra 组 Object ID、测试成员和预算。
- 谁可以创建 Azure 角色分配并授予 Microsoft Graph 应用程序权限。
For user-only automatic sync, the sync identity uses GroupMember.Read.All; User.Read.All lets it read users' enabled/disabled state. These are Microsoft Graph application permissions on the Function App's managed identity, not permissions given to developers. Service-principal membership needs separate permission consideration.
对于仅面向用户的自动同步,同步身份使用 GroupMember.Read.All;User.Read.All 允许其读取用户的启用/禁用状态。这些是函数应用托管标识上的 Microsoft Graph 应用程序权限,而非授予开发者的权限。服务主体成员资格需要单独的权限考量。
Admin group search and names need their own approved Graph read permissions. New managed-identity grants may take hours to appear in cached tokens. Grant them before the rollout window where possible.
管理员组搜索和名称需要其各自批准的 Graph 读取权限。新的托管标识授权可能需要数小时才能出现在缓存令牌中。尽可能在部署窗口之前授予这些权限。
Private IPs belong in DNS, not in the backend URL
私有 IP 应位于 DNS 中,而非后端 URL 中
Use the account's hostname:
使用该账户的主机名:
https://<foundry-account>.services.ai.azure.com/anthropicPrivate DNS resolves it to the private endpoint IP. Replacing the hostname with https://10.x.x.x breaks hostname-based TLS validation; CCOF also requires the expected standby hostname.
私有 DNS 将其解析为私有终结点 IP。将主机名替换为 https://10.x.x.x 会破坏基于主机的 TLS 验证;CCOF 还需要预期的备用主机名。
Private DNS zones are global. Another Foundry region does not need another set of same-named zones. What matters is which zone the APIM network resolves and whether it can reach the returned IP. Peering alone does not provide DNS forwarding.
私有 DNS 区域是全局的。另一个 Foundry 区域不需要另一组同名区域。重要的是 APIM 网络解析了哪个区域,以及它是否能访问返回的 IP。对等连接本身不提供 DNS 转发。
Figure 3. A cropped Azure portal capture from an earlier East US 2 lab. Resource names and subscription details are replaced. The account, SQL private endpoint and NIC are separate resources; the service itself does not live inside the endpoint subnet.
图 3. 来自早期东美国 2 实验室的裁剪版 Azure 门户截图。资源名称和订阅详细信息已替换。账户、SQL 私有终结点和 NIC 是单独的资源;服务本身并不驻留在终结点子网内。
Figure 4. An earlier lab used public inbound APIM access and enabled outbound VNet integration. A production gateway can instead have private inbound access; that is a separate owner decision, not what this screenshot proves.
图 4. 早期的实验室使用了公共入站 APIM 访问并启用了出站 VNet 集成。生产网关可以改为具有私有入站访问权限;这是单独的负责人决策,并非此截图所证明的内容。
If APIM public access is disabled, both the acceptance-test machine and developer machines need the corporate network, VPN or VDI path and private DNS. An operator may deploy through ARM from the internet but still be unable to call the private gateway.
如果禁用了 APIM 公共访问,则验收测试机器和开发人员机器都需要企业网络、VPN 或 VDI 路径以及私有 DNS。操作员可能通过 ARM 从互联网进行部署,但仍无法调用私有网关。
4. Deploy in stages
4. 分阶段部署
The deployment-day runbook gives the sequence and expected output. The configuration guide explains each choice.
部署日运行手册提供了序列和预期输出。配置指南解释了每个选择。
| Stage | Work |
|---|---|
| 0 | Read-only preflight: subscription, providers, HA support, deployments and existing APIM checks |
| 1 | Create resources and verify their settings |
| 2 | Create the Cosmos database and containers |
| 3 | Assign and verify runtime Azure/Cosmos roles |
| 4 | Create or reuse Entra registrations and groups |
| 5 | Apply app settings, APIM policy/backends and telemetry |
| 6 | Provision or verify the configured private network paths |
| 7 | Publish code, seed data, load membership and export the client configuration |
| 8 | Test authentication, allowed/denied models and accounting |
| 阶段 | 工作 |
|---|---|
| 0 | 只读预检:订阅、提供程序、高可用性支持、部署和现有 APIM 检查 |
| 1 | 创建资源并验证其设置 |
| 2 | 创建 Cosmos 数据库和容器 |
| 3 | 分配并验证运行时 Azure/Cosmos 角色 |
| 4 | 创建或重用 Entra 注册和组 |
| 5 | 应用应用设置、APIM 策略/后端和遥测 |
| 6 | 配置或验证配置的私有网络路径 |
| 7 | 发布代码、种子数据、加载成员资格并导出客户端配置 |
| 8 | 测试身份验证、允许/拒绝模型和计费 |
From a checkout, in PowerShell 7:
从签出状态开始,在 PowerShell 7 中:
$cfg = Join-Path $HOME 'ccof-private/staged.config.json'
$run = Join-Path (Get-Location) 'infra/staged/Invoke-StagedDeployment.ps1'
pwsh -File $run -Stage 0 -ConfigPath $cfg
# Preview, review, then apply one stage at a time.
pwsh -File $run -Stage 1 -ConfigPath $cfg
pwsh -File $run -Stage 1 -ConfigPath $cfg -ApplyContinue through Stage 8 only after the preceding stage succeeds. Keep the configuration and its saved state together. Stage 1 is create-only: decide HA options before it succeeds.
仅在 preceding stage 成功之后继续执行 Stage 8。将配置及其保存的状态保持在一起。Stage 1 为仅创建阶段:在其成功之前确定高可用性(HA)选项。
An existing APIM keeps its networking, units and existing APIs. Choose unused CCOF names, for example apiId: ccof-claude-messages, apiPath: ccof and backend ID ccof-foundry. Its global policy still applies, and service-level diagnostics may include its other APIs. Review that scope and cost with the owner.
现有的 APIM 保留其网络、单元和现有 API。选择未使用的 CCOF 名称,例如 apiId: ccof-claude-messages,apiPath: ccof 以及后端 ID ccof-foundry。其全局策略仍然适用,且服务级诊断可能包含其其他 API。请与所有者一起审查该范围和成本。
更进一步:量化金融体系
看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力