【问题标题】:Spring boot admin: Full authentication is required to access this resourceSpring boot admin:访问此资源需要完全身份验证
【发布时间】:2019-01-01 12:03:58
【问题描述】:

我们正在使用 netflix oss 进行反向代理和微服务的安全性,我们遵循这里提到的 jhipster 模式https://www.jhipster.tech/microservices-architecture/,其中来自 UI 应用程序的请求进入网关,即 Api 网关,并将请求代理到我们的后端微服务,我们正在使用 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 个过滤器,一个用于执行器端点的过滤器,一个用于 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-boot spring-security microservices spring-boot-admin


    【解决方案1】:

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

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

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

    【讨论】:

      【解决方案2】:

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

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

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

      【讨论】:

        猜你喜欢
        • 2016-10-03
        • 2018-09-11
        • 2020-11-21
        • 2020-10-25
        • 1970-01-01
        • 2016-11-11
        • 2015-01-08
        • 2020-03-30
        • 2022-01-03
        相关资源
        最近更新 更多