spring-cloud / spring-cloud-vault

Configuration Integration with HashiCorp Vault
http://cloud.spring.io/spring-cloud-vault/
Apache License 2.0
270 stars 151 forks source link

InactiveConfigDataAccessException: cannot contain property 'spring.cloud.vault.enabled' #640

Closed ghost closed 2 years ago

ghost commented 2 years ago

Describe the bug According to the Spring Cloud Vault documentation, I can use the field spring.cloud.vault.enabled to disable connecting to vault in profiles where we don't need the connection.

https://docs.spring.io/spring-cloud-vault/docs/current/reference/html/#vault.configdata.location.optional

However, if I run under a profile where spring.cloud.vault.enabled=true, the application crashes because some of the inactive profiles have spring.cloud.vault.enabled=false.

Reason: org.springframework.boot.context.config.InactiveConfigDataAccessException: Inactive property source 'Config resource 'class path resource [application.yml]' via location 'optional:classpath:/' (document #2)' imported from location 'class path resource [application.yml]' cannot contain property 'spring.cloud.vault.enabled' [origin: class path resource [application.yml] - 67:16]

Sample application.yml:

spring:
  application:
    name: ApplicationName-v2
  config:
    import: 
      - "optional:vault://"
  cloud:
    vault:
      enabled: true
      host: vault.mycompany.org
      port: 8200
      scheme: https
      authentication: TOKEN
      kv:
        enabled: true
        default-context: ApplicationName
        backend: ApplicationName-test
        profile-separator: '/'

---
spring:
  config.activate.on-profile: local
  cloud:
    vault:
      enabled: true

---
spring:
  config.activate.on-profile: default
  cloud:
    vault:
      enabled: false

---
spring:
  config.activate.on-profile: prod
  cloud:
    vault:
      kv:
        backend: ApplicationName-prod
ghost commented 2 years ago

I'm using org.springframework.boot:spring-boot-starter-parent2.6.6 org.springframework.cloud:spring-cloud-vault-parent:310

ghost commented 2 years ago

Found a workaround. properties like spring.cloud.vault.enabled and spring.config.import must be separated into profile specific configuration files.

In this example, they had to be moved from application.yml to application-local.yml, application-default.yml, and application-prod.yml

I was able to keep all the other properties in application.yml

mp911de commented 2 years ago

I think this is rather a Spring Boot issue as the Config Data API is provided by Spring Boot.