【问题标题】:How do I get Public Key of a User Managed Service account in Google Cloud Platform如何在 Google Cloud Platform 中获取用户托管服务帐户的公钥
【发布时间】:2026-01-28 06:25:02
【问题描述】:

我正在使用 Google Cloud Scheduler 调用外部应用程序。 Google Cloud Scheduler 使用 OIDC 身份验证并使用服务帐户。我只能从 Google 服务帐户 UI 控制台页面获取服务帐户的私钥。如何公开该用户管理的服务帐户?

我通过在此处粘贴 Bearer 令牌找到了此服务帐户的公钥:https://jwt.io/

但是,这是获取服务帐户公钥的唯一方法吗?有没有其他方法可以得到这个? (如图书馆等)?有什么方法可以从 Google utils 或 gcloud 或 Google 控制台获取此信息?

其中一个网站提到“公钥可以广泛分发,因此令牌的每个消费者都可以验证其完整性。” .那么,这个 Google 服务帐户的公钥分发到哪里?是否有存储所有 Google 服务帐户公钥的服务器/位置?

此外,还有一个选项可以将公钥嵌入到 jwt 令牌中。如果我从谷歌云调度程序获得不记名令牌,我怎么知道它是否嵌入了公钥?还是分布式公钥?

提前感谢您的支持!

问候

PS:我阅读了这些但不是很有帮助:

1.Get developer keys for Google Cloud Service Accounts 2.https://www.pingidentity.com/fr/company/blog/posts/2019/the-hard-parts-of-jwt-security-nobody-talks-about.html

【问题讨论】:

标签: google-cloud-platform jwt openid-connect public-key-encryption encryption-asymmetric


【解决方案1】:

根据官方文档:

Creating and managing service account keys

Google 确保所有服务帐号的所有公钥都 任何人都可以公开访问,并且可以验证签名 是用私钥创建的。公钥是公开的 可通过以下 URL 访问:

1.x.509 证书:https://www.googleapis.com/service_accounts/v1/metadata/x509/[SA-NAME]@[PROJECT-ID].iam.gserviceaccount.com

2.JSON 网络密钥(JWK): https://www.googleapis.com/service_accounts/v1/jwk/[SA-NAME]@[PROJECT-ID].iam.gserviceaccount.com

3.原始端点: https://www.googleapis.com/service_accounts/v1/metadata/raw/[SA-NAME]@[PROJECT-ID].iam.gserviceaccount.com

我使用 curl 访问网址:

  curl -i  https://www.googleapis.com/service_accounts/v1/jwk/[SA-NAME]@[PROJECT-ID].iam.gserviceaccount.com
{
"keys": [
  {
    "e": "xxxx",
    "kty": "xxx",
    "alg": "xxxx",
    "n": "xxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "use": "xxx",
    "kid": "xxxxxxxxxxxxxxxx"
  }
]
}

或者访问原始端点:

     curl -i https://www.googleapis.com/service_accounts/v1/metadata/raw/[SA-NAME]@[PROJECT-ID].iam.gserviceaccount.com
   {
 "keyvalues": [
   {
     "exponent": "xxx",
     "keyid": "xxxxxxxxxxx",
     "modulus": "xxxxxxxxxxx",
     "algorithm": "xxx"
   }
 ]
}

【讨论】:

  • 谢谢!这真的很有帮助。另外,我知道使用这个密钥我可以从像8gwifi.org/jwkconvertfunctions.jsp这样的网站获得公钥证书。
  • 如果我的回答对您有帮助,请将其标记为已接受,以提高社区的知名度。
  • 链接googleapis.com/service_accounts/v1/metadata/x509/…提供的公钥证书和我在粘贴不记名令牌时从jwt.io获得的公钥证书不匹配。有什么我想念的吗?
  • 请确保您使用相同的服务帐户创建不记名令牌,我对jwt.io了解不多