I'm trying to connect my Spring Application with maven as build tool to a postgres instance on my GCP project.
I had setup a postgres instance, generated client-key.pem, client-cert.pem & server-ca.pem, turned on ssl on those instances and added all those certs to my locally run project (src/main/resources/ssl).
So here's some application.properties that I've tried to connect to gcp with ssl
1.
spring.datasource.url= jdbc:postgresql://[[DATABASEIP]]:[[DATABASEPORT]]/[[DATABASENAME]]?sslmode=verify-ca&sslrootcert=/ssl/server-ca.pem&sslcert=/ssl/client-cert.pem&sslkey=/ssl/client-key.pk8
spring.datasource.username=[[DB_USERNAME]]
spring.datasource.password=[[DB_PASSWORD]]
2.
spring.datasource.url=jdbc:postgresql:///[[DATABASENAME]]?cloudSqlInstance=[gcp-project-id]:[region]:[instance-name]&socketFactory=com.google.cloud.sql.postgres.SocketFactory&user=[[DB_USERNAME]]&password=[[DB_PASSWORD]]
spring.datasource.continue-on-error=true
3.
spring.cloud.gcp.sql.enabled=true
spring.cloud.gcp.sql.database-name=[[DATABASENAME]]
spring.cloud.gcp.datastore.host=[[DATABASEIP]]
spring.cloud.gcp.sql.instance-connection-name=[gcp-project-id]:[region]:[instance-name]
spring.datasource.continue-on-error=true
None of them work
I've tried to find a github repo where I can see how to properly setup Spring Application to connect to GCP, found some, but none provided connecting with SSL
github.com - spring-cloud-gcp-sql-postgres-sample
spring-cloud-gcp documentation
It's not even listed on how to connect to PostgreSQL on Spring Cloud Documentation.
I've make sure that instance is working fine, connected it with those certs from Dbeaver, it connects. Connected from my Spring project with SSL turned off, everythings running fine. But once enable SSL, even authorizing all networks to connect (0.0.0.0/0), it failed to connect from my Spring applications.
Can someone give me some hint if I'm missing something on my configs, or any hint where I should look.
I would really appreciate if someone can provide me with an example repositories of how to connect to GCP instance with SSL. Where should I put all of those certs? How I should configure my GCP Instance?
Thanks in advance.
Configure SSL Database Connection to PostgreSQL on Google Cloud Instance from a Spring Application with Maven as build tool