gcp雷包之default service account不要亂用

sasa :)
5 min readMar 21, 2020

--

#gcp雷包

前情提要

在gcp的每個服務中,都有一個default的service account

這個service account是gcp幫你maintain的,你不一定看得到

但有時候可以用(官方document會建議你用)

但有時候卻不能用

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呼叫

所以設定如下

Cloud Scheduler setting

我開啟了auth要讓gcp協助我做Cloud Function的權限設定[2]

設定只要是這個service account來的,就可以執行Cloud Function

再來,因為本人實在很懶惰

因此我直接把權限grant給Cloud Scheduler的default service account

都設定好惹~

結果一run 就發現

error when invoke the GCF

居然獲得了一個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

[3]https://medium.com/google-cloud/automatic-oidc-using-cloud-scheduler-tasks-and-pubsub-to-make-authenticated-calls-to-cloud-run-de9e7e9cec3f

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

sasa :)
sasa :)

Written by sasa :)

目標是做一個讓所有人都聽得懂技術語言的transfer person

No responses yet

Write a response