[英]I can't get google cloud functions gen 2 to work with only authorized requests from behind a API Gateway
我最近切換到谷歌雲功能第 2 代,並且在通過 API 網關進行身份驗證時遇到問題。 我的網關調用了新的雲 function,而 function 本身不允許未經授權的用戶。 網關附加了一個服務帳戶,並帶有雲函數調用者角色(以及所有者角色,因為我正在排除故障)。
雲function日志中的錯誤信息是
請求未通過身份驗證。 允許未經身份驗證的調用或設置正確的授權 header。 在https://cloud.google.com/run/docs/securing/authenticating了解更多信息 其他故障排除文檔可在以下位置找到: https://cloud.google.com/run/docs/troubleshooting#unauthorized-client
我有一個測試 function 使用相同的代碼,使用雲功能 gen 1 並且不允許未經身份驗證的用戶。 當您點擊我的 api 網關時,此 function 效果很好。 我還有一個雲 function gen 2,它確實允許未經身份驗證的用戶,並且在訪問網關時也可以按預期工作,只是我的 gen 2 不允許未經身份驗證的用戶。
對於我的 API 網關 yaml 文件,這是文件的樣子(敏感信息 XXX'd out),
swagger: "2.0"
info:
title: XXXXXXXX api gateway for carson blade analytics app
description: Sample API on API Gateway with a Google Cloud Functions backend
version: 1.0.0
schemes:
- https
produces:
- application/json
paths:
/convert_csv:
get:
summary: Converts an XLSX file to a CSV file
operationId: convert
x-google-backend:
address: https://convert-csv-XXXXX-ue.a.run.app
responses:
"200":
description: A successful response
schema:
type: string
當我點擊未經身份驗證的允許的並查看它的標題時,我看到了
{
"aud": "https://convert-csv-XXXXX-ue.a.run.app/",
"azp": "XXXX",
"email": "XXX@XXX.iam.gserviceaccount.com",
"email_verified": true,
"exp": 1660101164,
"iat": 1660097564,
"iss": "https://accounts.google.com",
"sub": "XXXXX"
}
with the email being the email that is associated with the service account that has the correct cloud function invoker role and the aud being the same address as the address in the cloud api yaml. 因此,它正在替換我使用其服務帳戶發送的身份驗證 header,正如預期的那樣。 我已經嘗試閱讀所有文檔並嘗試了一堆不同的 yaml 配置,但我就是想不通。
總而言之,每個都連接到雲 api 網關並從 postman 到達端點,第 2 代允許未經身份驗證關閉 -> 不起作用。 gen 2 允許未經身份驗證打開-> 作品。 第 1 代,允許未經身份驗證已關閉 -> 有效
任何幫助將不勝感激,謝謝。
Cloud Functions 2nd gen 是 Cloud Run 之上的包裝器。 很多時候,2個產品糾纏在一起。
這絕對不清楚,從 Alpha 版本開始。 盡管我對 PM 和工程團隊發表了評論,但該產品已經公開發布,由於缺乏明確的分離,現在出現了很多錯誤和混亂。 太糟糕了:(
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.