gpt4 book ai didi

spring-boot - 是否可以将 Spring Boot 应用程序部署到 App Engine 并连接到数据库?

转载 作者:太空宇宙 更新时间:2023-11-03 15:22:58 26 4
gpt4 key购买 nike

我觉得我在这里兜圈子,所以,请多多包涵。我想将我的 Spring Boot 应用程序部署到 App Engine,但与 simple sample Google provides 不同,我的,需要一个数据库,这意味着凭据。我在 Google App Engine 的标准版上运行 Java 11。

我设法通过在 application.properties 中添加这个来使我的应用程序成功连接:

spring.datasource.url=jdbc:postgresql://google/recruiters_wtf?cloudSqlInstance=recruiters-wtf:europe-west2:recruiters-wtf&socketFactory=com.google.cloud.sql.postgres.SocketFactory&user=the_user&password=monkey123

问题是我不想向存储库提交任何凭据,因此,这是 Not Acceptable 。我可以使用环境变量,但我必须在 app.yaml 文件中定义它们。我要么保留一个部署所需的未提交的 app.yaml 文件,这很麻烦,要么我提交它,然后我回到原点,将凭据提交到存储库。

因为显然Google App Engine cannot have environment variables defined in any other way ( unlike Heroku ),这是否意味着不使用一些不安全/繁琐的做法就不可能将 Spring Boot 应用程序部署到 App Engine 并让它连接到数据库?我觉得我在这里遗漏了一些东西。

最佳答案

根据我对您所描述内容的理解,您实际上希望将在 Google App Engine 上运行的 Spring boot 应用程序连接到数据库,而不暴露敏感信息。如果是这样的话,我就能找到 Cloud KMS为用户提供 secret 管理的能力。具体来说,在构建或运行时需要少量敏感数据的应用程序称为 secrets .这些 secret 可以用对称 key 加密和解密。在您的情况下,您可以将数据库凭据存储为 secret 。您可能会找到加密/解密 secret 过程的更多详细信息 here .

他们目前是three ways to manage secrets :

  1. Storing secrets in code, encrypted with a key from Cloud KMS. This solution is implementing secrets at the application layer.
  2. Storing secrets in a storage bucket in Cloud Storage, encrypted at rest. You can use Cloud Storage: Bucket to store your database credentials and can also grant that bucket a specific Service Account. This solution allows for separation of systems. In the case that the code repository is breached, your secrets would themselves may still be protected.
  3. Using third-party secret management system.

就存储 secret 本身而言,我发现以下步骤概述了 here对此非常有用。本指南将指导用户在 Cloud Storage 存储桶中设置和存储 secret 。 secret 在应用层使用来自 Cloud KMS 的加密 key 进行加密。鉴于您的用例,这将是一个很好的选择,因为您的 secret 将存储在存储桶中而不是 app.yaml 文件中.此外,存储在存储桶中的 secret 将使您能够使用服务帐户角色限制对它的访问。

从本质上讲,您的应用需要对 Google Cloud Storage 执行 API 调用才能下载包含 key 的 KMS 加密文件。然后它将使用 KMS 生成的 key 解密文件,以便能够读出密码并使用它手动连接到数据库。添加这些额外的步骤将实现更多的安全层,这是“'Note: Saving credentials in environment variables is convenient, but not secure - consider a more secure solution such as Cloud KMS to help keep secrets safe.”中提到的整个想法。 '” 在 Cloud SQL 的 Google 示例存储库中。

希望对您有所帮助!

关于spring-boot - 是否可以将 Spring Boot 应用程序部署到 App Engine 并连接到数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58498281/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com