Uses label when searching secrets in [Spring]VaultEnvironmentRepository#2460
Uses label when searching secrets in [Spring]VaultEnvironmentRepository#2460ryanjbaxter merged 6 commits intospring-cloud:4.1.xfrom
Conversation
|
So this will break existing apps since the location in vault will be different now? |
Yes, the secret keys should include a label (mostly |
|
IMO this will be problematic to include in anything but a major in its current form. What if we didn't include the label in the key if it is the same as the default label? That would preserve the existing behavior for the more part. I also want to run this by the rest of the team to see what they think. |
|
Right, If we skip appending label to the key if it is same as default label ( |
The default is
I guess I wonder if anyone is using a label and if so why if it was never actually used with Vault? |
|
Default label is only configurable for some backends like Regarding your second point: |
|
Got it. After discussing with the team we think that this new functionality should be wrapped in a feature flag which is disabled by default and should only go into main. |
|
@ryanjbaxter |
|
@ryanjbaxter would you mind having a look at latest changes (feature flag) ? |
|
Looks good, can you document the new property? |
|
@ryanjbaxter while trying to update the documents, I just realised an ambiguity in the secret path which is introduced by my changes. A complete secret key would be something like
The simplest solution which I can think of is always including the profile (even if it is default) in the valut key. So that we have a fix key format consist of 3 separate segments ( Note: Since we have the feature flag for the changes in this PR, It should not break any existing functionality. |
I agree with this. When making a request to the config server only the label is optional in the path, you must include the application name and profile even if that profile is default. So it makes sense that we require the application name and profile in the key.
Does that mean today that we don't require the profile when creating the key today? |
yes, the profile part is optional. secrets can be stored in the following paths in valut:
To keep the backward compatibility, the behaviour should stay the same when the |
|
Got it. But I would say that it should always have 2 segments, application and profile, label being optional. Again much like the rest API label is the only optional part. |
Label is optional in API level but when omitted a default label (currently |
|
@ryanjbaxter I've updated the PR and I believe it is ready for the final review. |
|
@kvmw one small this, I think the default label should be |
Signed-off-by: kvmw <[email protected]>
Signed-off-by: kvmw <[email protected]>
Signed-off-by: kvmw <[email protected]>
…t key Signed-off-by: kvmw <[email protected]>
Signed-off-by: kvmw <[email protected]>
Signed-off-by: kvmw <[email protected]>
@ryanjbaxter Updated the PR with |
Like other EnvironmentRepositories,
VaultEnvironmentRepository::findOneandSpringVaultEnvironmentRepository::findOneshould use thelabelargument passed to them when searching for secrets in vault.So calling
findOne("my-app", "my-profile", "my-label")should search for secrets in vault in the following locations with the exact order:secret/myapp,my-profile,my-labelsecret/application,my-profile,my-label(Assumingapplicationis the default-key)secret/myapp,my-labelsecret/application,my-label(Assumingapplicationis the default-key)Currently the search locations are the followings (note the missing label):
secret/myapp,my-profilesecret/application,my-profile(Assumingapplicationis the default-key)secret/myappsecret/application(Assumingapplicationis the default-key)This PR fixes the above issue.
Breaking Change
Since this wrong behaviour has been there from the day one, based on my knowledge, everyone using the vault backend has been relying on it and they have been adding their vault secrets in the wrong location (without label). Fixing this behaviour is going to break all those applications using the vault backend.
Update 23 Sep. 2024
I've updated the PR with the following changes:
Added a feature flag (
enableLabel) for the new changes (using label in search). The feature flag (enableLabel) isoffby default.Added the
defaultLabelto Vault properties. It ismasterby default and only used when above feature flag ison.When above feature flag is
on, the vault secrets should have always all three segments ([application name | 'application'],[profile | 'default'],[label | 'master']) in their paths.Updated the vault docs.