GoogleCloudPlatform / GoogleCloudPlatform/spring-cloud-gcp
New secret format sm@ not properly working with postgres
- Dominant language
- Java
- Stars
- 551
- Forks
- 349
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 14
Description
I tried to migrate from sm:// to sm@ and all seemed fine until I tried to make an actual request. It looks like the db connection cannot be made anymore because of bad request:
```Unhandled exception, something went wrong while processing request
org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:313)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.startTransaction(AbstractPlatformTransactionManager.java:532)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:405)
at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:639)
...
Caused by: org.postgresql.util.PSQLException: Something unusual has occurred to cause the driver to fail. Please report this exception.
at org.postgresql.Driver.connect(Driver.java:321)
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:137)
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:360)
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:202)
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:461)
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:550)
at com.zaxxer.hikari.pool.HikariPool.(HikariPool.java:98)
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:111)
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:269)
... 158 common frames omitted
Caused by: com.google.cloud.sql.core.TerminalException: [] The Google Cloud SQL Admin API failed for the project ").",
"reason": "invalid"
}
],
"message": "Invalid request: instance name (bazz\">)."
}
```
Config:
```
spring.config.import=sm@
spring.cloud.gcp.sql.enable-iam-auth=true
spring.cloud.gcp.sql.enabled=true
spring.cloud.gcp.sql.database-name=${sm@db-name}
spring.cloud.gcp.sql.instance-connection-name=${sm@foo-db_instance_name}
spring.cloud.gcp.sql.jdbc.enabled=true
spring.cloud.gcp.sql.r2dbc.enabled=false
```
Version used is **6.1**.
Will just revert back to using sm://, looks like the new variant is not stable enough yet.
From just glancing over the error it looks like it tries to make the request with the byte object, instead of the string.
Contributor guide
Research direction
Reproduce with the listed spring.config.import=sm@ and Cloud SQL properties, then compare the sm@ and sm:// paths at the PostgreSQL Driver.connect and DataSource connection flow. Trace how the secret values reach spring.cloud.gcp.sql.instance-connection-name and database-name; done means the Cloud SQL Admin API receives plain string values and the JDBC connection succeeds.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- gcp, java, postgresql, spring
- Domain
- backend, cloud, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100