1

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

访问此资源需要完全身份验证

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

management.security.enabled: false 

但仍然没有运气,请有人帮忙指导我需要进行哪些更改以使 Spring Boot 管理员能够成功轮询微服务和 API 网关?

我尝试了以下方法

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

第二个想法:

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

我启用了 2 个过滤器 一个用于执行器端点的过滤器和 1 个用于 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.
}


}
4

2 回答 2

1

我为 Spring Boot 管理服务器启用了基本身份验证,在微服务中添加了该属性

eureka.instance.metadata-map.user.name: 
eureka.instance.metadata-map.user.password:

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

于 2018-07-28T18:54:34.467 回答
0

我有一个类似的问题。在我的 Spring Boot 应用程序中,我们有一个 cors 过滤器来阻止 Http Head 请求。因此,spring boot admin 无法接受 head 请求。

  • 检查过滤器是否阻塞了 HEAD Http 请求。

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

于 2018-10-17T07:42:22.003 回答