问题描述
对于GCP中托管的API,我计划借助带有私钥和API网关的服务帐户来对消费服务(来自外部gcp环境)进行身份验证。
对于一个服务帐户(service-account-1
)都可以正常使用,即:
paths:
/hello:
get:
#...
security:
- service_account-1: []
securityDeFinitions:
service_account-1:
authorizationUrl: ""
flow: "implicit"
type: "oauth2"
x-google-issuer: "{service-account-1}@{project-id}.iam.gserviceaccount.com"
x-google-jwks_uri: "https://www.googleapis.com/robot/v1/Metadata/x509/{service-account-1}@{project-id}.iam.gserviceaccount.com"
x-google-audiences: "{project-id}"
但是我如何描述它,以便该项目中的任何服务帐户都可以访问?
编辑:我想避免每次创建新服务帐户并需要允许访问时在API网关上更新openapi配置。
解决方法
根据官方文档:
Authentication between services
您可以在API配置中定义多个安全性定义,但是 每个定义必须具有不同的x-google-issuer。如果你有 为每个呼叫服务创建单独的服务帐户,您可以 为每个服务帐户创建一个安全定义,例如:
securityDefinitions:
service-1:
authorizationUrl: ""
flow: "implicit"
type: "oauth2"
x-google-issuer: "[email protected]"
x-google-jwks_uri: "https://www.googleapis.com/robot/v1/metadata/x509/[email protected]"
service-2:
authorizationUrl: ""
flow: "implicit"
type: "oauth2"
x-google-issuer: "[email protected]"
x-google-jwks_uri: "https://www.googleapis.com/robot/v1/metadata/x509/[email protected]"
因此,您必须创建多个安全性定义。