ulisesbocchio / jasypt-spring-boot

Jasypt integration for Spring boot
MIT License
2.91k stars 522 forks source link

Spring Cloud Kubernetes can not reload property from configmap when jasypt is added to classpath #293

Open hashmaparraylist opened 3 years ago

hashmaparraylist commented 3 years ago

Hi,

I have a problem with jasypt and spring-cloud-starter-kubernetes-fabric8-config.

Versions: spring boot: 2.5.1 spring cloud: 2020.0.3 jasypt: 3.0.4

We use Kubernetes' ConfigMap as the Config Server. When we add jasypt-spring-boot to the Classpath, the application.yaml in the Kubernetes ConfigMap can be readed when the application started. But, after edited the ConfigMap, the application does not restart and read the new ConfigMap.

application.yaml look like

management:
  endpoint:
    restart:
      enabled: true
  endpoints:
    web:
      exposure:
        include: health, info, env, restart

test:
  password: ENC(xxxxxxxxxxx)

jasypt:
  encryptor:
    password: demo

bootstrap.yaml look like

spring:
  application:
    name: demo
  cloud:
    kubernetes:
      reload:
        enabled: true
        mode: polling
        period: 5000
        strategy: restart_context
      config:
        name: ${spring.application.name}-config

and ConfigMap look like

apiVersion: v1
data:
  application.yaml: >
    hello: world
kind: ConfigMap
metadata:
  name: demo-config
  namespace: default

And we changed spring cloud's logger level (change to DEBUG). Spring Cloud's PollingConfigMapChangeDetector did not compare local's property and configmap's property.

2021-09-24 16:53:08.131 DEBUG [demo,a56d0ab377792aad,a56d0ab377792aad] 1 --- [pool-3-thread-1] c.k.c.c.r.PollingConfigMapChangeDetector : Polling for changes in config maps
2021-09-24 16:53:08.131 DEBUG [demo,a56d0ab377792aad,a56d0ab377792aad] 1 --- [pool-3-thread-1] c.k.c.c.r.PollingConfigMapChangeDetector : findPropertySources
2021-09-24 16:53:08.132 DEBUG [demo,a56d0ab377792aad,a56d0ab377792aad] 1 --- [pool-3-thread-1] c.k.c.c.r.PollingConfigMapChangeDetector : environment: ApplicationServletEnvironment {activeProfiles=[kubernetes], defaultProfiles=[default], propertySources=[EncryptableMapPropertySourceWrapper {name='server.ports'}, EncryptableEnumerablePropertySourceWrapper {name='bootstrapProperties-configmap.demo-config.default'}, ConfigurationPropertySourcesPropertySource {name='configurationProperties'}, EncryptableEnumerablePropertySourceWrapper {name='commandLineArgs'}, StubPropertySource {name='servletConfigInitParams'}, EncryptableEnumerablePropertySourceWrapper {name='servletContextInitParams'}, EncryptableMapPropertySourceWrapper {name='systemProperties'}, EncryptableSystemEnvironmentPropertySourceWrapper {name='systemEnvironment'}, EncryptablePropertySourceWrapper {name='random'}, EncryptablePropertySourceWrapper {name='cachedrandom'}, EncryptableMapPropertySourceWrapper {name='springCloudClientHostInfo'}, EncryptableMapPropertySourceWrapper {name='KUBERNETES_NAMESPACE_PROPERTY_SOURCE'}, OriginTrackedMapPropertySource {name='Config resource 'class path resource [application.yml]' via location 'optional:classpath:/''}, EncryptableMapPropertySourceWrapper {name='defaultProperties'}, OriginTrackedMapPropertySource {name='Config resource 'class path resource [bootstrap.yml]' via location 'optional:classpath:/''}, EncryptableMapPropertySourceWrapper {name='springCloudDefaultProperties'}, EncryptablePropertySourceWrapper {name='Management Server'}]}
2021-09-24 16:53:08.132 DEBUG [demo,a56d0ab377792aad,a56d0ab377792aad] 1 --- [pool-3-thread-1] c.k.c.c.r.PollingConfigMapChangeDetector : environment sources: [EncryptableMapPropertySourceWrapper {name='server.ports'}, EncryptableEnumerablePropertySourceWrapper {name='bootstrapProperties-configmap.demo-config.default'}, ConfigurationPropertySourcesPropertySource {name='configurationProperties'}, EncryptableEnumerablePropertySourceWrapper {name='commandLineArgs'}, StubPropertySource {name='servletConfigInitParams'}, EncryptableEnumerablePropertySourceWrapper {name='servletContextInitParams'}, EncryptableMapPropertySourceWrapper {name='systemProperties'}, EncryptableSystemEnvironmentPropertySourceWrapper {name='systemEnvironment'}, EncryptablePropertySourceWrapper {name='random'}, EncryptablePropertySourceWrapper {name='cachedrandom'}, EncryptableMapPropertySourceWrapper {name='springCloudClientHostInfo'}, EncryptableMapPropertySourceWrapper {name='KUBERNETES_NAMESPACE_PROPERTY_SOURCE'}, OriginTrackedMapPropertySource {name='Config resource 'class path resource [application.yml]' via location 'optional:classpath:/''}, EncryptableMapPropertySourceWrapper {name='defaultProperties'}, OriginTrackedMapPropertySource {name='Config resource 'class path resource [bootstrap.yml]' via location 'optional:classpath:/''}, EncryptableMapPropertySourceWrapper {name='springCloudDefaultProperties'}, EncryptablePropertySourceWrapper {name='Management Server'}]

Maybe PollingConfigMapChangeDetector does not recognize EncryptablePropertySourceWrapper as the property of ConfigMap, so the comparison is ignored.

Thank you

ulisesbocchio commented 1 year ago

Interesting, would have to investigate...

yxxpers commented 9 months ago

I had the same problem with jasypt and spring-cloud-starter-kubernetes-fabric8-config, and my version is as follows: spring boot: 3.2.0 spring cloud: 2023.0.0 jasypt: 3.0.5