개발하자

(Terform, Cloud Run) 오류: 금지됨 클라이언트에 이 서버에서 URL/을(를) 가져올 수 있는 권한이 없습니다.

Cuire 2022. 12. 24. 08:10
반응형

(Terform, Cloud Run) 오류: 금지됨 클라이언트에 이 서버에서 URL/을(를) 가져올 수 있는 권한이 없습니다.

아래 코드로 도커 이미지를 실행하려고 합니다.

provider "google" {
  credentials = file("myCredentials.json")
  project     = "myproject-214771"
  region      = "asia-northeast1"
}

resource "google_cloud_run_service" "default" {
  name     = "hello-world"
  location = "asia-northeast1"

  template {
    spec {
      containers {
        image = "gcr.io/myproject-214771/hello-world:latest"
      }
    }
  }

  traffic {
    percent         = 100
    latest_revision = true
  }
}

그런 다음 도커 이미지를 실행하는 데 성공했습니다.

enter image description here

그러나 URL에 액세스하면 다음과 같이 표시됩니다.

enter image description here

오류: 금지됨 클라이언트에 이 서버에서 / URL을 가져올 수 있는 권한이 없습니다.

제 코드에 실수가 있나요?




아래의 코드를 코드에 추가(복사하여 붙여넣기)합니다.

data "google_iam_policy" "noauth" {
  binding {
    role = "roles/run.invoker"
    members = [
      "allUsers",
    ]
  }
}

resource "google_cloud_run_service_iam_policy" "noauth" {
  location    = google_cloud_run_service.default.location
  project     = google_cloud_run_service.default.project
  service     = google_cloud_run_service.default.name

  policy_data = data.google_iam_policy.noauth.policy_data
}

그래서 이것은:

provider "google" {
  credentials = file("myCredentials.json")
  project     = "myproject-214771"
  region      = "asia-northeast1"
}

resource "google_cloud_run_service" "default" {
  name     = "hello-world"
  location = "asia-northeast1"

  template {
    spec {
      containers {
        image = "gcr.io/myproject-214771/hello-world:latest"
      }
    }
  }

  traffic {
    percent         = 100
    latest_revision = true
  }
}

data "google_iam_policy" "noauth" {
  binding {
    role = "roles/run.invoker"
    members = [
      "allUsers",
    ]
  }
}

resource "google_cloud_run_service_iam_policy" "noauth" {
  location    = google_cloud_run_service.default.location
  project     = google_cloud_run_service.default.project
  service     = google_cloud_run_service.default.name

  policy_data = data.google_iam_policy.noauth.policy_data
}

마지막으로, 당신의 URL은 당신의 웹사이트를 참조하십시오.

enter image description here

게다가, 지금은:

enter image description here

다음에 역할을 추가하는 것을 잊지 마십시오.

enter image description here

그렇지 않으면 아래 오류가 표시됩니다.

클라우드 실행 서비스 "v1/projects/myproject-214771/locations/asia-northern1/services/hello-world"에 대한 IAM 정책을 설정하는 중 오류 발생: googleapi: 오류 403: 권한 'run.services'.리소스 'projects/myproject-214771/locations/asia-northern1/services/hello-world'에서 setImPolicy'가 거부되었습니다(또는 리소스가 존재하지 않을 수 있습니다).

또한 아래의 역할에서는 다음을 수행할 수 없습니다.

enter image description here

역할만 할 수 있습니다.

enter image description here




서비스 계정에 "Cloud Run Admin" 액세스 권한을 부여해야 하는 경우가 많습니다. run.services가 필요합니다.새 클라우드 실행에 대한 설정을 변경할 수 있는 setImPolicy 권한


반응형