default的service account長相通常是:
service-${project_number}@${gcp service name}.iam.gserviceaccount.com
或
${project_number}@${gcp service name}.gserviceaccount.com
差不多是這樣[1]
雷包的產生
這次的使用情境是
我想要new一個Cloud Scheduler的服務,定時去呼叫一隻Cloud Function
然後我又想要這隻Cloud Function只讓這個Cloud Scheduler呼叫
所以設定如下

我開啟了auth要讓gcp協助我做Cloud Function的權限設定[2]
設定只要是這個service account來的,就可以執行Cloud Function
再來,因為本人實在很懶惰
因此我直接把權限grant給Cloud Scheduler的default service account
都設定好惹~
結果一run 就發現

居然獲得了一個PERMISSION_DENIED
我一直以為是auth設定有錯,或是有權限沒有grant到,找了很久
最後我在網路上找到了一篇[3]
他的設定方式跟我一模一樣,但他是用custom service account
在無計可施的狀態下,我想說不然我也new一個自訂的
結果
我 成 功 了!!!???
我好疑惑,為何default的不能用,但custom的可以?
為此,我發信問了support
support回我:
default service account是由Google管理的一種service account, 如官方文檔 [1] Setting up the service account 中,第三點提到“Cloud Scheduler itself must have a service account of its own that has the Cloud Scheduler Service Agent role granted.”
同文件 [1] Setting up the service account 中,第二點又提到,您需要創建一個client service accont, 並給予對應Google Cloud service的invoke權限
因此在建立cloud schedule job的時候不能使用Cloud Scheduler的default service account,而需要創建一個custom service account。
[1] https://cloud.google.com/scheduler/docs/http-target-auth#setting_up_the_service_account
痾…肯定是我哪裡有誤會,他沒有說為什麼不能用
只有說文件說要new一個custom的呀(這我有眼睛我有看到)

anyway我決定不再鑽研這件沒意義的事情
總之 此案結案
Cloud Scheduler的default service account不要用!
容我發這篇文紀念我逝去的一個工作天
我決定為gcp的踩地雷生活開個系列來記錄
不知老綁如果google到這系列的 他會不會要打我XD
記錄有誤歡迎留言
#GCP踩地雷系列 #WhenIWorkWithGCP
參考文件
[1]https://cloud.google.com/iam/docs/service-accounts#google-managed
[2]https://cloud.google.com/scheduler/docs/http-target-auth?hl=zh-tw#token