asp.net-core - 无法通过 http 获取 steeltoe 健康执行器端点
问题描述
我已经阅读了发布说明https://steeltoe.io/reference/reference-release-notes/#2-2-0并有兴趣通过 http 公开 /health 端点(我的意思是在 PCF 应用程序管理器之外)。我在 appsettings.json 中有以下设置
{
"management": {
"endpoints": {
"path": "/cloudfoundryapplication",
"cloudfoundry": {
"validateCertificates": false
},
"health": {
"showdetails": "always",
"claim": {
"type": "health_actuator",
"value": "see_details"
}
}
}
}
}
我的项目参考了 Steeltoe.Management.CloudFoundryCore V2.2.0,我的启动如下所示
public void ConfigureServices(IServiceCollection services)
{
// Add health actuator
services.AddHealthActuator(configuration);
services.AddCloudFoundryActuators(Configuration);
}
public void Configure(IApplicationBuilder app)
{
if (HostingEnvironment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseCloudFoundryActuators();
app.UseHealthChecks();
app.UseMvc();
}
现在,当我尝试调用 url https://myservice/cloudfoundryapplication/health时,我收到一个 401 错误,提示 {"security_error":"Authorization header is missing or invalid"}。知道这里可能有什么问题。
解决方案
以下是在 cloudfoundry 中运行时访问应用程序管理器外部健康端点所需的步骤:
- 请勿将其设置
management:endpoints:path
或设置为 /cloudfoundryapplication 以外的任何内容。默认情况下,您的外部端点将在 /actuator/** 下可用。您可以将其设置为例如管理(只是不是 cloudfoundryapplication,因为应用程序人使用该路由并且它是安全的)。 - 像这样添加您的执行器:
services.AddCloudFoundryActuators(Configuration, MediaTypeVersion.V2, ActuatorContext.ActuatorAndCloudFoundry);
这包括 Health 执行器,因此您不需要另一个 AddHealthActuator 像这样使用执行器:
app.UseCloudFoundryActuators( MediaTypeVersion.V2, ActuatorContext.ActuatorAndCloudFoundry);
为了保护它,您可以添加此配置,
"claim": { "type": "health_actuator", "value": "see_details" }
...您应该在您的请求中提供这些内容。但看起来你不是。此配置是保护端点的一种方式。要在没有安全性的情况下查看它,您可以删除该部分配置。此外,默认设置是显示详细信息,因此您可以将配置完全放在“健康”下。
推荐阅读
- python - pandas 如果列为真,则对该行执行百分比更改
- express - 在显示列表数据时返回 Union Graphql 类型中的自定义错误 | 在graphql中返回具有联合类型的列表
- python - Matplotlib。如何每次使用相同的颜色进行绘图?
- php - Laravel - 通知或调度作业队列工作者 laravel 会导致锁定表的双重选择?
- flutter - 颤振中的状态栏颜色不可控
- json - 如何将数据类转换为地图
- docker - Kind kubernetes 集群拉取 docker 镜像失败
- javascript - 动态创建 javascript/jquery 对象?
- php - 将php函数的结果添加到WP数据库
- c - 如何从我的文件资源管理器中删除这些生成的文件?