使用受信任的访问获取 Azure Kubernetes 服务中 Azure 资源的安全访问(预览版)

许多与 Azure Kubernetes 服务 (AKS) 集成的 Azure 服务都需要访问 Kubernetes API 服务器。 若要避免授予这些服务管理员访问权限或将 AKS 群集公开供网络访问,可以使用 AKS 受信任访问功能。

此功能允许服务使用 Azure 后端安全地访问 AKS API 服务器,而无需专用终结点。 此功能可以使用系统分配的托管标识对要用于 AKS 群集的托管服务和应用程序进行身份验证,而不是依赖于具有 Microsoft Entra 权限的标识。

本文介绍如何使用受信任的访问在 AKS 中获取 Azure 服务对 Kubernetes API 服务器的安全访问。

注意

受信任的访问 API 已正式发布。 我们为 Azure CLI 提供正式版 (GA) 支持,但它仍处于预览状态,需要使用 aks-preview 扩展。

受信任访问功能概述

受信任访问解决了以下情况:

  • 如果已设置或位于专用群集中,则除非实现专用终结点访问模型,否则 Azure 服务可能无法访问 Kubernetes API 服务器。

  • 授予 Azure 服务管理员对 Kubernetes API 的访问权限并不遵循最低特权访问最佳做法,并可能导致特权升级或凭据泄露风险。 例如,你可能必须实现高特权服务到服务权限,并且它们在审核评审中并不理想。

可以使用受信任的访问显式同意系统分配的允许资源的托管标识,以使用名为 角色绑定的 Azure 资源访问 AKS 群集。 Azure 资源通过系统分配的托管标识身份验证通过 AKS 区域网关访问 AKS 群集。 通过名为角色的 Azure 资源分配相应的 Kubernetes 权限。 通过受信任的访问,可以访问具有不同配置的 AKS 群集,包括但不限于专用群集、本地帐户已关闭的群集、Microsoft Entra 群集和授权 IP 范围群集

先决条件

创建 AKS 群集

在要访问群集的 Azure 资源所在的同一订阅中,创建 AKS 群集

选择所需的受信任访问角色

选择的角色取决于要访问 AKS 群集的 Azure 服务。 Azure 服务可帮助创建角色和角色绑定,以生成从 Azure 服务到 AKS 的连接。

创建受信任的访问角色绑定

确认要使用的角色后,使用 Azure CLI 在 AKS 群集中创建受信任的访问角色绑定。 角色绑定将所选角色与 Azure 服务相关联。

# Create a Trusted Access role binding in an AKS cluster

az aks trustedaccess rolebinding create  --resource-group <AKS resource group> --cluster-name <AKS cluster name> -n <role binding name> -s <connected service resource ID> --roles <roleName1, roleName2>

下面是一个示例:

# Sample command

az aks trustedaccess rolebinding create \
-g myResourceGroup \
--cluster-name myAKSCluster -n test-binding \
--source-resource-id /subscriptions/000-000-000-000-000/resourceGroups/myResourceGroup/providers/Microsoft.MachineLearningServices/workspaces/MyMachineLearning \
--roles Microsoft.Compute/virtualMachineScaleSets/test-node-reader,Microsoft.Compute/virtualMachineScaleSets/test-admin

更新现有的受信任访问角色绑定

对于具有关联源服务的现有角色绑定,可以使用新角色更新角色绑定。

注意

加载项管理器每隔五分钟更新一次群集,因此新角色绑定可能需要长达五分钟才能生效。 在新的角色绑定生效之前,现有角色绑定仍然有效。

可使用 az aks trusted access rolebinding list --name <role binding name> --resource-group <resource group> 检查当前角色绑定。

# Update the RoleBinding command

az aks trustedaccess rolebinding update --resource-group <AKS resource group> --cluster-name <AKS cluster name> -n <existing role binding name>  --roles <newRoleName1, newRoleName2>

下面是一个示例:

# Update the RoleBinding command with sample resource group, cluster, and roles

az aks trustedaccess rolebinding update \
--resource-group myResourceGroup \
--cluster-name myAKSCluster -n test-binding \
--roles Microsoft.Compute/virtualMachineScaleSets/test-node-reader,Microsoft.Compute/virtualMachineScaleSets/test-admin

显示受信任的访问角色绑定

使用 az aks trustedaccess rolebinding show 命令显示特定的受信任访问角色绑定:

az aks trustedaccess rolebinding show --name <role binding name> --resource-group <AKS resource group> --cluster-name <AKS cluster name>

列出群集的所有受信任访问角色绑定

使用 az aks trustedaccess rolebinding list 命令列出群集的所有受信任访问角色绑定:

az aks trustedaccess rolebinding list --resource-group <AKS resource group> --cluster-name <AKS cluster name>

删除群集的受信任访问角色绑定

警告

删除现有的受信任访问角色绑定会断开 Azure 服务与 AKS 群集的连接。

使用 az aks trustedaccess rolebinding delete 命令删除现有的受信任访问角色绑定:

az aks trustedaccess rolebinding delete --name <role binding name> --resource-group <AKS resource group> --cluster-name <AKS cluster name>