Skip to content

Commit

Permalink
Add PostgreSQL error code 28000 to authentication errors (#223)
Browse files Browse the repository at this point in the history
* PostgreSQL Error Code 28000 is also considered as an authentication error

PostgreSQL Error Code 28000 is also considered as an authentication error in order to trigger secret refresh (together with 28P01 - invalid_password)

PostgreSQL Error Code 28000 (invalid_authorization_specification) is the error code returned by RDS Proxy when the secret is rotated in alternating user mode: refreshing the secret cache would address the issue #222.

* Fix formatting

---------

Co-authored-by: Simon Marty <[email protected]>
  • Loading branch information
canelzio and simonmarty authored Jan 29, 2024
1 parent 4e6b76f commit 59d1f4e
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ public final class AWSSecretsManagerPostgreSQLDriver extends AWSSecretsManagerDr
*/
public static final String ACCESS_DENIED_FOR_USER_USING_PASSWORD_TO_DATABASE = "28P01";

/**
* The error code returned by RDS Proxy when the secret is rotated in alternating user mode.
*
* See <a href="https://www.postgresql.org/docs/current/errcodes-appendix.html">PosgreSQL documentation</a>.
*/
public static final String ACCESS_DENIED_FOR_INVALID_AUTHORIZATION_SPECIFICATION = "28000";

/**
* Set to postgresql.
*/
Expand Down Expand Up @@ -106,7 +113,7 @@ public boolean isExceptionDueToAuthenticationError(Exception e) {
if (e instanceof SQLException) {
SQLException sqle = (SQLException) e;
String sqlState = sqle.getSQLState();
return sqlState.equals(ACCESS_DENIED_FOR_USER_USING_PASSWORD_TO_DATABASE);
return sqlState.equals(ACCESS_DENIED_FOR_USER_USING_PASSWORD_TO_DATABASE) || sqlState.equals(ACCESS_DENIED_FOR_INVALID_AUTHORIZATION_SPECIFICATION);
}
return false;
}
Expand Down

0 comments on commit 59d1f4e

Please sign in to comment.