spring-cloud / spring-cloud-vault

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

Intermittent database connection with Atlas #583

Closed joaoheytor closed 3 years ago

joaoheytor commented 3 years ago

Describe the bug Hello guys, Almost all of our applications here use SpringCloud in a Kubernetes eco-system and now, due to security reasons, we decided to use the Hashicorp Vault too. All the things seem to be working but we have an intermittent database connection when we're working with Atlas. We're not sure why, but it is possible to see that the application restarts a lot of times before the correct startup. Looking for the spring cloud logs, we can see that the spring is calling the Vault and Vault is creating a dynamic user for us and some seconds later, the spring requests to delete this user since it seems it is not working. Any of you already faced something like that?

In our pom.xml, we have the following dependencies:

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-vault-config</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-vault-config-databases</artifactId>
</dependency>
</dependencies>

And the example of the bootstrap.yaml:

spring:
  application:
    name: application-name
    version: @project.version@
  profiles: dev,sit,uat,prod
  cloud:
    vault:
      enabled: true
      application-name: application-name
      authentication: APPROLE
      read-timeout: 15000
      app-role:
        role-id: XXXXXXX
        secret-id: XXXXX
        role: XXXXXX
      fail-fast: true
      scheme: http
      host: 10.121.0.11
      connection-timeout: 30000
      config:
        lifecycle:
          enabled: true
          min-renewal: 15m
          expiry-threshold: 30m
      generic:
        enabled: false
      database:
        enabled: true
        role: YYYYYY
        backend: database
        username-property: db.username
        password-property: db.password
  data:
    mongodb:      
   uri: mongodb+srv://${db.username}:${db.password}@europe-dev-shard-pri.bro0z.azure.mongodb.net/?retryWrites=true&w=majority}
      database: ${MONGODB_DATABASE:application-database}

The full log of the application is below: log.txt

spencergibb commented 3 years ago

Closing in favor or stack overflow. Please don't cross post https://stackoverflow.com/questions/66699667/intermittent-database-connection-with-atlas