是否可以在Spring Cloud Stream Starter应用程序上禁用安全性?

时间:2018-07-02 12:07:04

标签: java spring-boot kubernetes spring-cloud-stream spring-cloud-dataflow

我正在玩Spring Cloud Data Flow。我已经使用相关的documentation在Kubernetes上成功部署了SCDF。注册1.5.x based starter apps时,一切都按预期工作,因此在流定义的部署过程中无需进一步配置启动程序应用程序。

使用2.x based starter apps时,需要适应Spring Boot 2.0的一些变化,例如执行器端点已更改。作为参考,以下是我在流部署期间提供的属性:

app.*.management.endpoints.web.exposure.include=health,info,binders
deployer.*.cpu=2
deployer.*.memory=4096
deployer.http.count=2
deployer.*.kubernetes.livenessProbePath=/actuator/health
deployer.*.kubernetes.readinessProbePath=/actuator/info

但是,由于healthinfo端点现在似乎在默认情况下受到保护,因此准备就绪探测失败。因此,由于从Kubernetes的角度来看,这些Pod永远都没有准备好,所以它们最终陷入了崩溃循环。

我通过遵循patching the starter apps上的指南来解决这种情况,我的流定义依赖于该指南(例如throughput接收器),

@SpringBootApplication
@Import({org.springframework.cloud.stream.app.throughput.sink.ThroughputSinkConfiguration.class})
public class DemoApplication {

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

    @Configuration
    protected static class ThroughputSinkSecurityConfiguration extends WebSecurityConfigurerAdapter {

        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http
                .authorizeRequests()
                .requestMatchers(EndpointRequest.to("health", "info")).permitAll();
        }

    }
}

是否可以通过标志或属性指定这种安全配置?这样的WebSecurityConfigurerAdapter是否不应该默认存在以使Kubernetes可以访问healthinfo端点?

2 个答案:

答案 0 :(得分:2)

我建议从另一个角度调查情况,并从Kubernetes提供凭据以访问安全的微服务。

必须保护所有资源的当前状态问题。

您可以生成自己的静态密码,并将其存储在application.properties中,而不必为每次重新启动应用程序重新配置Kubernetes:https://docs.spring.io/spring-boot/docs/2.0.3.RELEASE/reference/htmlsingle/#boot-features-security

答案 1 :(得分:2)

Artem的回应非常相关。我还想分享一些其他针对安全性和OOTB应用程序的方法。

  1. 在1.6快照中,我们最近通过spring-cloud/spring-cloud-deployer-kubernetes#236添加了支持,以插入basic-auth领域以与安全的执行器端点进行交互。它们适用于活动性和就绪性探针。这是commit/docs供您参考。

  2. 如果您根本不想要安全性(尽管不建议这样做),则可以显式禁用“安全性”配置。

  

dataflow:> stream create foo-定义“ http |吞吐量”

     

数据流:>流部署foo --properties应用程序。*。spring.autoconfigure.exclude = org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration”

(即,foo流定义中的所有应用都将从排除的SecurityAutoConfiguration开始)