Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring Cloud GCP Starter Secret Manager - Not Obtaining Secrets after Spring Boot 3 Upgrade. #1628

Closed
ejarans1 opened this issue Feb 26, 2023 · 5 comments

Comments

@ejarans1
Copy link

Describe the bug
We are seeing our secret manager auto configuration fail for applications running on Spring Boot 3.x

Running on 2.7.6 with spring cloud gcp 3.4.0 and spring cloud dependencies 2021.0.4 works as expected.

After upgrading Spring Boot 2.7.6 -> 3.x and the necessary cloud and gcp dependencies, secret manager starter no longer is obtaining secrets from application.yml files.

My Config:

Application.yml
mongo-connection-config:
secret: ${sm://mongo_secret}

build.gradle
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'com.google.cloud:spring-cloud-gcp-starter-secretmanager'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'

}

dependencyManagement {
imports {
mavenBom "com.google.cloud:spring-cloud-gcp-dependencies:4.1.1"
mavenBom 'org.springframework.cloud:spring-cloud-dependencies:2022.0.1'
}
}

@meltsufin
Copy link
Member

Did you follow the migration guide and add spring.config.import=sm://?

@ejarans1
Copy link
Author

Hi Meltsufin,

You are a legend. This was exactly what I needed. I was not aware of this migration guide previously.

I adjusted per the guide and it is working as expected now.

Thanks,
Ethan

@mpeddada1
Copy link
Contributor

Thanks for the suggestion @meltsufin and glad it is working as expected now @ejarans1! Closing this issue.

@Topchiisky
Copy link

Hi there, i have similar problem and i am curious what i am doing wrong.
Here is my setup...
In the pom.xml i have the following

<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>3.0.2</version>
		<relativePath /> <!-- lookup parent from repository -->
</parent>
<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>com.google.cloud</groupId>
				<artifactId>spring-cloud-gcp-dependencies</artifactId>
				<version>4.1.4</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
</dependencyManagement>
<dependency>
			<groupId>com.google.cloud</groupId>
			<artifactId>spring-cloud-gcp-starter-secretmanager</artifactId>
</dependency>

In the application.properties I have added a property like so: my.app.secret=${sm://test_secret}.

Now in the code i tried a couple of things:

  1. @value("${sm://test_secret}")
    private String secret;

  2. System.out.println(env.getProperty("my.app.secret"));

  3. @Autowired
    private SecretManagerTemplate secretManagerTemplate;

    secretManagerTemplate.getSecretString("test_secret");

From the above 1. and 2. are returning '//test_secret' and not the value of the secret.
3. Is returning properly the value of the secret.

Based on this thread I tried putting 'spring.config.import=sm://' in my application.properties file, but this is breaking my application:

00:22:41.905 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
java.lang.RuntimeException: Failed to create the Secret Manager Client for ConfigData loading.
at com.google.cloud.spring.autoconfigure.secretmanager.SecretManagerConfigDataLocationResolver.createSecretManagerClient(SecretManagerConfigDataLocationResolver.java:124)
at com.google.cloud.spring.autoconfigure.secretmanager.SecretManagerConfigDataLocationResolver.lambda$registerSecretManagerBeans$0(SecretManagerConfigDataLocationResolver.java:75)
at org.springframework.boot.BootstrapRegistry$InstanceSupplier.lambda$from$1(BootstrapRegistry.java:160)
at org.springframework.boot.DefaultBootstrapContext.getInstance(DefaultBootstrapContext.java:119)
at org.springframework.boot.DefaultBootstrapContext.getOrElseThrow(DefaultBootstrapContext.java:111)
at org.springframework.boot.DefaultBootstrapContext.get(DefaultBootstrapContext.java:88)
at com.google.cloud.spring.autoconfigure.secretmanager.SecretManagerConfigDataLocationResolver.createSecretManagerTemplate(SecretManagerConfigDataLocationResolver.java:132)
at com.google.cloud.spring.autoconfigure.secretmanager.SecretManagerConfigDataLocationResolver.registerSecretManagerBeans(SecretManagerConfigDataLocationResolver.java:85)
at com.google.cloud.spring.autoconfigure.secretmanager.SecretManagerConfigDataLocationResolver.resolve(SecretManagerConfigDataLocationResolver.java:60)
at org.springframework.boot.context.config.ConfigDataLocationResolvers.lambda$resolve$1(ConfigDataLocationResolvers.java:102)
at org.springframework.boot.context.config.ConfigDataLocationResolvers.resolve(ConfigDataLocationResolvers.java:113)
at org.springframework.boot.context.config.ConfigDataLocationResolvers.resolve(ConfigDataLocationResolvers.java:102)
at org.springframework.boot.context.config.ConfigDataLocationResolvers.resolve(ConfigDataLocationResolvers.java:94)
at org.springframework.boot.context.config.ConfigDataImporter.resolve(ConfigDataImporter.java:105)
at org.springframework.boot.context.config.ConfigDataImporter.resolve(ConfigDataImporter.java:97)
at org.springframework.boot.context.config.ConfigDataImporter.resolveAndLoad(ConfigDataImporter.java:85)
at org.springframework.boot.context.config.ConfigDataEnvironmentContributors.withProcessedImports(ConfigDataEnvironmentContributors.java:115)
at org.springframework.boot.context.config.ConfigDataEnvironment.processInitial(ConfigDataEnvironment.java:242)
at org.springframework.boot.context.config.ConfigDataEnvironment.processAndApply(ConfigDataEnvironment.java:229)
at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:96)
at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:89)
at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEnvironmentPreparedEvent(EnvironmentPostProcessorApplicationListener.java:109)
at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEvent(EnvironmentPostProcessorApplicationListener.java:94)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131)
at org.springframework.boot.context.event.EventPublishingRunListener.multicastInitialEvent(EventPublishingRunListener.java:136)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:81)
at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:64)
at java.base/java.lang.Iterable.forEach(Iterable.java:75)
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:118)
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:112)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:63)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:352)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1302)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1291)
at

@meltsufin
Copy link
Member

@Topchiisky Can you open a new issue for this problem please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants