Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Polish Secret Manager Code #2270

Merged
merged 5 commits into from
Mar 26, 2020
Merged

Polish Secret Manager Code #2270

merged 5 commits into from
Mar 26, 2020

Conversation

dzou
Copy link
Contributor

@dzou dzou commented Mar 24, 2020

Followup to secret manager version feature changes.

Contents of PR:

  • Fixes integration tests
  • Rename 'version' property to 'default-version' : I feel this more accurately conveys that when a user specifies a specific version of a secret it will override the default.
  • Fixes bug where if the default version doesn't exist for a particular secret it will now correctly be skipped instead of throw error.
  • General polish.

@dzou dzou requested review from meltsufin and elefeint March 24, 2020 00:04
@codecov
Copy link

codecov bot commented Mar 24, 2020

Codecov Report

Merging #2270 into master will decrease coverage by 7.10%.
The diff coverage is 0.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2270      +/-   ##
============================================
- Coverage     79.73%   72.63%   -7.11%     
+ Complexity     2276     2055     -221     
============================================
  Files           258      258              
  Lines          7460     7450      -10     
  Branches        759      762       +3     
============================================
- Hits           5948     5411     -537     
- Misses         1193     1689     +496     
- Partials        319      350      +31     
Flag Coverage Δ Complexity Δ
#integration ? ?
#unittests 72.63% <0.00%> (+0.16%) 2055.00 <0.00> (+6.00)
Impacted Files Coverage Δ Complexity Δ
...anager/GcpSecretManagerBootstrapConfiguration.java 0.00% <ø> (ø) 0.00 <0.00> (ø)
...gure/secretmanager/GcpSecretManagerProperties.java 0.00% <ø> (ø) 0.00 <0.00> (ø)
...ure/secretmanager/SecretManagerPropertySource.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...retmanager/SecretManagerPropertySourceLocator.java 0.00% <ø> (ø) 0.00 <0.00> (ø)
...a/spanner/repository/query/SpannerQueryMethod.java 0.00% <0.00%> (-100.00%) 0.00% <0.00%> (-6.00%)
...figure/config/GcpConfigBootstrapConfiguration.java 0.00% <0.00%> (-100.00%) 0.00% <0.00%> (-2.00%)
...restore/repository/query/FirestoreQueryMethod.java 0.00% <0.00%> (-100.00%) 0.00% <0.00%> (-2.00%)
...epository/config/SpannerRepositoriesRegistrar.java 0.00% <0.00%> (-100.00%) 0.00% <0.00%> (-3.00%)
...pository/support/FirestoreQueryLookupStrategy.java 0.00% <0.00%> (-100.00%) 0.00% <0.00%> (-2.00%)
...ository/config/DatastoreRepositoriesRegistrar.java 0.00% <0.00%> (-100.00%) 0.00% <0.00%> (-3.00%)
... and 56 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update eb6c09a...c7ef782. Read the comment docs.

@meltsufin
Copy link
Contributor

@eddumelendez FYI

@eddumelendez
Copy link
Contributor

thanks for let me know @meltsufin

Copy link
Contributor

@meltsufin meltsufin left a comment

Choose a reason for hiding this comment

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

I think we can offer both options of skipping or failing on missing version. WDYT?

docs/src/main/asciidoc/secretmanager.adoc Outdated Show resolved Hide resolved
}
catch (Exception e) {
if (e instanceof NotFoundException) {
LOGGER.debug("Skipped loading secret " + secretId + " because it does not have version " + defaultVersion);
Copy link
Contributor

Choose a reason for hiding this comment

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

Notice that this will also happen when a specific secret.version is specified.
I fear that this make it hard to debug mistakes in the client code.
Consider adding another property to chose whether to skip silently or fail.
Something like failOnMissingSecretVersion.

Copy link
Contributor Author

@dzou dzou Mar 24, 2020

Choose a reason for hiding this comment

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

For this one, this is what I think makes the most sense:

  • If a user-specified version doesn't exist, throw an error.
  • If a default version doesn't exist for a secret, ignore the secret.

I think this makes the most sense for the default version handling because most users will have multiple secrets in their project, and they might all be at different versions (like some you'll be at version 5 and maybe some at version 1 or 2).

In practice, for any value of default-version other than "latest", there is a low chance that every secret in the project is up to that version. For example, if you choose to set default-version to 2, this bootstrap loading would fail if any secret in the project was only at version 1. So I think the default-version option is only useful if you skip the secrets that aren't up to the default version.

Copy link
Contributor

Choose a reason for hiding this comment

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

Your reasoning makes sense, but I still feel that it's just too complicated and will leave room for some surprises for people who do not carefully read the documentation. You can argue that the default version setting should never be used, unless the project keeps all of the secrets at the same version. Maybe they have a convention where each version of the application has a corresponding version of the secrets. In that case, as a developer I would like a hard fail if I make a mistake and forget to include a secret with the right version that follows that convention.
Of course there could be exceptions. Therefore, I'm suggesting to add a property to allow skipping secrets with non-existing versions.
I guess we're struggling here partly because we're not sure what is the common use-case for default-version.
Maybe @eddumelendez can help us out here.

Copy link
Contributor Author

@dzou dzou Mar 24, 2020

Choose a reason for hiding this comment

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

I see. I just was not a fan of the additional setting because I imagine most projects will have secrets of different versions.

I don't see it being likely that each version of an application will have its own version of secrets - like a password to your MySQL database might stay the same across all of your application versions but some other secret might be updated more frequently. And what if you have to add a new secret to an application? If you're at version 5 for your current secrets, the new secret must be updated 5 times to hit version 5. (The only way to increment a secret version is to create a new version of it in the APIs; you can't create a new secret and set it to 5 directly)

Hmm, the more I think about it, the less useful overriding the default-version is. It feels like defaulting to latest makes the most sense and overriding secret versions should be done on an individual level per secret. What do you guys think? @meltsufin @eddumelendez

Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't realize that the version cannot be set directly.
I happy to remove the default version feature.
@saturnism @eddumelendez WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

It feels like defaulting to latest makes the most sense and overriding secret versions should be done on an individual level per secret.

I'm in favor of this.

There is just two options for every secret which is use the latest or a specific version. Given that, default-version doesn't make much sense.

Also, regarding to:

If a user-specified version doesn't exist, throw an error.
If a default version doesn't exist for a secret, ignore the secret

So, if the secret is ignored then @Value will not resolve it, right? I think the docs are pretty clear about the context but not sure if will be hard to figure it out is we are missing to read the docs.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds like we're all leaning towards just removal of default-version and hard fail in case a specified version doesn't exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you both for the input, this is much appreiciated. Yes in that case, let's go in that direction.

dzou added 2 commits March 26, 2020 11:40
# Conflicts:
#	docs/src/main/asciidoc/secretmanager.adoc
@dzou
Copy link
Contributor Author

dzou commented Mar 26, 2020

@meltsufin - done, just removed the default-version; PTAL.

meltsufin
meltsufin previously approved these changes Mar 26, 2020
Copy link
Contributor

@meltsufin meltsufin left a comment

Choose a reason for hiding this comment

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

LGTM aside from the build failure.

@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 2 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@dzou dzou merged commit a30ac3f into master Mar 26, 2020
@dzou dzou deleted the polish-secretmanager branch March 26, 2020 23:16
guillaumeblaquiere pushed a commit to guillaumeblaquiere/spring-cloud-gcp that referenced this pull request Mar 27, 2020
Removes the version property for secret manager
guillaumeblaquiere pushed a commit to guillaumeblaquiere/spring-cloud-gcp that referenced this pull request Mar 27, 2020
Removes the version property for secret manager
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants