Spring boot admin:访问此资源需要完全身份验证

Spring boot admin: Full authentication is required to access this resource

我们正在使用 netflix oss 进行微服务的反向代理和安全,我们遵循此处提到的 jhipster 模式 https://www.jhipster.tech/microservices-architecture/,其中来自 UI 应用程序的请求转到网关 Api 网关并将请求代理到我们的后端微服务,我们使用 jwt 进行身份验证,我们想要一个仪表板来监控我们的微服务和 api 向 eureka 服务器注册的网关,我们启动了一个单独的 spring 引导管理服务器,以便它向尤里卡服务器注册并轮询微服务和网关以获取指标端点,但我们遇到异常

Full authentication is required to access this resource

这是由在 api 网关和微服务级别过滤 jwts 的过滤器抛出的, 我们也试过禁用

management.security.enabled: false 

但仍然没有运气,有人可以帮助指导我需要进行哪些更改才能启用 spring 启动管理员以成功轮询微服务和 api 网关吗?

我尝试了以下方法

首先我启用了 web.ignoring().antMatchers("/actuator/**"),因此执行器端点会被 spring 安全性忽略,但这种方法会冒着 api的

第二个想法:

如果我在 spring security 中启用 2 个过滤器,第一个过滤器将用于 spring 启动管理员,对执行器端点进行基本身份验证,第二个过滤器将是我的 jwt 身份验证,用于其余所有 api 和下游 api 不确定是否可行?

我启用了 2 个过滤器,一个过滤器用于执行器端点,另一个过滤器用于 api,但这些过滤器工作正常但无法连接到 SBA

public class SpringSecurityAdminFilter extends WebSecurityConfigurerAdapter {



@Autowired
public void configureGlobalSecurity(AuthenticationManagerBuilder auth) throws Exception {

       String password = passwordEncoder().encode("xxxx");
    auth.inMemoryAuthentication().passwordEncoder(passwordEncoder()).withUser("sam").password(password).roles("ADMIN");

}

@Bean
public BCryptPasswordEncoder passwordEncoder() {
    return new BCryptPasswordEncoder();
}

@Override
protected void configure(HttpSecurity http) throws Exception {

  http.csrf().disable()
    .authorizeRequests()
    .antMatchers("/actuator/**").hasRole("ADMIN")
    .and().httpBasic()
    .and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);//We don't need sessions to be created.
}


}

我为 spring 启动管理服务器启用了基本身份验证,在微服务

中添加了 属性
eureka.instance.metadata-map.user.name: 
eureka.instance.metadata-map.user.password:

现在执行器端点受基本身份验证保护

我遇到过类似的问题。在我的 spring 启动应用程序中,我们有一个 cors 过滤器来阻止 Http Head 请求。因此无法接受来自 spring 引导管理员的 head 请求。

  • 检查过滤器是否正在阻止 HEAD Http 请求。

  • 在 application.properties 中设置 management.security.enabled=false 也是必要的。