使用服务帐户的 GCP 服务器到服务器身份验证

GCP Server to Server Authentication with Service Account

我正在尝试验证从我的 Google Cloud Function 到 App Engine(标准环境)上的 API 的请求。

我有一些工作,但我是 OAuth2 的新手,正在寻找健全性检查。

在我的 Cloud Function 中,我向 API 发送经过身份验证的请求,执行以下操作:

import { GoogleAuth } from 'google-auth-library';

// Send Request Code:
const auth = new GoogleAuth();
const tokenClient = await auth.getIdTokenClient(`/protectedEndpoint`);
await tokenClient.request({
    url: `https://${process.env.GCLOUD_PROJECT}.appspot.com/protectedEndpoint`,
    method: 'POST',
});

在 API(在 App Engine 上)中,我执行以下操作:

import { GoogleAuth } from 'google-auth-library';

// Handle Request Code:
const token = <Bearer token parsed from request headers>
const googleAuth = new GoogleAuth();
const tokenClient = await googleAuth.getIdTokenClient('');
const loginTicket = await tokenClient.verifyIdToken({
    idToken: token,
    audience: '/protectedEndpoint',
});

if (loginTicket.getUserId() !== process.env.SERVICE_ACCOUNT_ID)) {
    throw new Error('Unauthenticated Service Account');
}

return 'Successful Authentication'

注意:在这两种情况下,我都使用 Google 的默认应用程序凭据来初始化 GoogleAuth 客户端。 (我的默认 App Engine 服务帐户)

一切正常。我的函数向我的 API 发送请求,我的 API 能够解析不记名令牌并告诉我它来自我批准的服务帐户......但我不是 100% 确信这实际上是安全的。是否有人可以在没有凭据的情况下欺骗我的服务帐户?

提前致谢!

Is it possible for someone to spoof my service account without having its credentials?

准确的回答需要时间的规定。如果有足够的时间和处理能力,任何 authentication/authorization/encryption/hashing/signing 方法都可以被破解。

Google 服务帐户包含一个 RSA 2048 位私钥。目前的猜测是 300 万亿年才能破解 RSA 2048 位加密。随着计算机的快速发展,我们假设到 RSA 被破解时,您的数据可能已经不复存在 use/value。

私钥用于签署 JWT。 Signed JWT 用于请求 OAuth Access/Identity 令牌。

欺骗需要使用相同的私钥签名。因此,今天的技术无法进行欺骗。

Stealing/leaking 私钥或生成的 OAuth 令牌是当今唯一现实的方法。