Google cloud platform 为最终用户和其他服务保护云运行服务

Google cloud platform 为最终用户和其他服务保护云运行服务,google-cloud-platform,firebase-authentication,google-cloud-run,Google Cloud Platform,Firebase Authentication,Google Cloud Run,我有一组云运行的服务,它们需要能够通过Firebase auth接收最终用户的请求,但也可以接收彼此的请求。我知道如何使用ID令牌对最终用户进行身份验证。但是,我不确定如何对服务之间的请求进行身份验证。关于服务到服务调用的教程使用私有服务,但我需要将服务设置为“unauthenticated requests”以允许用户请求,因此我不确定如何从google auth library验证令牌。有人对处理此问题的最佳方法有什么想法吗?如果您有两种类型的身份验证,则需要两个端点。如果您使用Fireba

我有一组云运行的服务,它们需要能够通过Firebase auth接收最终用户的请求,但也可以接收彼此的请求。我知道如何使用ID令牌对最终用户进行身份验证。但是,我不确定如何对服务之间的请求进行身份验证。关于服务到服务调用的教程使用私有服务,但我需要将服务设置为“unauthenticated requests”以允许用户请求,因此我不确定如何从google auth library验证令牌。有人对处理此问题的最佳方法有什么想法吗?

如果您有两种类型的身份验证,则需要两个端点。如果您使用Firebase Auth,那么您可以使用API网关(或云端点)(我在这一点上对云端点进行了说明,但它与API网关类似)和。并将您的云运行服务设置为受保护,每次都需要ID令牌

或者,您需要2个云运行服务。第一个接受来自用户的请求并在“允许未经身份验证”中设置,它将有效请求(在用户验证后)转发到以保护模式部署的第二个云运行,仅使用经过身份验证的请求(来自所有云运行服务)调用


使用此代码和JWT令牌,您基本上是在调用另一个云服务(在您的情况下,是另一个云运行服务)。

因此,如果我使用带有firebase安全定义的API网关,我就不能在网关后面的服务之间发送请求了?如果所有云运行的服务都是私有的,它们难道不能同时对网关和彼此负责吗?我想我可以授予他们两个IAM中的“调用者”角色。非常感谢您的帮助。请求将从API网关转发到后端(您的云运行)。来自API网关的调用使用API网关本身生成的ID_令牌进行身份验证。您不能使用IAM调用者角色对firebase用户进行授权,这不是Google帐户。服务还使用身份令牌对云运行进行身份验证。
def auth_and_trigger(self):
#the other cloud run url you wanna trigger
receiving_service_url = 'https://cloudrun-url-uc.a.run.app/download'

# Set up metadata server request
# See https://cloud.google.com/compute/docs/instances/verifying-instance-identity#request_signature
metadata_server_token_url = 'http://metadata/computeMetadata/v1/instance/service-accounts/default/identity?audience='

token_request_url = metadata_server_token_url + receiving_service_url
token_request_headers = {'Metadata-Flavor': 'Google'}

# Fetch the token
token_response = requests.get(token_request_url, headers=token_request_headers)
jwt = token_response.content.decode("utf-8")

# Provide the token in the request to the receiving service
receiving_service_headers = {'Authorization': f'bearer {jwt}'}

try:
   service_response = requests.post(url=receiving_service_url,
                                 json={'okay':'bro'},
                                 headers=receiving_service_headers
                                 )
logging.info(service_response.content)

except Exception as error:
    logging.error(error)