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

Secrets manager does not work as expected with @ConfigurationProperties("prefix") #1205

Open
hasyimibhar opened this issue Sep 15, 2024 · 1 comment
Labels
component: secrets-manager Secrets Manager integration related issue status: waiting-for-feedback Waiting for feedback from issuer

Comments

@hasyimibhar
Copy link

hasyimibhar commented Sep 15, 2024

Type: Bug

Component: Secrets Manager

Describe the bug
Spring Cloud version: 3.1.1

Secrets manager does not work as expected with @ConfigurationProperties("prefix"). Given the following secret:

{
  "EXAMPLE_FOO": "bar"
}

And the following ConfigurationProperties:

@Configuration
@ConfigurationProperties("example")
@Data
public class ExampleProperties {
  private String foo;
}

I expect foo to resolve to bar, but it resolves to null instead.

Without specifying prefix, the following works:

@Configuration
@ConfigurationProperties()
@Data
public class ExampleProperties {
  private String exampleFoo;
}

exampleFoo now resolves to bar.

It is also possible to make it work by adding the following to application.properties:

example.foo=${EXAMPLE_FOO}

Using ?prefix=example. and the following secrets also works:

{
  "FOO": "bar"
}

Sample
N/A. The description above should be enough.

@maciejwalkowiak
Copy link
Contributor

Properties are added to environment as they are defined in the secret, so in this case it is just EXAMPLE_FOO.

If you define JSON secret as:

{
  "example.foo": "foo",
  "example.bar": "bar"
}

then it will be bound to a class like:

@ConfigurationProperties("example")
class ExampleProps {
    private String foo;
    private String bar;
    // ...
}

I believe this is a correct, no-suprise behavior.

@maciejwalkowiak maciejwalkowiak added component: secrets-manager Secrets Manager integration related issue status: waiting-for-feedback Waiting for feedback from issuer labels Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: secrets-manager Secrets Manager integration related issue status: waiting-for-feedback Waiting for feedback from issuer
Projects
None yet
Development

No branches or pull requests

2 participants