Is it possible to connect to Google Cloud SQL from a Google Managed VM?

可紊 提交于 2019-12-05 01:51:42

问题


Is it possible to connect to Google Cloud SQL from a Google Managed VM? With regular Google App Engine applications, I can connect by authorizing my project in the Cloud SQL console and using unix_socket='/cloudsql/' + _INSTANCE_NAME. However, the /cloudsql/ socket doesn't seem to be available on Managed VMs. Do I have to whitelist the IP of my Managed VM application? If so, how do I find the IP address to whitelist?


回答1:


The /cloudsql/ sockets are only available in regular App Engine. Managed VMs are regular VMs so connection to Cloud SQL needs to use the external IP of that Cloud SQL instances. The external IP needs to be whitelisted. The external IP is showed in the Developers Console and can also be retrieved via gcloud CLI tool.

Two options to avoid having to whitelist the IP of the GCE VMs are:

  1. Switch to use only SSL connections for IP connectivity and whitelist 0.0.0.0/0.
  2. Funnel all the traffic to Cloud SQL via a VM that runs a TCP proxy (HAProxy) for example.

We are aware that none of these are very satisfying solutions. :-(




回答2:


If you're willing to try out Cloud SQL Second Generation (currently in Beta), there's built-in support for connecting from Managed VMs that is similar to App Engine: https://cloud.google.com/sql/docs/sql-proxy#gae




回答3:


Everything is described here depends on language: https://cloud.google.com/sql/docs/dev-access more details with pythons are here:

subject: Step 2: Grant your App Engine application access to the Google Cloud SQL instance https://cloud.google.com/appengine/docs/python/cloud-sql/




回答4:


Concerning the first solution provided by @Razvan Musaloiu-E

Switch to use only SSL connections for IP connectivity and whitelist 0.0.0.0/0.

Are there any security concerns if I do this ? Besides from having a "root"/"root" login/pasword on my Cloud SQL database of course...



来源:https://stackoverflow.com/questions/27573161/is-it-possible-to-connect-to-google-cloud-sql-from-a-google-managed-vm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!