本文提供为 Azure Database for PostgreSQL 灵活服务器启用或禁用系统分配的托管标识的分步说明。
针对现有服务器的启用步骤
使用 Azure 门户:
选择您的“Azure Database for PostgreSQL”灵活服务器。
在资源菜单中的 “安全 ”部分下,选择“ 标识”。
在“系统分配的托管标识”部分,选择“启用”。
选择“保存”。
如果服务器已将数据加密配置为使用客户托管密钥,则启用服务器后,无法禁用服务器的系统分配托管标识。 因此,如果门户检测到此条件,它会要求你确认是否要启用系统分配的托管标识。
进程启动时,通知会通知你系统分配的托管标识正在启用。
该过程完成后,通知会通知你系统分配的托管标识已启用。
Important
Azure CLI尚不支持通过Azure Database for PostgreSQL灵活服务器的特定模块或扩展来使用此功能。
使用 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 门户:
选择您的“Azure Database for PostgreSQL”灵活服务器。
在资源菜单中的 “安全 ”部分下,选择“ 标识”。
在“系统分配的托管标识”部分,选择“禁用”。
选择“保存”。
进程启动时,通知会通知你系统分配的托管标识正在禁用。
该过程完成后,通知会通知你系统分配的托管标识已禁用。
Important
Azure CLI尚不支持通过Azure Database for PostgreSQL灵活服务器的特定模块或扩展来使用此功能。
使用 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 server has User Assigned Managed identities assigned."
else
echo "System Assigned Managed identity is already disabled."
fi
显示当前分配的标识的步骤
使用 Azure 门户:
选择您的“Azure Database for PostgreSQL”灵活服务器。
在资源菜单中,选择“概述”。
选择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
相关内容