To restrict access from Service app2 to service app1, but not to general public, you have to use Cloud Endpoints. In order to do it, follow the next steps:
1) You've to create an openapi-appengine.yaml file going to Cloud Endpoints. Configure it as following:
swagger: '2.0'
info:
title: Cloud Endpoints
description: Sample API on Cloud Endpoints with a Cloud Run backend
version: 1.0.0
host: endpoint-service.appspot.com ---> you've to put your service URL
x-google-allow: all
schemes:
- https
produces:
- application/json
paths:
/resdticted-endpoint-1: --> Here you've to put all the endpoints you want to restrict
get:
summary: Greet a user
operationId: hello
responses:
'200':
description: A successful response
schema:
type: string
security:
- DEFINITION_NAME: []
/resdticted-endpoint-2:
get:
summary: Greet a user
operationId: hello
responses:
'200':
description: A successful response
schema:
type: string
security:
- DEFINITION_NAME: []
securityDefinitions:
DEFINITION_NAME:
authorizationUrl: ""
flow: "implicit"
type: "oauth2"
x-google-issuer: "SA_EMAIL_ADDRESS" --> Here you've to add a Service Account, in case you don't have any, create a new one
x-google-jwks_uri: "https://www.googleapis.com/robot/v1/metadata/x509/SA_EMAIL_ADDRESS" --> put your service account name at the end
2) Then, go to App2 service:
- Add your service name to the app.yaml file:
endpoints_api_service:
# The following values are to be replaced by information from the output of
# 'gcloud endpoints services deploy openapi-appengine.yaml' command.
name: ENDPOINTS-SERVICE-NAME
rollout_strategy: managed
Replace ENDPOINTS-SERVICE-NAME with the name of your Endpoints service. This is the same name that you configured in the host field of your OpenAPI document. For example:
endpoints_api_service:
name: example-project-12345.appspot.com
rollout_strategy: managed
3) Finally continue this Official Documentation in order to authenticate between services.