首页 > 解决方案 > 从 K8s configmap 读取时,Spring Boot Actuator 端点不显示属性值

问题描述

我正在尝试查看我在项目中拥有的一些自定义属性application.yml

meanwhileinhell:
  myproject:
    myserver:
      security:
        users:
          - username: user1
            password: "{noop}password1"
            roles:
              - USER
          - username: user2
            password: "{noop}password2"
            roles:
              - USER
      services:
        - "service-the-first"
        - "another-service"

我在 Kubernetes 集群中运行我的系统,在安装过程中,我使用以下命令configmap为每个项目创建 s :application.yml

kubectl create configmap <project> --from-file "<project>/src/main/resources/application.yml"

在我正在运行的系统上查看这些配置图,我可以看到所有的值都在那里。

这些属性绑定到 Kotlin 类:

@ConstructorBinding
@ConfigurationProperties("meanwhileinhell.myproject.myserver.security")
class SecurityUsersProperties(val users: List<User>)

data class User(val username: String, val password: String, val roles: List<String>)
@ConstructorBinding
@ConfigurationProperties("meanwhileinhell.myproject.myserver")
class ServiceNameProperties(val services: List<String>)

然后在几个配置类中启用:

@EnableConfigurationProperties(ServiceNameProperties::class)

笔记!在课堂SecurityUsersProperties::class上启用 。WebSecurityConfig

这些值都已成功加载,因为我可以在需要的地方使用凭据登录,并监控该特定服务列表。

我的问题是当我尝试查看actuator/configprops端点上的属性时。我可以看到属性名称列表,但是当我单击展开值时,它们不会显示。

contexts:
  application-1:
    beans:
      meanwhileinhell.myproject.myserver.security-com.meanwhileinhell.myproject.myserver.security.properties.SecurityUsersProperties:
        properties:
          users:
        inputs:
          users:
            0:
              roles:
                0:
                  origin:    "\"meanwhileinhell.myproject.myserver.security.users[0].roles[0]\" from property source \"bootstrapProperties-configmap.myserver.default\""
            1:
              roles:
                0:
                  origin:    "\"meanwhileinhell.myproject.myserver.security.users[1].roles[0]\" from property source \"bootstrapProperties-configmap.myserver.default\""

在这种情况下,只roles:显示,没有username或 (sanitised) password。如果我搜索我的服务列表也是如此:

contexts:
  application-1:
    beans:
      meanwhileinhell.myproject.myserver.services-com.meanwhileinhell.myproject.myserver.health.properties.ServiceNameProperties:
        properties:
          services:
        inputs:
          services:
            0:
              origin:   "\"meanwhileinhell.myproject.myserver.services[0]\" from property source \"bootstrapProperties-configmap.myserver.default\""
            1:
              origin:   "\"meanwhileinhell.myproject.myserver.services[1]\" from property source \"bootstrapProperties-configmap.myserver.default\""

在我的 rootbuild.gradle.kts中,我在所有服务上启用了执行器端点:

implementation("org.springframework.boot:spring-boot-starter-actuator")

有什么我遗漏的东西可以显示我的属性吗?

更新 我的env执行器端点现在似乎正在工作,并显示我的用户名和(经过清理的)密码以及角色。但是,configprops仍然没有显示它们,只有roles上面提到的那些。

标签: spring-bootkotlinkubernetesspring-boot-actuatorconfigmap

解决方案


推荐阅读