0
votes

I am trying to establish SSL connection between spring boot application and GCP MySQL instance. For that have generated and downloaded 'client-cert.pem', 'client-key.pem' and 'server-ca .pem' from GCP. Followed below steps:

Step 1: generated 'my-cert.p12' file

openssl pkcs12 -export -in client-cert.pem -inkey client-key.pem -out my-cert.p12 

Step 2 : imported 'my-cert.p12' file

keytool -importkeystore  -srckeystore D:\my-cert.p12 -destkeystore ./cacerts -srcstoretype PKCS12 -deststorepass changeit

setp 3 : converted 'server-ca.pem' to 'server-ca.der'

openssl x509 -in server-ca.pem -inform pem -out server-ca.der -outform der

step 4 : imported 'server-ca.der' keytool -importcert -alias gcp-mysql-ca -keystore ./cacerts -storepass changeit -file D:\server-ca.der

step 5: configured spring boot application.properties file:

spring.datasource.url= jdbc:mysql://xxx.xxx.xxx.xxx:3306/xxx?useUnicode=true&characterEncoding=utf8&useSSL=true&requireSSL=true

When I run spring boot application, getting below exception:

Caused by: java.sql.SQLException: Access denied for user 'root'@'XXX.XXX.XXX.XX' (using password: YES)

Can anyone suggest a good way to install GCP MySQL SSL certificate and configure it in Spring Boot application?

1

1 Answers

0
votes

Have you considered using the Spring Cloud GCP SQL integration? You could use a Google OAuth2 credential and Spring Cloud GCP would take care of the rest.

https://github.com/spring-cloud/spring-cloud-gcp

https://docs.spring.io/spring-cloud-gcp/docs/1.0.0.M2/reference/htmlsingle/#_spring_jdbc