【问题标题】:Spring Boot - Only secure actuator endpointsSpring Boot - 仅安全执行器端点
【发布时间】:2016-08-26 15:13:28
【问题描述】:

我正在使用带有 Jersey 的 Spring Boot (1.3.0)(pom 依赖项:spring-boot-starter-jerseyspring-boot-starter-actuatorspring-boot-starter-webspring-boot-starter-security)。

我有一个 Jersey 端点(见下文),非常简单:

@Component
@Path("/helloworld")
public class HelloWorldResource {

    @GET
    public String home() {
        return "Hello World !";
    }
}

我已通过为 Spring MVC url (server.servlet-path=/system) 设置特定路径来启用 Spring Boot Actuator,如Spring Boot guide 中所述。
感谢spring-boot-starter-security,Actuator 端点通过基本身份验证得到保护。

我的问题是 /helloworld 也是安全的,但我想让它不安全。

我该怎么做?

谢谢!

【问题讨论】:

    标签: security spring-boot spring-boot-actuator


    【解决方案1】:

    您可以将security.user.name 属性与management.security.role 一起添加到您的配置中,例如application.properties 或spring cloud 配置中心的配置,并在启动日志中搜索随机密码。当然,您也可以在bootstrap.yml 中添加密码以使用您指定的密码。

    【讨论】:

    • bootstrap.yml 是 Spring Cloud 的一项功能。它应该是 application.propertiesapplication.yml 与普通 Spring Boot。
    • 你说得对,bootstrap.yml 不够通用。
    • 你没有回答这个问题 :) 我能够保护执行器 (myDomain/system) 但不能让其他端点不安全 (myDomain/myURI)。
    • 通常actuator会集成到其他项目如spring mvc项目中。如果您的项目包含应该不同的其他端点而不是控制器。请您发布有关您的项目结构的更多信息吗?比如其他spring模块。
    • 据我所知,spring security 不会将执行器与您的 uri 区别对待。但是更改执行器的端口甚至地址或禁用其安全性并将其留给防火墙或仅将其与不同的网络隔离是合理的。
    【解决方案2】:

    您必须在 yaml/properties 文件中配置设置,如下所示 -

    server:
      port: 8080
      context-path: /MyApplication
    
    security:
       user:
           name: admin
           password: secret
       basic:
           enabled: false
    
    management:
       context-path: /actuator
       security:
                 enabled: true
    

    因此,对于您的应用程序,安全性被禁用,但对执行器端点启用。确保您没有在管理安全下配置用户名/密码,否则将无法正常工作。

    【讨论】:

    • 从 spring 1.5.4 开始,您不需要在 .yml 中设置任何特定的 context-path。我可以设置security.basic.enabled=falsemanagement.security.enabled=true,它就像一个魅力。
    • @MartinHansen 同上。
    猜你喜欢
    • 1970-01-01
    • 2020-01-03
    • 2018-12-06
    • 1970-01-01
    • 2018-09-11
    • 1970-01-01
    • 2019-07-10
    • 2019-05-11
    • 2018-08-05
    相关资源
    最近更新 更多