OAuth2.0 证书在使用前多长时间发布?

How long before usage are OAuth2.0 certificates published?

目前,我正在编写服务器端功能来验证 GCP 元数据服务器提供的 JWT(有关详细信息,请参阅 https://cloud.google.com/compute/docs/instances/verifying-instance-identity)。

在我的第一个(脏)实现中,我为每个传入请求从 https://www.googleapis.com/oauth2/v1/certs 获取了 Google 的证书。这就像一个魅力,但并没有真正扩展。所以我想缓存证书。

一种方法是创建一个缓存来存储与 kid 对应的证书。但是,这允许对手通过发送带有随机 kid 的虚假 JWT 来让服务器向 Google 服务器发出许多请求。

所以我更想要的是存储来自证书端点的完整响应。但是,为了使它起作用,我需要知道在使用前多长时间发布证书。

我在任何 RFC 或 GCP 文档中都找不到关于此的任何信息。有谁知道这是否在某处指定?

我向 GCP 支持部门询问了这个问题,他们回复了以下内容:

We cannot provide any guarantees about certificate rotation. The keys may rotate and additional valid certs may appear within the max-age. The server should pull [1] again to refresh the cert cache if it receives a token with an unknown kid.

  1. https://www.googleapis.com/oauth2/v1/certs

所以总结一下:只能缓存单个键,不能缓存完整的结果。应始终在 Google 的端点重新检查任何缓存未命中。