Skip to content

Commit

Permalink
fix: clarify vault error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mattnichols committed Feb 2, 2024
1 parent d3b8d2f commit 8208fb6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,20 +226,20 @@ final Vault buildAuthenticatedDriver(Vault authenticationDriver) {

case APPROLE:
resp = authenticationDriver.auth().loginByAppRole(configuration.getAppRole(), configuration.getSecretId());
validateVaultAuthenticationResponse(resp, "Unable to login via jwt");
validateVaultAuthenticationResponse(resp, "Unable to login via vault app-role");

token = resp.getAuthClientToken();
break;

case APPID:
resp = authenticationDriver.auth().loginByAppID("app-id/login", configuration.getAppId(), configuration.getUserId());
validateVaultAuthenticationResponse(resp, "Unable to login via app-id");
validateVaultAuthenticationResponse(resp, "Unable to login via vault app-id");

token = resp.getAuthClientToken();
break;

default:
throw new VaultEncryptionConfigurationException("Invalid authentication type: " + getConfiguration().getAuthentication());
throw new VaultEncryptionConfigurationException("Invalid vault authentication type: " + getConfiguration().getAuthentication());
}

return buildVaultDriver(token);
Expand All @@ -260,7 +260,7 @@ private String doEncrypt(String plaintext) {
String path = "transit/encrypt/" + configuration.getKeyName();

LogicalResponse response = logicalWriteWithReauthentication(path, Collections.singletonMap("plaintext", encodedValue));
validateVaultOperationResponse(response, "Encrypt failed");
validateVaultOperationResponse(response, "Vault encrypt failed");

return response.getData().get("ciphertext");
}
Expand All @@ -269,7 +269,7 @@ private String doDecrypt(String ciphertext) {
LogicalResponse response = logicalWriteWithReauthentication(
"transit/decrypt/" + configuration.getKeyName(),
Collections.singletonMap("ciphertext", ciphertext));
validateVaultOperationResponse(response, "Decrypt failed");
validateVaultOperationResponse(response, "Vault decrypt failed");

String plaintext = response.getData().get("plaintext");

Expand Down Expand Up @@ -336,7 +336,7 @@ private LogicalResponse logicalReadWithReauthentication(final String path) {
resetDriver();
continue;
} catch (VaultException e) {
throw new VaultEncryptionOperationException("Logical read failed", e);
throw new VaultEncryptionOperationException("Vault logical read failed", e);
}

// If the response is permission denied
Expand All @@ -347,7 +347,7 @@ private LogicalResponse logicalReadWithReauthentication(final String path) {
}
}

throw new VaultEncryptionAuthenticationException("Permission denied and unable to reauthenticate");
throw new VaultEncryptionAuthenticationException("Permission denied and unable to reauthenticate vault read");
}

private LogicalResponse logicalWriteWithReauthentication(final String path, final Map<String, Object> nameValuePairs) {
Expand All @@ -359,7 +359,7 @@ private LogicalResponse logicalWriteWithReauthentication(final String path, fina
resetDriver();
continue;
} catch (VaultException e) {
throw new VaultEncryptionOperationException("Logical write failed", e);
throw new VaultEncryptionOperationException("Vault logical write failed", e);
}

// If the response is permission denied
Expand All @@ -370,6 +370,6 @@ private LogicalResponse logicalWriteWithReauthentication(final String path, fina
}
}

throw new VaultEncryptionAuthenticationException("Permission denied and unable to reauthenticate");
throw new VaultEncryptionAuthenticationException("Permission denied and unable to reauthenticate vault write");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ class VaultEncryptionServiceTest extends Specification {

then:
def ex = thrown(VaultEncryptionAuthenticationException)
ex.getMessage() == "Permission denied and unable to reauthenticate"
ex.getMessage() == "Permission denied and unable to reauthenticate vault write"
verify(subject, times(3)).resetDriver() || true
}

Expand All @@ -305,7 +305,7 @@ class VaultEncryptionServiceTest extends Specification {

then:
def ex = thrown(VaultEncryptionOperationException)
ex.getMessage() == "Logical write failed"
ex.getMessage() == "Vault logical write failed"
verify(subject, never()).resetDriver() || true
}

Expand Down Expand Up @@ -366,7 +366,7 @@ class VaultEncryptionServiceTest extends Specification {

then:
def ex = thrown(VaultEncryptionAuthenticationException)
ex.getMessage() == "Permission denied and unable to reauthenticate"
ex.getMessage() == "Permission denied and unable to reauthenticate vault write"
verify(subject, times(3)).resetDriver() || true
}

Expand All @@ -384,7 +384,7 @@ class VaultEncryptionServiceTest extends Specification {

then:
def ex = thrown(VaultEncryptionOperationException)
ex.getMessage() == "Logical write failed"
ex.getMessage() == "Vault logical write failed"
verify(subject, never()).resetDriver() || true
}

Expand Down

0 comments on commit 8208fb6

Please sign in to comment.