具有X509身份验证的管理端口和服务器端口

时间:2020-11-03 11:11:53

标签: spring-boot spring-boot-actuator

我有一个通过x509认证的API。但是,我需要从验证中绕过执行器健康检查终点,以便我可以在没有客户端证书的情况下进行健康检查。

我意识到可以通过使用不同的端口来实现执行器端点的服务器和管理。

我的application.yml配置如下:

server:
  port: 9000
  ssl:
    key-store: classpath:keystore.jks
    key-store-password: password
    key-password: password
    enabled: true
    trust-store: classpath:truststore.jks
    trust-store-password: password
    client-auth: need
    
management:
  server:
    port: 9010
    ssl:
      enabled: false
    security:
      enabled: false

我的问题是,即使使用此配置,管理端点也不是我可以访问运行状况端点的位置。 http:// localhost:9010 / health->这不起作用

我仍然可以使用服务器端口和证书来访问它。 https:// localhost:9000 / health->可行

我的安全性配置如下:

@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter  {
    
    @Override
    public void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
        .anyRequest()
        .authenticated()
        .and()
        .x509()
        .subjectPrincipalRegex("CN=(.*?)(?:,|$)")
        .userDetailsService(userDetailsService())
        .and()
        .sessionManagement()
        .sessionCreationPolicy(SessionCreationPolicy.NEVER)
        .and()
        .csrf().disable();
    }
    
    @Bean
    public UserDetailsService userDetailsService() {
        return new UserDetailsService() {
            public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
                if (username.equals("user")) {
                    return new User(username, "", AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"));
                }
                throw new UsernameNotFoundException("User not found!");
            }
        };
    }

我的pom中有spring-boot-actuator依赖项。我不明白为什么我的管理端口不起作用。

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

我弄清楚这里出了什么问题。这是Spring Boot的依赖。我使用的是spring-boot-actuator,当我将其更改为spring-boot-starter-actuator时,管理端口开始监听配置的端口。然后,我在该端口上禁用了SSL身份验证。在下面提供我的配置,以便对其他人有帮助:

management:
  server:
    port: 8000
    ssl:
      enabled: false

server:
  port: 9000
  ssl:
    key-store: classpath:keystore.jks
    key-store-password: password
    key-alias: alias
    key-password: password
    enabled: true
    trust-store: classpath:truststore.jks
    trust-store-password: password
    client-auth: need

现在,我可以使用有效的客户端证书通过端口8000上的http访问我的执行器端点,例如运行状况,并通过端口https上的9000端口访问我的应用程序剩余API。