Чтобы ограничить доступ из приложения-службы2 к приложению-службе1, но не к общедоступным c, необходимо использовать конечные точки облака. Чтобы сделать это, выполните следующие шаги:
1) Вам необходимо создать файл openapi-appengine.yaml, идущий в облачные конечные точки. Настройте его следующим образом:
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) Затем go для службы App2: - добавьте имя своей службы в файл app.yaml:
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
Замените ENDPOINTS-SERVICE-NAME на имя вашей службы конечных точек. Это то же имя, которое вы указали в поле хоста вашего документа OpenAPI. Например:
endpoints_api_service: name: example-project-12345.appspot.com rollout_strategy: managed
3) Наконец, продолжите это Официальная документация для аутентификации между сервисами.