使用 Spring-Boot-Admin 和 Eureka 发现进行身份验证

Authentication with Spring-Boot-Admin and Eureka discovery

SBA 版本 2.0.1

Spring-云Finchley.RELEASE

我在尤里卡注册了一些服务。这些服务是 Spring-Boot 应用程序,并通过 HTTP 基本身份验证保护其执行器。服务执行器位于 /actuator。这些服务正在运行,我可以通过 Postman 和 curl 与他们的执行器进行交互。 SBA 连接到 Eureka 并发现服务,但它们始终处于关闭(红色)状态,除了 SBA 应用程序本身,它在 SBA 控制台中显示为绿色,我可以单击它并查看它的属性。

当我单击其中一个服务实例时,系统提示我输入凭据。我不确定要使用什么凭据,所以我使用服务执行器的凭据。如文档中所示,我已经在元数据映射中拥有这些凭据,但系统仍然提示我输入凭据。这总是会导致显示 Whitelabel 错误页面,并显示如下错误消息:

Mon Jun 25 12:40:57 CDT 2018 There was an unexpected error (type=Method Not Allowed, status=405). Request method 'POST' not supported

虽然我注意到该错误的 url 显然是在 SBA 实例本身,而不是远程服务上。 url 解码为:http://localhost:8080/#/instances/9207aa5fc06b/

但我在该服务的日志中看到了这一点,显然是一个未经身份验证的请求正在发送到删除服务:

[2018-06-25 12:16:54.242] - DEBUG - [http-nio-8380-exec-7] [AUTHENTICATION_SERVICE_DEV,8dc8165d4f77be7c,8dc8165d4f77be7c,false] --- [nio-8380-exec-7] o.s.w.s.m.m.a.HttpEntityMethodProcessor : Written [{timestamp=Mon Jun 25 12:16:54 CDT 2018, status=401, error=Unauthorized, message=Unauthorized, path=/actuator/health}] as "application/vnd.spring-boot.actuator.v2+json" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@30c8681]

在 SBA 日志中:

2018-06-25 12:39:40.884 ERROR [SERVICES_ADMIN_CONSOLE_LOCAL,,,] 20728 --- [nio-8080-exec-8] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception

java.io.IOException: An established connection was aborted by the software in your host machine

这是我困惑的根源,我不确定我需要什么凭证,甚至不确定我要验证什么。我已经在属性和登录表单中提供了远程服务的凭据,但它不起作用。

当我在 SBA 控制台中单击 SBA 应用程序时,它按预期工作。所以这似乎与远程执行器的身份验证有关,但我无法弄清楚问题所在。

服务器:

@Configuration
@EnableAutoConfiguration
@EnableEurekaClient
@EnableAdminServer
public class ServiceAdmin {

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

    @Configuration
    public static class SecurityPermitAllConfig extends WebSecurityConfigurerAdapter {
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http.authorizeRequests().anyRequest().permitAll()
                    .and().csrf().disable();
        }
    }
    }

SBA 配置:

management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
management.info.git.mode=full
management.endpoint.shutdown.enabled=true
spring.security.user.name=actuator
spring.security.user.password=password
spring.security.user.roles=ACTUATOR

eureka.instance.leaseRenewalIntervalInSeconds=10
eureka.instance.health-check-url-path=/actuator/health
eureka.instance.metadata-map.user.name=actuator
eureka.instance.metadata-map.user.password=password
eureka.client.registryFetchIntervalSeconds=5
eureka.client.serviceUrl.defaultZone=http://svcregistry1.mycompany.com/eureka/,http://svcregistry2.mycompany.com

这里的问题是我没看懂文档。 metadataMap 中的 eureka 凭据必须由受监视的应用程序在注册时提供。 SBA 配置中未提供。

对于任何遇到这个问题,和我一样困惑的人,澄清这个答案。

我在同一个应用程序中有 Eureka 和 Springboot admin server/ui

将注册到 eureka 和 springboot admin 中的所有服务都需要将它们自己的 /actuator 凭据作为元数据提供:

eureka.instance.metadata-map.user.name = ${endpoints.user.name} 
eureka.instance.metadata-map.user.password = ${endpoints.user.password}

这 post 解决了一些问题。 https://zoltanaltfatter.com/2018/05/15/spring-cloud-discovery-with-spring-boot-admin/