GCP Cloud Function 배포 오류 문제 (python)

다음과 같이 cloud function 의 hello world quickstart 를 배포만 하려고 하는데 퍼미션 에러가 발생했다:

$ gcloud functions deploy hello_get --runtime python39 --trigger-http --allow-unauthenticated

ERROR: (gcloud.functions.describe) ResponseError: status=[403], code=[Ok], message=[Permission denied on resource project XXX.]

문제는 service account 쪽이 아닌 cloud build 쪽의 권한이 제대로 설정되지 않아서 발생한 문제였다:


문서상으로는 functions 배포에 cloud build 가 관여하는 내용이 없었기 때문에 한참 헤매었다. cloud build 의 설정 메뉴에서 cloud functions, app engines, 서비스 계정 등등 필요할 것 같은 서비스 상태를 설정하고 실행했다.

$ gcloud functions deploy hello_get --region=asia-northeast3 --runtime python39 --trigger-http --allow-unauthenticated

Deploying function (may take a while - up to 2 minutes)...failed.

ERROR: (gcloud.functions.deploy) OperationError: code=7, message=Build failed: service account "XXXXX@cloudbuild.gserviceaccount.com" has insufficient permission to execute the build on project "XXXXX"

com.google.net.rpc3.client.RpcClientException: <eye3 title='/ArgoAdminV1.CreateBuild, PERMISSION_DENIED'/> APPLICATION_ERROR;google.devtools.cloudbuild.v1/ArgoAdminV1.CreateBuild;service account "504779468686@cloudbuild.gserviceaccount.com" has insufficient permission to execute the build on project "XXXXX";AppErrorCode=7;StartTimeMs=1622877299715;unknown;ResFormat=AUTOMATIC;ServerTimeSec=0.396627094;LogBytes=256;Non-FailFast;EndUserCredsRequested;EffSecLevel=none;ReqFormat=AUTOMATIC;ReqID=5041fb31b02b28dd;GlobalID=0;Server=[2002:ac2:844a:0:b029:4e5:9557:d2fc]:4001


오류 메시지에 cloudbuild 가 등장한다. 이제 거의 다 온 듯.

https://www.learngoogle.com/2020/11/23/cloud-build-failure-you-do-not-have-permission-to-act-as-service-account/

을 참고해서 다음과 같이 수정:

1. 클라우드 콘솔의 IAM 및 관리자-IAM 선택

2. cloudbuild.gserviceaccount.com 서비스 계정 수정 선택 후 "CloudBuild 서비스 에이전트" 와 "저장소 관리자" 역할 추가

이러면 cloud build 로 인한 deploy 오류는 사라진다.

... 사실 hello world 실행과 관련해서는 한가지 오류가 더 있었다 :

Deploying function (may take a while - up to 2 minutes)...failed.

ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed: found incompatible dependencies: "functions-framework 2.1.3 has requirement click<8.0,>=7.0, but you have click 8.0.1.\nfunctions-framework 2.1.3 has requirement flask<2.0,>=1.0, but you have flask 2.0.1."; Error ID: efb30c0a

이건 내부의 functions framework 버저닝과 관련된 문제인데, https://cloud.google.com/functions/docs/writing/specifying-dependencies-python 를 참고해서 requirement.txt 에 flask < 2.0 으로 수정하면 되었다.


GCP 가 AWS 에 비해서 문서가 부족하고 이번처럼 빠진 부분도 많은데다, Trouble Shooting 과 관련된 내용을 찾기도 참 어렵다. 개인 프로젝트에는 괜찮지만 엔터프라이즈 용도로 쓰기에는 여러모로 불안한 부분이 많다.

댓글

이 블로그의 인기 게시물

pandas.read_csv() 에서 왠만하면 컬럼타입을 지정하자

스프링 컨텍스트 설정파일과 URI 경로를 제대로 못찾는 삽질