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

Added support for regional secrets via Google Cloud Secret Manager #1202

Conversation

abheda-crest
Copy link
Contributor

Added support for regional secrets via Google Cloud Secret Manager.

Approach:

  • We have added a location field in the SecretManagerConfigurationProperties
  • We have injected the SecretManagerConfigurationProperties into the SecretManagerFactory using constructor injection. This will be used to create the SecretManagerServiceClient based on the location provided in the configuration.
  • We have added DefaultLocationSecretManagerClient class that will be used to fetch regional secrets based on the location provided in the configuration. For this, we have injected SecretManagerConfigurationProperties.
  • We have also handled scenario to conditionally generate an implementation of SecretManagerClient based on the availability of location property in the configuration using @Requires annotation. i.e. If location field is present, than a bean of DefaultLocationSecretManagerClient will be created, else a bean of DefaultSecretManagerClient will be created.
  • We have also added location field to the wrapper class VersionedSecret.

Alternative Approach and the reason we avoided it:

Rather than developing a separate implementation for the wrapper client DefaultLocationSecretManagerClient, we could have introduced a new field for SecretManagerConfigurationProperties and utilised constructor injection to modify the existing constructor of the DefaultSecretManagerClient. However, we were concerned that some users might have used this constructor to instantiate the wrapper client. As a result, we decided to pursue the approach outlined above.

We've covered the following scenarios for both global as well as regional secrets to test the functionality:

  • Positive
    • We were able to inject the bean of type SecretManagerServiceClient and fetch the secrets
    • We were able to inject the bean of wrapper client SecretManagerClient and fetch the secrets
    • We were able to load default config when config-client is enabled
    • We were able to load non default config when config-client is enabled
    • We were able to load key/value pairs into a PropertySource when config-client is enabled
  • Negative
    • When config-client is not enabled, the default config is not loaded
    • When config-client is enabled and the default-config property is false, the default config is not loaded
    • When config-client is not enabled, the non default config is not loaded
    • When config-client is not enabled, the key/value pairs is not loaded into a PropertySource
    • When I added gcp.secret-manager.location= to the bootstrap configuration, the SecretManagerServiceClient was created using the global endpoint (https://secretmanager.googleapis.com/). Also, DefaultLocationSecretManagerClient was instantiated, rather than the DefaultSecretManagerClient itself, which depends on the SecretManagerServiceClient. Consequently, when using the methods of this wrapper location client, we cannot retrieve the regional secrets, and we won’t see any errors. This is because the getSecret method manages errors by returning a Mono.empty() object in case of an error.

More information about regional secrets: https://cloud.google.com/secret-manager/regional-secrets/data-residency

@CLAassistant
Copy link

CLAassistant commented Oct 23, 2024

CLA assistant check
All committers have signed the CLA.

@graemerocher graemerocher added the type: enhancement New feature or request label Oct 23, 2024
@graemerocher graemerocher requested a review from sdelamo October 23, 2024 14:37
Copy link
Contributor

@graemerocher graemerocher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Just a few items to address

@sdelamo sdelamo changed the base branch from 5.7.x to 5.8.x October 24, 2024 14:16
Copy link
Contributor

@sdelamo sdelamo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sdelamo sdelamo merged commit 09721e2 into micronaut-projects:5.8.x Oct 25, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants