このページでは、組織のポリシー サービスのカスタム制約を使用して、次の Google Cloud リソースに対する特定のオペレーションを制限する方法について説明します。
eventarc.googleapis.com/Channeleventarc.googleapis.com/ChannelConnectioneventarc.googleapis.com/Enrollmenteventarc.googleapis.com/GoogleApiSourceeventarc.googleapis.com/GoogleChannelConfigeventarc.googleapis.com/MessageBuseventarc.googleapis.com/Pipelineeventarc.googleapis.com/Trigger
組織のポリシーの詳細については、カスタムの組織のポリシーをご覧ください。
組織のポリシーと制約について
Google Cloud 組織のポリシー サービスを使用すると、組織のリソースをプログラマティックに一元管理できます。組織のポリシー管理者は組織のポリシーを定義できます。組織のポリシーは、Google Cloud リソース階層内のGoogle Cloud リソースやそれらのリソースの子孫に適用される、制約と呼ばれる一連の制限です。組織のポリシーは、組織レベル、フォルダレベル、またはプロジェクト レベルで適用できます。
組織のポリシーを利用することで、あらかじめ用意されたマネージド制約をさまざまな Google Cloud サービスに適用できます。ただし、組織のポリシーで制限されている特定の項目をより細かくカスタマイズして制御したい場合は、カスタム制約を作成して、それを組織のポリシーで使うこともできます。
ポリシーの継承
デフォルトでは、組織のポリシーは、そのポリシーを適用したリソースの子孫に継承されます。たとえば、フォルダにポリシーを適用した場合、 Google Cloud はそのフォルダ内のすべてのプロジェクトにそのポリシーを適用します。この動作の詳細と変更方法については、階層評価ルールをご覧ください。
制限事項
Eventarc によって作成され、トリガーのトランスポート層(
resource.transport.pubsub.topic)として使用される Pub/Sub トピックにカスタム組織のポリシー制約を適用するには、Eventarc Standard トリガーではなく、Pub/Sub トピック リソースに制約を適用する必要があります。ただし、既存の Pub/Sub トピックを使用している場合は、Eventarc Standard トリガーを使用して制約を適用できます。eventarc.googleapis.com/ChannelConnectionリソースの場合、カスタムの組織のポリシーはCREATEメソッドにのみ適用できます。
始める前に
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
 - 
    
    
      
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
 - 
      Create a project: To create a project, you need the Project Creator
      (
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles. 
 - 
  
    
Verify that billing is enabled for your Google Cloud project.
 - 
      
Install the Google Cloud CLI.
 - 
          
外部 ID プロバイダ(IdP)を使用している場合は、まず連携 ID を使用して gcloud CLI にログインする必要があります。
 - 
        
gcloud CLI を初期化するには、次のコマンドを実行します。
gcloud init - 
    
    
      
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
 - 
      Create a project: To create a project, you need the Project Creator
      (
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles. 
 - 
  
    
Verify that billing is enabled for your Google Cloud project.
 - 
      
Install the Google Cloud CLI.
 - 
          
外部 ID プロバイダ(IdP)を使用している場合は、まず連携 ID を使用して gcloud CLI にログインする必要があります。
 - 
        
gcloud CLI を初期化するには、次のコマンドを実行します。
gcloud init - 組織 ID を確認します。
 ORGANIZATION_ID: 組織 ID(123456789など)。CONSTRAINT_NAME: 新しいカスタム制約に付ける名前。カスタム制約はcustom.で始まる必要があり、大文字、小文字、数字のみを含めることができます。例:custom.eventarcPipelineNoErrorLogこのフィールドの最大長は 70 文字です。RESOURCE_NAME: 制限するオブジェクトとフィールドを含むGoogle Cloud リソースの完全修飾名。例:eventarc.googleapis.com/PipelineCONDITION: サポート対象のサービス リソースの表現に対して書き込まれる CEL 条件。このフィールドの最大長は 1,000 文字です。条件の書き込み先として使用できるリソースの詳細については、サポート対象のリソースをご覧ください。例:"resource.loggingConfig.logSeverity=='ERROR'"ACTION:conditionが満たされている場合に実行するアクション。有効な値はALLOWとDENYです。DISPLAY_NAME: 制約の名前。わかりやすい名前を入力してください。このフィールドの最大長は 200 文字です。DESCRIPTION: ポリシー違反時にエラー メッセージとして表示される制約の説明。わかりやすい説明を入力してください。このフィールドの最大長は 2,000 文字です。- Google Cloud コンソールで [組織のポリシー] ページに移動します。
 - プロジェクト選択ツールで、組織のポリシーを設定するプロジェクトを選択します。
 - [組織のポリシー] ページのリストで制約を選択して、その制約の [ポリシーの詳細] ページを表示します。
 - このリソースの組織のポリシーを構成するには、[ポリシーを管理] をクリックします。
 - [ポリシーの編集] ページで、[Override parent's policy] を選択します。
 - [ルールを追加] をクリックします。
 - [適用] セクションで、この組織のポリシーの適用を有効にするかどうかを選択します。
 - 省略可: タグで組織のポリシーに条件を設定するには、[条件を追加] をクリックします。組織のポリシーに条件付きルールを追加する場合は、少なくとも 1 つは無条件のルールを追加する必要があります。そうしないとポリシーを保存できないのでご注意ください。詳細については、タグ付きの組織のポリシーの設定をご覧ください。
 - [変更内容をテスト] をクリックして、組織のポリシーの効果をシミュレートします。以前のマネージド制約ではポリシー シミュレーションを使用できません。詳細については、Policy Simulator で組織のポリシーの変更をテストするをご覧ください。
 - 組織のポリシーを完成させて適用するには、[ポリシーを設定] をクリックします。ポリシーが有効になるまでに最大 15 分かかります。
 - 
        
PROJECT_ID: 制約を適用するプロジェクト。 - 
        
CONSTRAINT_NAME: カスタム制約に定義した名前。たとえば、custom.eventarcPipelineNoErrorLogのようにします。 - 組織のポリシー サービスについて詳細を学習する。
 - 組織のポリシーの作成と管理の方法について学習する。
 - マネージドの組織のポリシーの制約全一覧を参照する。
 
必要なロール
    
      カスタムの組織のポリシーを管理するために必要な権限を取得するには、組織のリソースに対する組織のポリシー管理者(roles/orgpolicy.policyAdmin)の IAM ロールを付与するよう管理者に依頼してください。ロールの付与については、プロジェクト、フォルダ、組織へのアクセス権の管理をご覧ください。
必要な権限は、カスタムロールや他の事前定義ロールから取得することもできます。
カスタム制約を作成する
カスタム制約は、組織のポリシーを適用しているサービスでサポートされるリソース、メソッド、条件、アクションを使用して YAML ファイルで定義されます。カスタム制約の条件は、Common Expression Language(CEL)を使用して定義されます。CEL を使用してカスタム制約で条件を作成する方法については、カスタム制約の作成と管理の CEL セクションをご覧ください。
カスタム制約を作成するには、次の形式で YAML ファイルを作成します。
name: organizations/ORGANIZATION_ID/customConstraints/CONSTRAINT_NAME
resourceTypes:
- RESOURCE_NAME
methodTypes:
- CREATE
- UPDATE
condition: "CONDITION"
actionType: ACTION
displayName: DISPLAY_NAME
description: DESCRIPTION
次のように置き換えます。
カスタム制約の作成方法については、カスタム制約の定義をご覧ください。
カスタム制約を設定する
新しいカスタム制約の YAML ファイルを作成したら、組織内の組織のポリシーで使用できるように設定する必要があります。カスタム制約を設定するには、gcloud org-policies set-custom-constraint コマンドを使用します。gcloud org-policies set-custom-constraint CONSTRAINT_PATH
CONSTRAINT_PATH は、カスタム制約ファイルのフルパスに置き換えます。例: /home/user/customconstraint.yaml
完了すると、カスタム制約が組織のポリシーとして Google Cloud 組織のポリシーのリストに表示されます。カスタム制約が存在することを確認するには、gcloud org-policies list-custom-constraints コマンドを使用します。gcloud org-policies list-custom-constraints --organization=ORGANIZATION_ID
ORGANIZATION_ID は、組織リソースの ID に置き換えます。詳細については、組織のポリシーの表示をご覧ください。カスタムの組織のポリシーを適用する
制約を適用するには、それを参照する組織のポリシーを作成し、その組織のポリシーを Google Cloud リソースに適用します。コンソール
gcloud
ブール型ルールを含む組織のポリシーを作成するには、制約を参照するポリシー YAML ファイルを作成します。
name: projects/PROJECT_ID/policies/CONSTRAINT_NAME spec: rules: - enforce: true
次のように置き換えます。
制約を含む組織のポリシーを適用するには、次のコマンドを実行します。
gcloud org-policies set-policy POLICY_PATH
      POLICY_PATH は、組織のポリシーの YAML ファイルのパスに置き換えます。ポリシーが有効になるまでに最大 15 分かかります。
一般的なユースケースのカスタム組織ポリシーの例
次の表では一般的なカスタム制約の構文例をまとめています。
| 説明 | 制約の構文 | 
|---|---|
| CMEK 鍵を必須にする | 
    name: organizations/ORGANIZATION_ID/customConstraints/custom.eventarcCMEKOrgPolicy resourceTypes: - eventarc.googleapis.com/Channel methodTypes: - CREATE condition: "resource.cryptoKeyName.contains('projects/my-project/')" actionType: ALLOW displayName: Enforce the use of a CMEK key from my-project description: All Eventarc channels must be created with a CMEK key from my-project  | 
| CMEK 鍵を拒否する | 
    name: organizations/ORGANIZATION_ID/customConstraints/custom.eventarcGoogleChannelKey resourceTypes: - eventarc.googleapis.com/GoogleChannelConfig methodTypes: - CREATE - UPDATE condition: "resource.cryptoKeyName.contains('projects/my-project/')" actionType: DENY displayName: Constrain the use of CMEK keys from my-project description: CMEK keys from a specific project are denied when creating or updating the configuration that supports using a Google Cloud service as an event source  | 
| ロギングの重大度が必要 | 
        name: organizations/ORGANIZATION_ID/customConstraints/custom.eventarcPipelineErrorLog
    resourceTypes:
    - eventarc.googleapis.com/Pipeline
    methodTypes:
    - CREATE
    condition: "resource.loggingConfig.logSeverity=='ERROR'"
    actionType: ALLOW
    displayName: Enforce minimum severity for log entries
    description: All Eventarc Advanced pipelines must be configured
    with a logging level of  | 
| 宛先を拒否する | 
    name: organizations/ORGANIZATION_ID/customConstraints/custom.eventarcTriggerNoTestDestination resourceTypes: - eventarc.googleapis.com/Trigger methodTypes: - CREATE condition: "resource.destination.cloudRun.service.contains('test')" actionType: DENY displayName: Constrain Cloud Run service destinations description: Specific Cloud Run service destinations are denied when creating an Eventarc Standard trigger  | 
Eventarc でサポートされているリソース
次の表に、カスタム制約で参照できる Eventarc リソースを示します。| リソース | フィールド | 
|---|---|
| eventarc.googleapis.com/Channel | 
        resource.cryptoKeyName
       | 
        resource.name
       | |
        resource.provider
       | |
| eventarc.googleapis.com/ChannelConnection | 
        resource.activationToken
       | 
        resource.channel
       | |
        resource.name
       | |
| eventarc.googleapis.com/Enrollment | 
        resource.annotations
       | 
        resource.celMatch
       | |
        resource.destination
       | |
        resource.displayName
       | |
        resource.messageBus
       | |
        resource.name
       | |
| eventarc.googleapis.com/GoogleApiSource | 
        resource.annotations
       | 
        resource.cryptoKeyName
       | |
        resource.destination
       | |
        resource.displayName
       | |
        resource.loggingConfig.logSeverity
       | |
        resource.name
       | |
| eventarc.googleapis.com/GoogleChannelConfig | 
        resource.cryptoKeyName
       | 
        resource.name
       | |
| eventarc.googleapis.com/MessageBus | 
        resource.annotations
       | 
        resource.cryptoKeyName
       | |
        resource.displayName
       | |
        resource.loggingConfig.logSeverity
       | |
        resource.name
       | |
| eventarc.googleapis.com/Pipeline | 
        resource.annotations
       | 
        resource.cryptoKeyName
       | |
        resource.destinations.authenticationConfig.googleOidc.audience
       | |
        resource.destinations.authenticationConfig.googleOidc.serviceAccount
       | |
        resource.destinations.authenticationConfig.oauthToken.scope
       | |
        resource.destinations.authenticationConfig.oauthToken.serviceAccount
       | |
        resource.destinations.httpEndpoint.messageBindingTemplate
       | |
        resource.destinations.httpEndpoint.uri
       | |
        resource.destinations.messageBus
       | |
        resource.destinations.networkConfig.networkAttachment
       | |
        resource.destinations.outputPayloadFormat.avro.schemaDefinition
       | |
        resource.destinations.outputPayloadFormat.protobuf.schemaDefinition
       | |
        resource.destinations.topic
       | |
        resource.destinations.workflow
       | |
        resource.displayName
       | |
        resource.inputPayloadFormat.avro.schemaDefinition
       | |
        resource.inputPayloadFormat.protobuf.schemaDefinition
       | |
        resource.loggingConfig.logSeverity
       | |
        resource.mediations.transformation.transformationTemplate
       | |
        resource.name
       | |
        resource.retryPolicy.maxAttempts
       | |
        resource.retryPolicy.maxRetryDelay
       | |
        resource.retryPolicy.minRetryDelay
       | |
| eventarc.googleapis.com/Trigger | 
        resource.channel
       | 
        resource.destination.cloudFunction
       | |
        resource.destination.cloudRun.path
       | |
        resource.destination.cloudRun.region
       | |
        resource.destination.cloudRun.service
       | |
        resource.destination.gke.cluster
       | |
        resource.destination.gke.location
       | |
        resource.destination.gke.namespace
       | |
        resource.destination.gke.path
       | |
        resource.destination.gke.service
       | |
        resource.destination.httpEndpoint.uri
       | |
        resource.destination.networkConfig.networkAttachment
       | |
        resource.destination.workflow
       | |
        resource.eventDataContentType
       | |
        resource.eventFilters.attribute
       | |
        resource.eventFilters.operator
       | |
        resource.eventFilters.value
       | |
        resource.name
       | |
        resource.serviceAccount
       | |
        resource.transport.pubsub.topic
       |