Only allow connection to GCP Compute Engine VM originating from Cloud Run service
Mar 4
I have a DB server running as a Compute Engine VM, and an API running on Cloud Run. Both are part of the same project. I want the DB VM to only be accessible from the Cloud Run code.
At first I thought this should just work because the firewall has a "default-allow-internal" rule that should apply to every machine in the project. However I was still getting connection failures.
Then I tried adding a new ingress rule that targeted the service account and allowed connections from the service account. This also didn't work.
I modified the rule to allow connections from my personal IP just to confirm the DB VM was working and my firewall rules worked, and everything worked as expected.
Finally I looked into filtering by "source tag" but the option was not selectable and I couldn't seem to be able to add source tags to the Cloud Run instance.
Is it possible for me to achieve my goal of restricting access to the DB VM to only allow incoming connections from the Cloud Run machine?
1 answer
Accepted answer · original discussion
Sep 15
You can configure Serverless VPC Acces to connect Cloud Run with Compute Engine VM, updated Sep 2020. https://cloud.google.com/vpc/docs/configure-serverless-vpc-access
1 question comment
Use comments to ask for clarification. Post a solution as an answer.
Mar 4