本文档介绍如何向服务帐号授予 Identity and Access Management (IAM) 角色,以便 Eventarc 可以从 Google Cloud 和第三方来源接收事件,并将事件传递给 Cloud Run for Anthos 服务。
如需详细了解 Eventarc 中的访问权限控制选项,请参阅访问权限控制。
所需 IAM 角色
向服务帐号授予适当的角色。
Cloud 审核日志
为了从 Google Cloud 来源接收事件,Eventarc 使用 Cloud Audit Logs 将日志传送到 Cloud Run for Anthos 目标。
服务帐号角色
-
向服务帐号授予 Pub/Sub Subscriber 角色 (
roles/pubsub.subscriber
):gcloud projects add-iam-policy-binding PROJECT_ID \ --member "serviceAccount:MY_SERVICE_ACCOUNT@PROJECT_NUMBER.iam.gserviceaccount.com" \ --role "roles/pubsub.subscriber"
-
向服务帐号授予 Monitoring Metric Writer 角色 (
roles/monitoring.metricWriter
):gcloud projects add-iam-policy-binding PROJECT_ID \ --member "serviceAccount:MY_SERVICE_ACCOUNT@PROJECT_NUMBER.iam.gserviceaccount.com" \ --role "roles/monitoring.metricWriter"
-
向服务帐号授予 Eventarc Event Receiver 角色 (
roles/eventarc.eventReceiver
):gcloud projects add-iam-policy-binding PROJECT_ID \ --member "serviceAccount:MY_SERVICE_ACCOUNT@PROJECT_NUMBER.iam.gserviceaccount.com" \ --role "roles/eventarc.eventReceiver"
替换以下值:
PROJECT_ID
:Google Cloud 项目 ID。MY_SERVICE_ACCOUNT
:您的服务帐号的名称。PROJECT_NUMBER
:Google Cloud 项目编号。
Cloud Storage
Eventarc 直接从 Cloud Storage 存储桶将事件通知发送到目标 Cloud Run for Anthos 服务。
服务帐号角色
-
向服务帐号授予 Pub/Sub Subscriber 角色 (
roles/pubsub.subscriber
):gcloud projects add-iam-policy-binding PROJECT_ID \ --member "serviceAccount:MY_SERVICE_ACCOUNT@PROJECT_NUMBER.iam.gserviceaccount.com" \ --role "roles/pubsub.subscriber"
-
向服务帐号授予 Monitoring Metric Writer 角色 (
roles/monitoring.metricWriter
):gcloud projects add-iam-policy-binding PROJECT_ID \ --member "serviceAccount:MY_SERVICE_ACCOUNT@PROJECT_NUMBER.iam.gserviceaccount.com" \ --role "roles/monitoring.metricWriter"
-
向服务帐号授予 Eventarc Event Receiver 角色 (
roles/eventarc.eventReceiver
):gcloud projects add-iam-policy-binding PROJECT_ID \ --member "serviceAccount:MY_SERVICE_ACCOUNT@PROJECT_NUMBER.iam.gserviceaccount.com" \ --role "roles/eventarc.eventReceiver"
替换以下值:
PROJECT_ID
:Google Cloud 项目 ID。MY_SERVICE_ACCOUNT
:您的服务帐号的名称。PROJECT_NUMBER
:Google Cloud 项目编号。
Cloud Storage 服务帐号角色
向服务帐号授予
Pub/Sub Publisher 角色 (roles/pubsub.publisher
):
SERVICE_ACCOUNT="$(gsutil kms serviceaccount -p PROJECT_ID)" gcloud projects add-iam-policy-binding PROJECT_ID \ --member="serviceAccount:SERVICE_ACCOUNT" \ --role='roles/pubsub.publisher'
将 PROJECT_ID
替换为 Google Cloud 项目 ID。
Pub/Sub 主题
为了接收来自第三方来源的事件,Eventarc 使用 Pub/Sub 通知将消息传送到 Cloud Run for Anthos 目标。
服务帐号角色
-
向服务帐号授予 Pub/Sub Subscriber 角色 (
roles/pubsub.subscriber
):gcloud projects add-iam-policy-binding PROJECT_ID \ --member "serviceAccount:MY_SERVICE_ACCOUNT@PROJECT_NUMBER.iam.gserviceaccount.com" \ --role "roles/pubsub.subscriber"
-
向服务帐号授予 Monitoring Metric Writer 角色 (
roles/monitoring.metricWriter
):gcloud projects add-iam-policy-binding PROJECT_ID \ --member "serviceAccount:MY_SERVICE_ACCOUNT@PROJECT_NUMBER.iam.gserviceaccount.com" \ --role "roles/monitoring.metricWriter"
替换以下值:
PROJECT_ID
:Google Cloud 项目 ID。MY_SERVICE_ACCOUNT
:您的服务帐号的名称。PROJECT_NUMBER
:Google Cloud 项目编号。