我在 GCP 中創建了一個服務帳戶,旨在運行云功能。這是服務帳戶,帶有我下載的 json 密鑰。

然后我做了這個云功能。這是默認的 python 3.9 函式,它簡單地列印出message你發送的資訊,或者如果沒有message,它只列印“Hello World!”

我設定了一個 HTTP 觸發器,要求使用我剛剛創建second_try的服務帳戶作為云功能的運行時服務帳戶進行身份驗證。請參閱下面的云功能的權限:

當我運行Test function時,即使我從未參考過我的服務帳戶憑據,它也能正常作業。

我在郵遞員中測驗了 curl 命令:
curl -m 70 -X POST https://us-central1-<MY PROJECT NAME>.cloudfunctions.net/func_two_hg \
-H "Authorization:bearer $(gcloud auth print-identity-token)" \
-H "Content-Type:application/json" \
-d '{}'
即使我沒有參考令人困惑的服務帳戶憑據,它仍然有效...
更令人困惑的是,當我嘗試參考服務帳戶憑據并因此通過服務帳戶運行該功能時,它會給出 401 錯誤,參考Your client does not have permission to the requested URL. 這是包含服務帳戶憑據的 curl 命令:
curl -m 70 -X POST https://us-central1-<MY PROJECT NAME>.cloudfunctions.net/func_two_hg \
-H "Authorization:bearer $(GOOGLE_APPLICATION_CREDENTIALS=/path/to/credentials.json gcloud auth application-default print-access-token)" \
-H "Content-Type:application/json" \
-d '{}'
這是錯誤:

What is the problem, and why won't it run with the service account credentials? And how do I make this function only run-able through the service account?
uj5u.com熱心網友回復:
如果您已正確配置所有內容,則應該:
- gcloud auth activate-service-account啟用服務帳戶。
- 然后,您可以
gcloud auth print-identity-token --account=${ACCOUNT}在哪里ACCOUNT獲取服務帳戶電子郵件以獲取身份令牌,該身份令牌應向云功能驗證您的身份。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/476476.html
標籤:curl google-cloud-platform google-cloud-functions postman service-accounts
