云任务无法使用确定性 URL 调用云函数

问题描述 投票:0回答:1

Cloud Function gen2 现在支持两种类型的 HTTP URL:

  • 确定性:
    https://REGION-PROJECT_ID.cloudfunctions.net/FUNCTION_NAME
  • 非确定性:
    https://FUNCTION_NAME-RANDOM_HASH-REGION.a.run.app

对于非确定性 URL,您可以使用以下 OIDC 配置

创建一个使用该函数进行身份验证的云任务
task: {
  httpRequest: {
    url: "https://FUNCTION_NAME-RANDOM_HASH-REGION.a.run.app/something",
    httpMethod: "POST",
    oidcToken: {
      serviceAccountEmail: "[email protected]",
    },
    ...
}

但是,如果您将

url
切换为确定性变体,生成的云任务将不再能够调用云函数,并且会失败并显示
unaUTHENTICATED(16): HTTP status code 401

google-cloud-platform google-cloud-functions google-cloud-tasks google-cloud-node
1个回答
0
投票

oidcToken
还有一个
audience
字段:

audience

绳子

生成 OIDC 令牌时要使用的受众。如果未指定,将使用 target 中指定的 URI。

虽然 NodeJS 客户端(或 Google API)可以正确导出非确定性 URL 的

@google-cloud/tasks
,但对于确定性 URL 似乎并非如此。
你必须明确定义受众。

audience

另外,请注意,如果您的 URL 有其他子路径(例如上面的 
task: { httpRequest: { url: "https://REGION-PROJECT_ID.cloudfunctions.net/FUNCTION_NAME/something", httpMethod: "POST", oidcToken: { serviceAccountEmail: "[email protected]", audience: "https://REGION-PROJECT_ID.cloudfunctions.net/FUNCTION_NAME" }, ... }

),则必须将其删除

/something
    

© www.soinside.com 2019 - 2024. All rights reserved.