我正在尝试验证从我的 Google Cloud Function 到我在 App Engine(标准环境)上的 API 的请求。
我有一些工作,但我是 OAuth2 的新手,正在寻找健全性检查。
在我的 Cloud Functions 中,我向我的 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% 确信这实际上是安全的。有人可能在没有凭据的情况下欺骗我的服务帐户吗?
提前致谢!
答案 0 :(得分:1)
是否有人可以在没有我的情况下欺骗我的服务帐户 它的凭据?
准确的答案需要指定时间。如果有足够的时间和处理能力,任何身份验证/授权/加密/散列/签名方法都可能被破解。
Google 服务帐户包含 RSA 2048 位私钥。目前的猜测是破解 RSA 2048 位加密需要 300 万亿年。随着计算机的飞速发展,假设您的数据在 RSA 被破解时可能没有任何用途/价值。
私钥用于签署 JWT。 Signed JWT 用于请求 OAuth 访问/身份令牌。
欺骗需要使用相同的私钥进行签名。因此,以今天的技术,欺骗是不可能的。
窃取/泄露私钥或生成的 OAuth 令牌是当今唯一可行的方法。