简体   繁体   English

如何在 Spring Cloud Gateway 中的执行器端点上设置密码

[英]How to set password on actuator endpoints in spring cloud gateway

I use spring cloud gateway HoxtonSR8, spring boot 2.3.4 and spring actuator我使用的是 spring 云网关 HoxtonSR8、spring boot 2.3.4 和 spring 执行器

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>

I want to set password on all actuator endpoints including health and info so only authenticated user can call them.我想在所有执行器端点上设置密码,包括健康和信息,以便只有经过身份验证的用户才能调用它们。 But as far as I know it only can be done using spring security but this framework is incompatible with gateway.但据我所知,它只能使用 spring security 来完成,但这个框架与网关不兼容。

How I can set password on actuator in cloud gateway?如何在云网关的执行器上设置密码?

Actuator endpoints reveal sensitive information about the application.执行器端点会显示有关应用程序的敏感信息。

To password protect the actuator endpoints follow the below steps :要密码保护执行器端点,请按照以下步骤操作:

Step 1 : Add spring-boot-starter-security dependency in pom.xml .步骤 1 :在pom.xml添加spring-boot-starter-security依赖项。

   <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
   </dependency>

Thanks to SpringBoot Auto Configuration .感谢SpringBoot Auto Configuration It automatically initialises all the security related components.它会自动初始化所​​有与安全相关的组件。

Step 2 : Define a username and password in your property/yaml file.第 2 步:在您的属性/yaml 文件中定义用户名和密码。

See the below configuration.请参阅以下配置。

spring:
  security:
    user:
      name: admin
      password: ********

Step 3 : Restart the application and try to access Secured Endpoints.第 3 步:重新启动应用程序并尝试访问 Secured Endpoints。

You should get “401 Unauthorized” response.你应该得到“401 Unauthorized”响应。

Step 4 : Open actuator endpoint in a Browser and it will prompt for username/password.第 4 步:在浏览器中打开执行器端点,它会提示输入用户名/密码。

If you want just to secure you actuator endpoints, Add below config :如果您只想保护您的执行器端点,请添加以下配置:

server:
  port: 8080
  context-path: /MyApplication

security:
   user:
       name: admin
       password: secret
   basic:
       enabled: false

management:
   context-path: /actuator
   security:
             enabled: true

This will make sure that application security is disabled but is enabled for actuator endpoints.这将确保禁用应用程序安全性,但为执行器端点启用。

Note : Don't configure username/password under management security otherwise it will not work.注意:不要在管理安全下配置用户名/密码,否则将无法正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM