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

handle null values in secrets loaded by the credentials provider #349

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/includes/attributes.adoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
:quarkus-version: 3.17.0
:quarkus-version: 3.17.4
:quarkus-vault-version: 4.1.0
:maven-version: 3.8.1+

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public class VaultITCase {
String someSecretThroughIndirection;

@Test
public void credentialsProvider() throws Exception {
public void credentialsProvider() {
Map<String, String> staticCredentials = credentialsProvider.getCredentials("static");
assertEquals("{" + PASSWORD_PROPERTY_NAME + "=" + DB_PASSWORD + "}", staticCredentials.toString());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ public Map<String, String> getCredentials(String credentialsProviderName) {
}

if (config.kvPath().isPresent()) {
String password = vaultKVSecretEngine.readSecret(config.kvPath().get()).get(config.kvKey());
var val = vaultKVSecretEngine.readSecretJson(config.kvPath().get());
if (val == null) {
throw new VaultException(
"unable to retrieve credential " + config.kvKey() + " from path " + config.kvPath().get());
}
String password = String.valueOf(val.get(config.kvKey()));
Map<String, String> result = new HashMap<>();
result.put(PASSWORD_PROPERTY_NAME, password);
return result;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.quarkus.vault.test;

import static io.quarkus.credentials.CredentialsProvider.PASSWORD_PROPERTY_NAME;
import static java.lang.Boolean.TRUE;
import static java.lang.String.format;
import static java.util.regex.Pattern.MULTILINE;
Expand Down Expand Up @@ -226,6 +225,7 @@ public void start() throws Exception {
.withClasspathResourceMapping("vault-postgres-creation.sql", TMP_VAULT_POSTGRES_CREATION_SQL_FILE, READ_ONLY)
.withClasspathResourceMapping("secret.json", "/tmp/secret.json", READ_ONLY)
.withClasspathResourceMapping("config.json", "/tmp/config.json", READ_ONLY)
.withClasspathResourceMapping("cred-provider.json", "/tmp/cred-provider.json", READ_ONLY)
.withClasspathResourceMapping(getTestPluginFilename(), "/vault/plugins/test-plugin", READ_ONLY)
.withCommand("server", "-log-level=debug", "-config=" + TMP_VAULT_CONFIG_JSON_FILE);

Expand Down Expand Up @@ -312,7 +312,7 @@ private void initVault() throws Exception {
execVault(format("vault kv put %s/%s %s=%s", SECRET_PATH_V1, APP_SECRET_PATH, SECRET_KEY, SECRET_VALUE));
execVault(
format("vault kv put %s/%s %s=%s", SECRET_PATH_V1, LIST_PATH + "/" + LIST_SUB_PATH, SECRET_KEY, SECRET_VALUE));
execVault(format("vault kv put %s/%s %s=%s", SECRET_PATH_V1, APP_CONFIG_PATH, PASSWORD_PROPERTY_NAME, DB_PASSWORD));
execVault(format("vault kv put %s/%s @/tmp/cred-provider.json", SECRET_PATH_V1, APP_CONFIG_PATH));
execVault(format("vault kv put %s/foo-json @/tmp/secret.json", SECRET_PATH_V1));
execVault(format("vault kv put %s/config-json @/tmp/config.json", SECRET_PATH_V1));

Expand All @@ -321,7 +321,7 @@ private void initVault() throws Exception {
execVault(format("vault kv put %s/%s %s=%s", SECRET_PATH_V2, APP_SECRET_PATH, SECRET_KEY, SECRET_VALUE));
execVault(
format("vault kv put %s/%s %s=%s", SECRET_PATH_V2, LIST_PATH + "/" + LIST_SUB_PATH, SECRET_KEY, SECRET_VALUE));
execVault(format("vault kv put %s/%s %s=%s", SECRET_PATH_V2, APP_CONFIG_PATH, PASSWORD_PROPERTY_NAME, DB_PASSWORD));
execVault(format("vault kv put %s/%s @/tmp/cred-provider.json", SECRET_PATH_V2, APP_CONFIG_PATH));
execVault(format("vault kv put %s/foo-json @/tmp/secret.json", SECRET_PATH_V2));
execVault(format("vault kv put %s/config-json @/tmp/config.json", SECRET_PATH_V2));

Expand Down
4 changes: 4 additions & 0 deletions test-framework/src/main/resources/cred-provider.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"password": "bar",
"mynull": null
}
Loading