Spring Boot Admin使用HTTP而不是HTTPS执行器端点

时间:2018-07-02 12:54:19

标签: java spring spring-mvc spring-boot spring-boot-admin

在Spring Boot Admin(SBA)服务器上注册后,客户端的某些执行器将使用http://springapplication.com/actuator代替https://springapplication.com/actuator。 为什么它将终结点更改为HTTP而不停留在HTTPS上?它是可定制的吗?

这里有一些日志和Java / YML文件。

日志:

2018-07-02 06:13:27.683  INFO 3194 --- [-client-epoll-7] d.c.b.a.server.services.StatusUpdater    : Couldn't retrieve status for Instance(id=0d47f12b0a94, version=57, registration=Registration(name=springbootapplication-Name, managementUrl=https://springbootapplication.com/actuator, healthUrl=https://springbootapplication.com/actuator/health, serviceUrl=https://springbootapplication.com, source=http-api), registered=true, statusInfo=StatusInfo(status=UP, details={}), statusTimestamp=2018-07-02T05:06:08.423Z, info=Info(values={}), endpoints=Endpoints(endpoints={httptrace=Endpoint(id=httptrace, url=http://springbootapplication.com/actuator/httptrace), flyway=Endpoint(id=flyway, url=http://springbootapplication.com/actuator/flyway), loggers=Endpoint(id=loggers, url=http://springbootapplication.com/actuator/loggers), health=Endpoint(id=health, url=https://springbootapplication.com/actuator/health), env=Endpoint(id=env, url=http://springbootapplication.com/actuator/env), heapdump=Endpoint(id=heapdump, url=http://springbootapplication.com/actuator/heapdump), scheduledtasks=Endpoint(id=scheduledtasks, url=http://springbootapplication.com/actuator/scheduledtasks), mappings=Endpoint(id=mappings, url=http://springbootapplication.com/actuator/mappings), beans=Endpoint(id=beans, url=http://springbootapplication.com/actuator/beans), configprops=Endpoint(id=configprops, url=http://springbootapplication.com/actuator/configprops), threaddump=Endpoint(id=threaddump, url=http://springbootapplication.com/actuator/threaddump), metrics=Endpoint(id=metrics, url=http://springbootapplication.com/actuator/metrics), conditions=Endpoint(id=conditions, url=http://springbootapplication.com/actuator/conditions), auditevents=Endpoint(id=auditevents, url=http://springbootapplication.com/actuator/auditevents), info=Endpoint(id=info, url=http://springbootapplication.com/actuator/info), jolokia=Endpoint(id=jolokia, url=http://springbootapplication.com/actuator/jolokia)}), buildVersion=null)

Application.yml(服务器):

server:
  port: 5100
spring: 
  security:
    user:
      name: admin
      password: password

SecuritySecureConfig.java(服务器):

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;

import de.codecentric.boot.admin.server.config.AdminServerProperties;

@Configuration
public class SecuritySecureConfig extends WebSecurityConfigurerAdapter {
    private final String adminContextPath;

    public SecuritySecureConfig(AdminServerProperties adminServerProperties) {
        this.adminContextPath = adminServerProperties.getContextPath();
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
        successHandler.setTargetUrlParameter("redirectTo");

        http.authorizeRequests().antMatchers(adminContextPath + "/assets/**").permitAll()
                .antMatchers(adminContextPath + "/login").permitAll().anyRequest().authenticated().and().formLogin()
                .loginPage(adminContextPath + "/login").successHandler(successHandler).and().logout()
                .logoutUrl(adminContextPath + "/logout").and().httpBasic().and().csrf().disable();
    }
}

SpringBootAdminApplication.java(服务器):

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.PropertySource;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;

import de.codecentric.boot.admin.server.config.EnableAdminServer;

@EnableAutoConfiguration
@EnableWebSecurity
@EnableAdminServer
@SpringBootApplication(scanBasePackages = "administration")
@PropertySource(value = "META-INF/build-info.properties", ignoreResourceNotFound = true)
public class SpringBootAdminApplication {

    private static final Logger log = LoggerFactory.getLogger(SpringBootAdminApplication.class);

    public static void main(final String[] args) {
        SpringApplication.run(SpringBootAdminApplication.class, args);
    }
}

Application.yml(客户端):

spring:
  application:
    name: springapplication
  boot:
    admin:
      client:
        username: ${application.security.usernameAdmin}
        password: ${application.security.passwordAdmin}
        url: "https://springBootAdminServerURL.com"
        instance:
          service-base-url: https://http://springapplication.com/
          metadata:
            user.name: ${application.security.usernameAdmin}
            user.password: ${application.security.passwordAdmin}                 
management:
  endpoints:
    web:
      exposure:
        include: "*"
application:
  security:
    usernameAdmin: admin
    passwordAdmin: password

3 个答案:

答案 0 :(得分:2)

需要在配置文件中更正以下属性,该属性表示为

  

用于计算要注册的服务URL的基本URL。路径是   在运行时推断,并附加到基本网址。

spring.boot.admin.client.instance.service-base-url


instance:
          service-base-url: https://springapplication.com/

答案 1 :(得分:2)

我有同样的问题。查看您的应用程序/actuator端点。将网址报告为http吗?即使健康使用https,它也对我有用。为我解决的是添加server.use-forward-headers=true,它添加了所有X-Forwarded-*,包括标识方案(http / https)的X-Forwared-Proto

请记住,如果您的应用程序位于NGINX之类的反向代理之后,则还需要进行配置。 NGINX的示例

location / {
  proxy_set_header   X-Forwarded-Proto $scheme;
  ...
}

答案 2 :(得分:0)

根据我的经验,这通常是由于两个问题造成的。

  1. 端口配置错误
  2. 不受信任的SSL证书

要解决第一个问题,您需要确保您的客户端应用程序正确通知Eureka使用安全端口:

eureka:
  instance:
    nonSecurePortEnable: false
    securePortEnabled: true

要解决第二个问题,您需要确保SSL证书受运行Spring Boot Admin的JVM信任。只需使用keytool将证书安装到JRE的cacert文件中即可。我建议您在尝试使SSL调试日志正常工作时启用SSL调试日志记录。

-Djavax.net.debug=SSL

这两个步骤为我解决了这个问题。