本文提供为 Azure Database for PostgreSQL 灵活服务器启用或禁用系统分配的托管标识的分步说明。
为现有服务器启用的步骤
使用 Azure 门户:
如果未打开服务器,请在门户中找到服务器。 一种方法是在搜索栏中键入服务器的名称。 显示具有匹配名称的资源时,请选择该资源。
在资源菜单中的 “安全性”下,选择“ 标识”。
在 “系统分配的托管标识 ”部分中,选择“ 打开”。
选择“保存”。
如果服务器的数据加密配置为使用客户托管密钥,则启用服务器后,不支持禁用服务器的系统分配托管标识。 因此,如果检测到该条件,系统会请求确认是否要启用系统分配的托管标识。
该过程完成后,通知会通知你系统分配的托管标识已启用。
az postgres flexible-server update 命令不提供内置支持来启用和禁用系统分配的托管标识。 解决方法是,可以使用 az rest 命令直接调用 服务器 - 更新 REST API。
# Enable system assigned managed identity
subscriptionId=<subscription-id>
resourceGroup=<resource-group>
server=<server>
result=$(az postgres flexible-server show --resource-group $resourceGroup --name $server --query "identity.type" --output tsv)
if [ -z "$result" ]; then
az rest --method patch --url https://management.chinacloudapi.cn/subscriptions/$subscriptionId/resourceGroups/$resourceGroup/providers/Microsoft.DBforPostgreSQL/flexibleServers/$server?api-version=2024-08-01 --body '{"identity":{"type":"SystemAssigned"}}'
elif [ "$result" == "UserAssigned" ]; then
az rest --method patch --url https://management.chinacloudapi.cn/subscriptions/$subscriptionId/resourceGroups/$resourceGroup/providers/Microsoft.DBforPostgreSQL/flexibleServers/$server?api-version=2024-08-01 --body '{"identity":{"type":"SystemAssigned,UserAssigned"}}'
else
echo "System Assigned Managed identity is already enabled."
fi
为现有服务器禁用的步骤
使用 Azure 门户:
如果未打开服务器,请在门户中找到服务器。 一种方法是在搜索栏中键入服务器的名称。 显示具有匹配名称的资源时,请选择该资源。
在资源菜单中的 “安全性”下,选择“ 标识”。
在 “系统分配的托管标识 ”部分中,选择“ 关闭”。
选择“保存”。
该过程完成后,通知会通知你系统分配的托管标识已禁用。
az postgres flexible-server update 命令不提供内置支持来启用和禁用系统分配的托管标识。 解决方法是,可以使用 az rest 命令直接调用 服务器 - 更新 REST API。
# Disable system assigned managed identity
subscriptionId=<subscription-id>
resourceGroup=<resource-group>
server=<server>
result=$(az postgres flexible-server show --resource-group $resourceGroup --name $server --query "identity.type" --output tsv)
if [ "$result" == "SystemAssigned" ]; then
az rest --method patch --url https://management.chinacloudapi.cn/subscriptions/$subscriptionId/resourceGroups/$resourceGroup/providers/Microsoft.DBforPostgreSQL/flexibleServers/$server?api-version=2024-08-01 --body '{"identity":{"type":"None"}}'
elif [ "$result" == "SystemAssigned,UserAssigned" ]; then
echo "System Assigned Managed identity cannot be disabled as the instance has User Assigned Managed identities assigned."
else
echo "System Assigned Managed identity is already disabled."
fi
显示当前分配的步骤
使用 Azure 门户:
如果未打开服务器,请在门户中找到服务器。 一种方法是在搜索栏中键入服务器的名称。 显示具有匹配名称的资源时,请选择该资源。
在资源菜单中,选择“概述”
选择 JSON 视图。
在打开的资源 JSON 面板中,找到标识属性,并在其中找到系统分配的托管标识的 principalId 和 tenantId。
# Show the system assigned managed identity
resourceGroup=<resource-group>
server=<server>
az postgres flexible-server identity list \
--resource-group $resourceGroup \
--server-name $server \
--query "{principalId:principalId, tenantId:tenantId}" \
--output table
在 Microsoft Entra ID 中验证的步骤
使用 Azure 门户:
如果尚未打开,请在门户中找到 企业应用程序 服务。 执行此作的一种方法是在搜索栏中键入其名称。 显示具有匹配名称的服务时,请选择它。
选择 应用程序类型 == 托管标识。
按 应用程序名称或对象 ID 文本框在“搜索 ”中提供 Azure Database for PostgreSQL 灵活服务器实例的名称。
# Verify the system assigned managed identity
server=<server>
az ad sp list --display-name $server
相关内容