google-cloud-platform - Google Cloud API Gateway 对多个服务帐号进行身份验证
问题描述
对于托管在 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 配置。
更新:我最终使用 Identity-Aware Proxy 来保护 API,只允许授权的服务帐户。
解决方案
根据官方文档:
您可以在 API 配置中定义多个安全定义,但每个定义必须具有不同的 x-google-issuer。如果您为每个调用服务创建了单独的服务帐户,则可以为每个服务帐户创建一个安全定义,例如:
securityDefinitions:
service-1:
authorizationUrl: ""
flow: "implicit"
type: "oauth2"
x-google-issuer: "service-1@example-project-12345.iam.gserviceaccount.com"
x-google-jwks_uri: "https://www.googleapis.com/robot/v1/metadata/x509/service-1@example-project-12345.iam.gserviceaccount.com"
service-2:
authorizationUrl: ""
flow: "implicit"
type: "oauth2"
x-google-issuer: "service-2@example-project-12345.iam.gserviceaccount.com"
x-google-jwks_uri: "https://www.googleapis.com/robot/v1/metadata/x509/service-2@example-project-12345.iam.gserviceaccount.com"
因此,您必须创建多个安全定义。
推荐阅读
- powershell - 使用 Get-AzureADUser 从 PowerShell 中的“SMTP:email@domain.com”中删除“SMTP”
- java - 为 robot.keyPress(java.awt.event.KeyEvent.VK_something) 生成 VK_something 动态
- hl7 - 通过 Mirth 使用 MDHT 提取 CCD 文档值
- python - groupby 的替代方案,用于从整洁的 pandas DataFrame 生成汇总表
- javascript - 延迟几秒钟后从一个站点重定向到另一个站点 url
- linux - 强制linux排序使用字典顺序
- wordpress - 视觉和 html 文本编辑器,Wordpress 中的缺失/白色文本
- angular - TypeScript 反序列化未按预期工作
- javascript - 等式为零
- sql - 如何从行中的每月数据生成视图,将其转换为 Oracle 表中的列