我们正在使用 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.
}
}