I’m trying to understand what the correct way to configure a a firewall rule that allows a Cloud Run service to connect to a VM on the same VPC, via internal IPs, using Direct VPC Egress preferably using network tags.
The only configuration that I can find that works is an Ingress rule with a target of the VM IP and a source of the entire subnet.
Initially I had configured an Ingress rule with a target filter on the VM service account and a source filter on the Cloud Run service account. This resulted in very strange behavior where the first container scheduled could always communicate, but subsequently created containers on cloud run would usually not be able to communicate.
Reviewing documentation I see that this setup is listed as not supported:
https://cloud.google.com/run/docs/configuring/vpc-direct-vpc#gcloud_2:~:text=Using%20service%20identity%20as%20the%20source%20service%20account%20in%20ingress%20firewall%20rules%20applied%20to%20the%20destination%20resource.
The strange non-deterministic behavior threw me off.
Further reviewing the docs I see that an Egress rule with tags is supposed to be supported:
https://cloud.google.com/run/docs/configuring/vpc-direct-vpc#terraform:~:text=In%20the%20egress%20firewall%20rule%2C%20refer%20to%20your%20service%20or%20job%20by%20using%20the%20linked%20service%20account%20service%20identity%2C%20the%20subnet%27s%20IP%20range%2C%20or%20the%20associated%20network%20tags.
However when testing this method, I again see strange behavior where some requests from the Cloud Run service are logged as ‘allow’ on the firewall rules, but generally the cloud run service is unable to hit the VM.
Is this a Cloud Run Direct VPC egress bug, or is there some configuration that is required that is not clear from the docs?