aws / aws-secretsmanager-jdbc

The AWS Secrets Manager JDBC Library enables Java developers to easily connect to SQL databases using secrets stored in AWS Secrets Manager.
Apache License 2.0
161 stars 77 forks source link

AWSSecretsManagerPostgreSQLDriver incorrectly constructs URL when dbname is missing #208

Closed JacobAMason closed 1 year ago

JacobAMason commented 1 year ago

Describe the bug

According to the postgres driver, jdbc urls need to end with a forward slash: https://github.com/pgjdbc/pgjdbc/blob/5c9928d81e4a337518c1e1104ea17f4b29269320/pgjdbc/src/main/java/org/postgresql/Driver.java#L567

However, AWSSecretsManagerPostgreSQLDriver only appends the forward slash if a dbname is found in the secret: https://github.com/aws/aws-secretsmanager-jdbc/blame/42dc301cc7e1a47b148f8526392be9fe8ecdaff2/src/main/java/com/amazonaws/secretsmanager/sql/AWSSecretsManagerPostgreSQLDriver.java#L119

Despite RDS Postgres db instances always having a default postgres database if no db name is specified, secrets created from such db instances do not contain the dbname json property.

To Reproduce

  1. Create an RDS Postgres instance without providing a dbname
  2. Create a Secrets Manager secret to access this database.
  3. Connect to the database using AWSSecretsManagerPostgreSQLDriver. Use the driver's connect method and pass the secret ARN for the URL.

Expected behavior I think the proper behavior should be to append the forward slash always and then append the db name if it exists.