Protect service in Google cloud App service - google-app-engine

I have just deployed the first default service to my project in Google clouds App Engine.
Im going to deploy more services to the project and i want to use the default service as an api-gateway accessible to public and all the other services NOT to be accessible to public.
So the the other services should only be accessible from the default service(api-gateway).
Is this possible to set up and if so, how?

Related

How to communicate between Standard AppEngine to another Standard AppEngine within shared VPC?

I have standard app engine which makes an api call to another app engine within same shared VPC and project but the response is 403 forbidden error. Also the standard app engine to which i am making api call as gcloud app services update service-name --ingress=internal-only but as soon as i updated the configuration of the appEngine as gcloud app services update service-name --ingress=all. All the API calls are successfull.
Note : as required by gcp a serverless connector as been created and it is being used.
Questions
1 . How to communicate between Standard AppEngine to another Standard AppEngine within shared VPC?
2 . How can i communicate between AppEngnies with gcloud app services update service-name --ingress=internal-only configuration.
When you set the ingress to internal, you tell to App Engine: accept the traffic only coming from the VPCs of this project.
Thus, you need to tell to your other App Engine services: Reach this (App Engine) service only through the VPC else you will be forbidden.
Firstly, when you deploy on serverless environment, App Engine, Cloud Run or Cloud Functions, you are on the Google Cloud VPC, not on your project VPC.
Therefore, you have to set the egress to your App Engine to use the VPC. You need to plug a VPC connector to make this bridge between the GOOGLE serverless VPC world and your VPC.
However, it won't work. Indeed, when you set that on App Engine, only the traffic to the private IP use the serverless VPC connector, but not the public IPs. You haven't the capacity to set the VPC egress to all to route all the traffic through the VPC, public and private (as you can do with Cloud Functions and Cloud Run)
Thus, the App Engine, with serverless VPC connector or not, will contact the internal App Engine service through internet and not through the VPC and you will get a 403 every time.
In conclusion, you can't do that with App Engine, have a look to Cloud Run or Cloud Functions for this type of set up. You can also review your security design and don't rely on the origine of the traffic (from the VPC) but on the authentication of the traffic (use identity token and IAM service to ensure the communication security).
This is now possible to reach other App Engine services (configured with internal traffics only) thanks to Serverless VPC.
In app.yaml add to all the services which need to talk to each others (in and/or out connection):
vpc_access_connector:
name: projects/PROJECT_ID/locations/LOCATION/connectors/CONNECTOR
egress_setting: all-traffic
The doc : https://cloud.google.com/appengine/docs/standard/go/connecting-vpc.

Google Cloud Serverless VPC Connector not working for App Engine

I'm trying to set up a project with an App Engine service that talks to a Cloud SQL database with Private IP connectivity. This is achievable through the Serverless VPC Access of Google Cloud, that allows App Engine and Cloud Functions to interact with resources in your private VPC.
For some unexplicable reason, I was able to interrogate the DB from a test Cloud Function, but not from App Engine, where I get a connection refused error. Since it works on Cloud Functions, it makes me think that the Serverless VPC Access is properly configured, but I still can't understand why it doesn't work with App Engine.
The App Engine app is deployed using gcloud app deploy. I also tried gcloud beta app deploy as somebody suggested but nothing changed.
Everything (App Engine, Cloud Function, Cloud SQL) is in the same region, europe-west1. I am not using the gcloud default network but a custom network, with a single subnetwork in the same region.
If you have any remote idea on what could possibly be misconfigured, please let me know as I really am losing hope on this. Thanks!

How to serve multiple gcloud service with one domain

I have multiple gcloud services running for different tasks. Some use functions, some app-engine and one is a compute engine machine.
How can I serve all of theme with one public domain?
I imagine some kind of mapping or routing like :
example.de/auth => function A
example.de/wallet => app-engine default service
example.de/user => cloud run service
...
I've red that cloud endpoints is the pendant to aws AWS api-gateway.
But as far as I understand I cannot apply a domain to cloud endpoints in general.
What can I use to build such kind of facade (example.de domain)?
Google Cloud Endpoints are a service that can be run in a docker image, GKE, or Cloud Run.
If you are running Cloud Endpoinsts as a service in Cloudrun then you can configure the custom domain for the the cloud Run service following This Guide which how to add a mapping to a custom domain.

Custom service account for AppEngine

I would like to set separate permissions for different applications that run on GCP AppEngine.
I think, that the way to do this is by using specialized service accounts for each application.
As far as I understand, all applications run with the AppEngine default service account project#appspot.gserviceaccount.com
Is there a way to explicitly set a service account for an application which is running on AppEngine in GCP? Then I would be able to create separate service accounts with fine access restrictions.
tldr; you can do gcloud beta app deploy --service-account=<your_service_account> app.yaml
AppEngine app's identity are not restricted to the AppEngine default service account anymore. You can deploy with custom service account for each AppEngine app now by following https://cloud.google.com/appengine/docs/standard/python/user-managed-service-accounts#app.yaml.
This works for both AppEngine Standard and Flexible.
I am assuming you mean App Engine Standard. You only have one App Engine Standard per project.
You can have multiple services under App Engine.
You will need to create a service account and then load the service account inside your code. You can then change the default service account to have the minimum permissions required to function. Make sure you research what you are doing before changing permissions. You can break App Engine by being too restrictive.
However, that brings up security issues on how you manage and distribute the service account keys.
If you mean App Engine Flexible. Google does not even show the Flexible service account in the console as Google does not want you to modify it.
You have to just add the following code in your app.yaml file
service_account: {SERVICE_ACCOUNT_YOU_WANT_TO_USE_TO_ACCESS_APP_ENGINE}

Can Google App Engine make a http request to a Compute Engine instance within the same project without an external IP?

In App Engine I'd like to make http fetch calls to a web server running on an Compute Engine instance, created within the same Google cloud project, and I'm wondering if I can make such calls to the instance without enabling an external IP for it? Are App Engine and Compute Engine instances, from the same project, within the same network and can I call a Compute Engine instance by name from App Engine?
The best way to solve that in the short/medium term is to deploy the VM as a VM-based backend (we are accepting TT applications). You can deploy the VM backend as a different App Engine module of the app. Then you can urlfetch "mymodule.myapp.appspot.com" from the frontend and it will hit your VM without going through the public IP.
You can also serve your app straight from the VM backend. There you can load classes that are blocked by the normal App Engine sandbox (and well as have full access to all App Engine APIs!). The downside with VM backends is that we don't have auto-scaling yet.
This is currently unsupported. Communication between App Engine and GCE must go through the URLFetch API and use a public IP.

Resources