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

use .readSecretJson in VaultCredentialsProvider #329

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

joeyy-watts
Copy link

@joeyy-watts joeyy-watts commented Sep 28, 2024

Fixes #327

I have tested this in my own fork of the repo, and confirmed it to be working.


Under .getCredentials(), the current code uses .readSecret() which will fail if the secret containing the password contains a null value, e.g.:

{
    "password": "foo",
    "someotherfield": null
}

This PR uses .readSecretJson() instead, which does not assume the secret's values are always String, and converts it to String using String.valueOf().

One caveat is that it will no longer (implicitly) guarantee the password to never be null. I am open to suggestions on this point.

@kdubb
Copy link
Contributor

kdubb commented Sep 28, 2024

@vsevel You're in a better position to determine if this is the best fix for this.

@kdubb kdubb requested a review from vsevel September 28, 2024 17:07
@joeyy-watts joeyy-watts marked this pull request as ready for review September 29, 2024 14:44
@joeyy-watts joeyy-watts requested a review from a team as a code owner September 29, 2024 14:44
@@ -56,7 +56,7 @@ public Map<String, String> getCredentials(String credentialsProviderName) {
}

if (config.kvPath().isPresent()) {
String password = vaultKVSecretEngine.readSecret(config.kvPath().get()).get(config.kvKey());
String password = String.valueOf(vaultKVSecretEngine.readSecretJson(config.kvPath().get()).get(config.kvKey()));
Copy link
Contributor

@vsevel vsevel Oct 8, 2024

Choose a reason for hiding this comment

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

this is fine. I would just add a check for nullity (assuming a null password does not make sense; and was not supported anyway).

var val = vaultKVSecretEngine.readSecretJson(config.kvPath().get()).get(config.kvKey());
if(val == null) {
  throw new VaultException("unable to retrieve credential "+config.kvKey()+" from path "+config.kvPath().get());
}

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

Successfully merging this pull request may close these issues.

NullPointerException when retrieving Vault contents with null values
3 participants