15

I'm looking through Google Cloud Functions docs and I wonder if it is possible to restrict access to HTTP cloud function to the given network? I would like to avoid anyone to exhaust the free quota.

Is there any firewall rules or similar mechanism for Cloud Functions?

Nicholas
  • 501
  • 2
  • 14
Evgeny Timoshenko
  • 3,119
  • 5
  • 33
  • 53
  • 2
    GCF now supports IAM and it seems possible to control access to the functions https://cloud.google.com/functions/docs/securing/authenticating – Evgeny Timoshenko Jun 28 '19 at 15:58
  • possible dupe https://stackoverflow.com/questions/43238611/secure-http-trigger-for-cloud-functions-for-firebase – giorgio79 May 16 '21 at 17:56

5 Answers5

2

I don't believe there is any in-built security restrictions at the moment.

In terms of avoid quota exhaustion you could pass a header or parameter with some kind of shared secret. Even a fixed string value would help avoid this problem.

2

You can add authentication to a cloud function by using firebase authentication. Here's a github example of how to do to it: https://github.com/firebase/functions-samples/tree/master/authorized-https-endpoint

Note however that the authentication code is executed by your function, so rejecting unauthorized access would still consume a small portion of your free resource allowance.

Aaron
  • 666
  • 1
  • 7
  • 23
1

The Google Function Authorizer module might be what you're looking for. It provides "a simple user authentication and management system for Google Cloud HTTP Functions." It doesn't seem to have a lot of users yet, but the project seems simple enough that you could at least use it as a basis to modify or implement your own solution if you prefer.

Darren
  • 1,846
  • 15
  • 22
1

This article was helpful for me.

https://cloud.google.com/solutions/authentication-in-http-cloud-functions

Anyone can still invoke the function but it must contain credentials from a user that has access to the resources accessed by the function.

Before that I was doing something very simple that is probably not great for production but does provide a little bit more security that just leaving it open publicly. I call my function with a password in the payload and if it doesn't match one of the passwords I hardcoded on the function it just fails with a 403.

Eduardo
  • 22,574
  • 11
  • 76
  • 94
0

If you need to restrict to IP range then you can follow instructions here: https://sukantamaikap.com/posts/load-balancing-cloud-functions
The UI of Google Cloud has unfortunately changed and you need to do some searching before you get all done, but I managed to set it up. But note that the related services will cost roughly 25 eur per month at minimum.

You can estimate the pricing here: https://cloudpricingcalculator.appspot.com/
You need to search for "Cloud Load Balancing and Network Services" and then enable "Cloud Load Balancing", "Google Cloud Armor", and "IP addresses".

Alternatively, in some cases it might be sufficient if you set the name of the function or some suffix to the name complex enough so that it will be effectively like a sort of password. Something like MyGoogleCloudFunc-abracadabra. Then it will not restrict the network but perhaps outsiders would not know the secret name anyway.

Roland Pihlakas
  • 4,246
  • 2
  • 43
  • 64