The peering connection cloudsql-mysql-googleapis-com is not established when a Cloud SQL instance is configured to use Private IP - mysql

I have created a private Cloud SQL instance in an app project. The network used is a shared VPC and it is hosted in a network project.
In the shared VPC:
The private access connection is enabled
An automatic internal IP range has been allocated for private connection
A private connection has been created
If I go to the VPC Network > VPC Network Peering page, I don't see a peering connection named cloudsql-mysql-googleapis-com. Therefore, I cannot connect to my cloud SQL instance using its private IP address. I can only reach the cloud SQL instance using its public IP address.
The same infrastructure works for the development environment, I use terraform to generate the GCP resources. The two environments have exactly the same configuration.
Source code: https://gitlab.com/Chabane87/cloudsql-issue
Does anyone know when this problem can happen?
Thanks

Based on the discussion about this issue on our another support channel, it seems connectivity tests were run to zero in on the problem. While the connection from one of your instances to Cloud SQL succeeded using public IP, it failed when using private IP but that is the intended behaviour.
The Telnet test was conducted later using live traffic from the instance to Cloud SQL and found that a port is missing in the production environment while it is defined correctly in the development environment and hence it is confirmed there is no issue with the Networking. So, please try to connect to the Cloud SQL after adding the missing port to the prod project.

Related

How to connect SSMS from my local Windows machine to Google Cloud SQL Proxy which is running in GCP VM Instance?

I configured Cloud SQL instance with privateIP and the VM with service account credentials configured.
I could successfully connect to SQL server from VM instance to SQL instance(privateIP) using cloud proxy as follows,
./cloud_sql_proxy -instances=proj:us-central1:test-sql=tcp:5353 -credential_file=service.json
and from VM,
sqlcmd -S tcp:127.0.0.1,5353 -U sqlserver
All these working from VM and inside Google cloud.
How to archive the same connectivity from Local SSMS studio, and i have tried downloading cloud-sql-proxy for windows system, and calling with same,
cloud_sql_proxy.exe -instances=proj:us-central1:test-sql=tcp:5353 -credential_file=service.json
using credential file for authentication; email=test#proj.iam.gserviceaccount.com
Listening on 127.0.0.1:5353 for proj:us-central1:test-sql
Ready for new connections
And i try to connect the SSMS using below connection params,
Error from cloud_sql_proxy CMD:
couldn't connect to "proj:us-central1:test-sql": dial tcp <PRIVATE_IP>:3307: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
Any idea whats the problem and why am not able to connect from local machine with proper credentials file using SSMS? or do i missing any configurations?
As this documentation says, "When you configure a Cloud SQL instance to use private IP, you use private services access. Private services access is implemented as a VPC peering connection between your VPC network and the underlying Google services VPC network where your Cloud SQL instance resides". That means that only the Google network can access to the Private IP. However, you can use private services access to connect to Cloud SQL resources from external sources over a VPN tunnel or Cloud Interconnect to your VPC network. The topology should be like this
ON-PREMISE ----- VPN ----- Your GCP Project
So, have you checked if your VPN tunnel or your Cloud interconnect settings are right?
I would recommend you to take a look at here and be sure you have followed this:
1.- Ensure your VPC network is connected to the external network using a Cloud VPN tunnel or a VLAN attachment for Dedicated Interconnect or Partner Interconnect.
2.- Identify the peering connections produced by the private services connection:
* cloudsql-mysql-googleapis-com
* cloudsql-postgres-googleapis-com
* servicenetworking-googleapis-com
3.- Update all of the peering connections to enable Export custom routes.
4.- Identify the allocated range used by the private services connection.
5.- Create a Cloud Router custom route advertisement for the allocated range on the Cloud Routers managing BGP sessions for your Cloud VPN tunnels or Cloud Interconnect attachments (VLANs).

Connect to GCE Cloudsql instance via private IP

I am currently setting up my first GCE kubernetes cluster, having previously used mainly AWS for this.
Cluster is up and running and can access a local NFS server on the same compute engine VPC via private IP, so one stage of private network connection is fine.
Cloudsql server is running and can access this fine from the cluster if I open up public ip to the world.
Have enabled private ip address on the cloudsql which looks good, but I cannot ping or connect from the same container that can reach the public ip.
Cloudsql private ip is a different subnet which I believe is to be expected.
Checked VPC Network peering and got a relevant looking rule.
Checked VPC routes and got the matching peering route with next hop.
I have seen in docs that private ip is still beta, so guess potential to be a glitch beyond my control.
Also read up on running a proxy container inside each pod - hesitant to do this unless only option, app may end up across platforms so would prefer more standard config.
There's currently a requirement that the GKE cluster must be created with "VPC-Native" networking in order to access Cloud SQL via private IP. Unfortunately you need to re-create the cluster in order to make it VPC-Native.
https://cloud.google.com/kubernetes-engine/docs/how-to/alias-ips

Connect to new Google Cloud SQL (MySQL) 2nd Generation via VPN

The new Google Cloud SQL Engine creates its own VM instance to run a MySQL database, with an exposed public IP address. I was hoping that it would be possible to VPN into the Google Compute Cloud, then connect to the MySQL VM instance internally. Is this possible? The computer I am trying to connect from is a physical machine located outside of the cloud.
If it's not possible, what if I connect via VPN and use the public IP address to connect to the MySQL instance? Would it resolve to the internal network quickly and mimic the behavior of a local connection (no delay)? Or would it have the same performance as connected to the external IP address with no VPN in place?
Sorry, there's currently no VPN/private IP support for Cloud SQL. At the moment, you can use instance settings to control which IPs are allowed to connect. By default, the mysql server is locked down from all external connectivity.
Connecting through a VPN should not improve latency and may in fact hurt it depending on how things are setup. I would recommend doing your own test if that's something you wish to verify.
You can also use the Cloud SQL Proxy to connect externally which uses SSL certs to establish an SSL tunnel to MySQL.

Getting AppHarbor and AWS RDS MySql to play nice

I have an app with two workers (Web and Background) on AppHarbor that connect to a MySql database hosted on Amazon's RDS.
I keep getting "Unable to connect to any of the specified MySQL hosts." exception.
The RDS instance in the US-East region and I have added the following AppHarbor CIDR to the security group.
50.17.211.192/28
54.235.159.192/27
I have added my own CIDR to the security group and I connect to the instance just fine.
However when the app is running on AppHarbor it fails.
My connection string (censored) is:
Server=myinstanceXXXX.cykjvptrw5xs.us-east-1.rds.amazonaws.com;Database=MyDatabase;UID=XXXXXX;PWD=XXXXX;
I have tried including the port 3306 on the server endpoint but it made no difference.
Am I missing something on getting the two to play nice with one another?
By default AppHarbor use Amazon's internal DNS service for resolving hostnames. Because of that Amazon RDS instances in the same region as AppHarbor will resolve the private IP addresses rather than the public ones listed in the knowledge base article, so setting up rules based on the public IPs will not work most of the time.
In case Amazon's DNS service becomes unavailable we'll fail over to an external DNS service. This means you'll still have to configure the external IPs for the highest availability as an external DNS service will resolve the public IPs. This way you can ensure that your application is resilient towards DNS failures.
You can set up security group based access rules for your RDS security group. We've updated this knowledge base article with a section specifically for Amazon RDS where you can find the information necessary to set this up.

Google App script and local database connectivity

I have mysql server installed on my machine. I would like to connect to the same local mysql instance using Google app script's jdbc service. I am getting connection failed error. So, I would like to confirm:
1. is it possible to connect to mysql instance running on private machine(laptop) using jdbc service.
2. If not is it always mandatory to connect to public IP. What is the alternative to connect to mysql instance running on private machine.
This definitely works, but you need to permit Google's machines to connect to your machine. That means opening a hole in your firewall, possibly setting up port forwarding on your router, etc.
There is an alternative to poking a hole in your security arrangement, it is called Secure Data Connector, and it lets your machine initiate the connection to Google - https://developers.google.com/secure-data-connector/
Unfortunately, I don't believe that SDC supports JDBC yet (I believe it only supports HTTP based communication).
(P.S. One very simple work around is to mirror your local database to some kind of cloud service, and then permit access to that replica from Google).