Micronaut GCP secrets are not loaded

Viewed 199

I am running a Mirconaut application on GCP cloud with Cloud sql database running on a private ip.

DB password is stored in GCP cloud secrets, I need to load the secret before creating connection to DB

I have followed the guide here: https://micronaut-projects.github.io/micronaut-gcp/3.4.0/guide/index.html#secretManager

but the secret is never preloaded for me.

Here is how my bootstrap.yml looks like:

micronaut:
  application:
    name: test
  config-client:
    enabled: true
gcp:
  secret-manager:
    keys:
      - db-user-password

and here is my application.yml db config:

micronaut:
  application:
    name: test
  config-client:
    enabled: true

datasources:
  default:
    url: jdbc:postgresql:///test?cloudSqlInstance=testcloudSqlInstance&socketFactory=com.google.cloud.sql.postgres.SocketFactory
    name: test
    username: user
    password: ${sm.db-user-password}
    dialect: POSTGRES
    maximumPoolSize: 15
    minimumIdle: 5

jpa:
  default:
    packages-to-scan:
      - "com.test"
    entity-scan:
      packages: 'com.test'
    properties:
      hibernate:
        hbm2ddl:
          auto: none
        show_sql: false

liquibase:
  datasources:
    default:
      enabled: true
      dropFirst: false
      defaultSchema: public
      change-log: 'liquibase-changelog.xml'

Micronaut version: 2.3.2 Micronaut gcp version: 3.4.0

1 Answers
  1. Enable logging

<logger name="io.micronaut.context.env.PropertySourcePropertyResolver" level="TRACE"/>

  1. Check google credentials

  2. Check the application's service account has a role "Secret Manager Secret Accessor" for each secret

  3. Looks like the placeholder should be ${sm.db.user.password} not ${sm.db-user-password}

Related