Skip to content

Conversation

@karenc-bq
Copy link
Contributor

Summary

Unwrap nested exceptions in AWS Secrets Manager Plugin when checking if the error is caused by invalid credentials

Description

Additional Reviewers

@sergiyvamz

…king if the error is caused by invalid credentials
@karenc-bq karenc-bq self-assigned this Sep 15, 2022
@karenc-bq karenc-bq marked this pull request as ready for review September 15, 2022 21:33

Throwable throwable = exception;
while (throwable != null) {
if (throwable instanceof SQLException) {
Copy link

@kaddybrar08 kaddybrar08 Sep 16, 2022

Choose a reason for hiding this comment

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

The internal exception which is wrapped in java.sql.SQLNonTransientConnectionException is of Type :- software.aws.rds.jdbc.mysql.shading.com.mysql.cj.exceptions.CJException.
This exception extends RuntimeException and not SQLException, therefore, the internal exception will be skipped and secrets won't get rotated.

The custom codefix which I tested :-
private boolean isLoginUnsuccessful(SQLException exception) { this.logger.logTrace("Login failed. SQLState=" + exception.getSQLState(), exception); Throwable t = exception; do { if (t instanceof SQLException) { if (((SQLException) t).getSQLState().equals(SQLSTATE_ACCESS_ERROR)) { return true; } } if (t instanceof CJException) { if (((CJException) t).getSQLState().equals(SQLSTATE_ACCESS_ERROR)) { return true; } } t = t.getCause(); } while (t != null); return false; }

image

-- Anmolpreet Singh (Chegg Inc)

@karenc-bq karenc-bq merged commit 49b2344 into main Sep 16, 2022
@karenc-bq karenc-bq deleted the unwrap_exceptions branch September 16, 2022 22:52
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.

3 participants