JSON 值无法转换为 System.Nullable`1[Microsoft.ContainerApps.ApiResources.Models.UnauthenticatedClientAction

The JSON value could not be converted to System.Nullable`1[Microsoft.ContainerApps.ApiResources.Models.UnauthenticatedClientAction

我有一个 Azure 容器应用程序,我想使用 Azure CLI 启用身份验证:
az containerapp auth update

resourceGroup='lorem'
appName='ipsum'
az containerapp auth update --resource-group $resourceGroup --name $appName --enabled true --unauthenticated-client-action RejectWith401

这会导致以下错误:

Bad Request({"type":"https://tools.ietf.org/html/rfc7231#section-6.5.1","title":"One or more validation errors occurred.","status":400,"traceId":"00-13a7f69e4ce3b84f82e3b7d2c0425143-5ec6db570ab2989b-01","errors":{"$.properties.globalValidation.unauthenticatedClientAction":["The JSON value could not be converted to System.Nullable`1[Microsoft.ContainerApps.ApiResources.Models.UnauthenticatedClientAction]. Path: $.properties.globalValidation.unauthenticatedClientAction | LineNumber: 0 | BytePositionInLine: 114."]}})

Optional Parameters支持这个:

--action --unauthenticated-client-action
The action to take when an unauthenticated client attempts to access the app. accepted values:
AllowAnonymous, RedirectToLoginPage, RejectWith401, RejectWith404

我使用

时返回同样的错误
--action RejectWith401

它在 Azure 门户中工作,但我在 CI/CD 管道中需要它。

我在 Whosebug 发现了类似的问题:

--set properties.siteAuthSettings.unauthenticatedClientAction=AllowAnonymous

--set 参数也存在于 az containerapp:
ContainerApp --set

--set
Value of a specific field within the configuration settings for the Azure App Service Authentication / Authorization feature.

在 Azure 门户中启用身份验证后,Azure CLI 返回 show:

resourceGroup='lorem'
appName='ipsum'
az containerapp auth show --resource-group $resourceGroup --name $appName
{
  "globalValidation": {
    "unauthenticatedClientAction": "Return401"
  },...
}

根据收集到的信息,我成功启用了身份验证:

resourceGroup='lorem'
appName='ipsum'
az containerapp auth update --resource-group $resourceGroup --name $appName --enabled true --set globalValidation.unauthenticatedClientAction=Return401
{
  "name": "current",
  "properties": {
    "globalValidation": {
      "unauthenticatedClientAction": "Return401"
    },...
    "platform": {
      "enabled": true
    }
  },
  "resourceGroup": "lorem",
  "type": "Microsoft.App/containerapps/authconfigs"
}