你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
本文提供了在 Azure Red Hat OpenShift 群集(ARO)中轮换服务主体凭据的必要详细信息。
在您开始之前
本文假设有一个现有 ARO 群集,其中应用了最新更新。
轮换 ARO 群集中的服务主体凭据的最低 Azure CLI 要求为 2.24.0。
若要检查 Azure CLI 的版本,请运行:
# Azure CLI version
az --version
若要安装或升级 Azure CLI,请按照 安装 Azure CLI作。
以下说明使用 bash 语法。
服务主体账号凭据轮换
重要
服务主体凭据轮换可能需要 2 小时以上,具体取决于群集状态。
服务主体凭据轮换有两种方法:
自动服务主体凭据轮换
重要
自动化服务主体凭据轮换要求使用 Azure CLI 2.24.0 或更高版本创建 ARO 群集。
自动服务主体凭据轮换将检查服务主体是否存在并轮换或创建新的服务主体。
使用以下命令自动轮换服务主体凭据:
# Automatically rotate service principal credentials
az aro update --refresh-credentials --name MyManagedCluster --resource-group MyResourceGroup
用户提供的客户端 ID 和客户端机密服务主身份凭据轮换
按照以下说明,使用用户提供的客户端 ID 和客户端机密手动轮换服务主体凭据:
检索服务主体 clientId(--client-id
)并将其设置为 SP_ID
环境变量。
# Retrieve the service principal clientId
SP_ID=$(az aro show --name MyManagedCluster --resource-group MyResourceGroup \
--query servicePrincipalProfile.clientId -o tsv)
使用SP_ID
上述变量为服务主体生成新的安全机密(--client-secret
)。 将新的安全机密存储为 SP_SECRET
环境变量。
# Generate a new secure secret for the service principal
SP_SECRET=$(az ad sp credential reset --id $SP_ID --query password -o tsv)
使用上述环境变量轮换服务主体凭据。
# Rotate service principal credentials
az aro update --client-id $SP_ID --client-secret $SP_SECRET \
--name MyManagedCluster --resource-group MyResourceGroup
故障排除
服务主体到期日期
服务主体凭据的到期日期为一年,应在给定的时间范围内轮换。
如果过期日期已经过期,可能发生以下错误:
Failed to refresh the Token for request to MyResourceGroup StatusCode=401
Original Error: Request failed. Status Code = '401'.
[with]
Response body: {"error":"invalid_client","error_description": The provided client secret keys are expired.
[or]
Response body: {"error":"invalid_client","error_description": Invalid client secret is provided.
若要检查服务主体凭据的到期日期,请运行以下命令:
# Service principal expiry in ISO 8601 UTC format
SP_ID=$(az aro show --name MyManagedCluster --resource-group MyResourceGroup \
--query servicePrincipalProfile.clientId -o tsv)
az ad app credential list --id $SP_ID --query "[].endDateTime" -o tsv
如果服务主体凭据已过期,请使用两种凭据轮换方法之一进行更新。
群集 AAD 应用程序包含具有空说明的客户端密钥
使用 自动化服务主体凭据轮换 时,会发生以下错误:
$ az aro update --refresh-credentials --name MyManagedCluster --resource-group MyResourceGroup
Cluster AAD application contains a client secret with an empty description.
Please either manually remove the existing client secret and run `az aro update --refresh-credentials`,
or manually create a new client secret and run `az aro update --client-secret <ClientSecret>`.
尚未使用 Azure CLI 2.24.0 或更高版本创建群集。 请改用 用户提供的客户端 ID 和客户端机密服务主体凭据轮换 方法。
Azure CLI ARO 更新帮助
有关详细信息,请参阅 Azure CLI ARO 更新帮助命令:
# Azure CLI ARO update help
az aro update -h