I am trying to restrict access to a specific App Engine Flex service in a project with multiple services using VPC firewall rules. I created a VPC network called "vpc" using automatic subnet creation and global dynamic routing. Next, I deployed my App with the following yaml file (names slightly changed):

runtime: custom
env: flex
service: someservice
    instances: 1
    cpu: 1
    memory_gb: 4.0
    disk_size_gb: 10
    cloud_sql_instances: cloud
    name: vpc

As you can see, I specified a network in the yaml file to run the app in vpc. Then, I created two firewall rules in VPC to allow access to only specific IPs. I first created a firewall rule called "deny" to deny access to the vpc network for all IP ranges:

gcloud compute firewall-rules create deny \
    --network vpc \
    --action deny \
    --direction ingress \
    --rules tcp \
    --source-ranges \
    --priority 5000

Finally, I created another rule named "allow" to allow a single IP address (e.g.

gcloud compute firewall-rules create allow \
    --network vpc \
    --action allow \
    --direction ingress \
    --rules tcp \
    --source-ranges \
    --priority 1000

However, after performing the above I am still able to access the app engine service from pretty much any IP I tested (used my phone's data and also asked friends for sanity check). What am I doing wrong? Any help is greatly appreciated!

Note: similar problem: https://stackoverflow.com/questions/49296666/google-app-engine-firewall-restrict-access-to-all-services-but-the-default-one


I would suspect that there is a more permissive firewall rule already in place, or one with a higher priority than the ‘deny all’ you manually created. By default any created firewall rules have a priority of 1000, firewall rule priority is an integer from 0 to 65535, inclusive. Lower integers indicate higher priorities. If you do not specify a priority when creating a rule, it is assigned a priority of 1000. A priority of 1000 is a higher priority than your ‘deny all’ rule with priority 5000.

You have at least a couple options to test this:

  • One, would be to set your ‘deny all’ rule to a higher priority (e.g. 900) and then retest the connections, increasing the ‘deny all’ priority as need be, this is an easily accomplished but not great option.

  • Two, would be from the Cloud Platform console, Select VPC network -> VPC Networks. Click/Select the name of the VPC you are working with, then select the “Firewall rules” tab. This will list all firewall rules currently active for this VPC. Go through the list and look for a higher priority (lower integer value) rule which is more permissive (perhaps even allow all) than your ‘deny all’ rule. Then remove that rule or change the priority to a lower priority than your ‘deny all’ rule.


according to the docs you source ranges must be in CIDR format or is implied - your source address is not in CIDR notation --source-ranges is not a range


or a.b.c.d/ - depending on how glcoud implements that

just had a look, it's implemented like so --source-ranges

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.