# GCP - Cloud Run SpringBoot Connect Cloud SQL (PostgreSQL) With SSL Certification ###### tags: `Cloud` > Referrer: [Stack Overflow Issue - Spring Boot connection to Postgresql with SSL](https://stackoverflow.com/questions/54257758/spring-boot-connection-to-postgresql-with-ssl) 使用springboot專案,連線至 Google Cloud SQL (PostgreSQL),此文件只介紹配置,不介紹springboot專案內容 ## 1. 創建新的Cloud SQL Instance。配置不說明 ## 2. 將Connections/Security中的 Allow only SSL connections開啟,需等待一段時間 ![](https://i.imgur.com/H80A5F2.png) ## 3. 建立新的憑證 ![](https://i.imgur.com/cCkpWEv.png) ## 4. 填寫名稱後建立 ![](https://i.imgur.com/YlPEHqN.png) ## 5. 有兩個檔案都下載(client-key.pem、client-cert.pem) ![](https://i.imgur.com/1ar9Qa9.png) ## 6. 接下來client-key.pem檔案使用openssl轉換成 pk8檔案 (必要) ``` sudo openssl pkcs8 -topk8 -inform PEM -outform DER -in client-key.pem -out client-key.pk8 -nocrypt ``` ## 7. 配置postgreSQL到application.properties檔案中 ``` spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect spring.jpa.hibernate.ddl-auto=none spring.jpa.hibernate.show-sql=true spring.datasource.url=jdbc:postgresql://${server-ip}:${db-port}/${db-name}?sslmode=require&sslkey=${path}/client-key.pk8&sslcert=${path}/client-cert.pem spring.datasource.username=${postgresql-user} spring.datasource.password=${postgresql-pwd} ``` ## 8. 使用postman測試 ![](https://i.imgur.com/hD92nFt.png)