保护 Compute Engine 上的 MySQL 服务器

Protect MySQL Server on Compute Engine

我在 App Engine 标准环境中有一个应用程序 运行,但数据库位于 Compute Engine 实例上。 App Engine 标准环境没有我可以在 Compute Engine 实例上列入白名单的静态 IP。 让 App Engine 访问数据库的唯一方法是允许所有 IP 连接到它,这可能是一个糟糕的主意。 由于定价因素,我想将该应用程序保留在 App Engine 标准环境中,而不使用 CloudSQL。 由于 SQL 服务器对所有 IP 开放,我还有哪些其他方法可以保护它。

要从 App Engine 应用程序直接连接到 Compute Engine 实例,我建议查看 Serverless VPC Access。请求通过您的应用程序通过无服务器 VPC 访问发送到您实例的内部 IP。

Steps to create the connector:

gcloud components update

gcloud services enable vpcaccess.googleapis.com

gcloud compute networks vpc-access connectors create CONNECTOR_NAME --network=VPC_NETWORK --region=REGION --range=IP_RANGE

确保您拥有适当的权限并且设置了不重叠的 IP 范围。

然后将以下代码添加到您应用的 yaml 文件中并部署您的应用。

vpc_access_connector:
  name: "projects/PROJECT_ID/locations/REGION/connectors/CONNECTOR_NAME"

您还可以查看配置 VM as a network proxy. In this situation you would have one VM that is open to the internet and with that VM you can securely connect to your database instance