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 - Failed to create the Secret Manager Client for ConfigData loading #1920

Open
magnram opened this issue Jun 2, 2023 · 2 comments

Comments

@magnram
Copy link

magnram commented Jun 2, 2023

Hi there, I'm having problems with my spring boot application using gcp secret manager. Found this comment on a closed issue #1628 where the author was asked to create a new issue on it, but I didn't find any issues created. I'm having the same issues as the original poster with spring boot 3.1.0 and secret manager 4.3.1.

Here is the original comment:

Originally posted by @Topchiisky in #1628 (comment)

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

Originally posted by @Topchiisky in #1628 (comment)

@meltsufin
Copy link
Member

Can you provide a reproducer? You can modify the Secrets Manager Sample for this.

@saibanna
Copy link

I had below property in application.properties after removing it worked fine for me
spring.cloud.gcp.secretmanager.enabled=true

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

No branches or pull requests

4 participants