カスタム組織ポリシーを構成する

このページでは、組織のポリシー サービスのカスタム制約を使用して、次の Google Cloud リソースに対する特定のオペレーションを制限する方法について説明します。

  • securitycenter.googleapis.com/BigQueryExport
  • securitycenter.googleapis.com/MuteConfig
  • securitycenter.googleapis.com/NotificationConfig
  • securitycenter.googleapis.com/ResourceValueConfig
  • securitycenter.googleapis.com/ContainerThreatDetectionSettings
  • securitycenter.googleapis.com/EventThreatDetectionSettings
  • securitycenter.googleapis.com/SecurityHealthAnalyticsSettings
  • securitycenter.googleapis.com/VirtualMachineThreatDetectionSettings
  • securitycenter.googleapis.com/WebSecurityScannerSettings
  • securitycentermanagement.googleapis.com/SecurityCenterService
  • securitycentermanagement.googleapis.com/SecurityHealthAnalyticsCustomModule
  • securitycentermanagement.googleapis.com/EventThreatDetectionCustomModule
  • websecurityscanner.googleapis.com/ScanConfig

組織のポリシーの詳細については、カスタムの組織のポリシーをご覧ください。

組織のポリシーと制約について

Google Cloud 組織のポリシー サービスを使用すると、組織のリソースをプログラマティックに一元管理できます。組織のポリシー管理者は組織のポリシーを定義できます。組織のポリシーは、Google Cloud リソース階層内のGoogle Cloud リソースやそれらのリソースの子孫に適用される、制約と呼ばれる一連の制限です。組織のポリシーは、組織レベル、フォルダレベル、またはプロジェクト レベルで適用できます。

組織のポリシーを利用することで、あらかじめ用意されたマネージド制約をさまざまな Google Cloud サービスに適用できます。ただし、組織のポリシーで制限されている特定の項目をより細かくカスタマイズして制御したい場合は、カスタム制約を作成して、それを組織のポリシーで使うこともできます。

ポリシーの継承

デフォルトでは、組織のポリシーは、そのポリシーを適用したリソースの子孫に継承されます。たとえば、フォルダにポリシーを適用した場合、 Google Cloud はそのフォルダ内のすべてのプロジェクトにそのポリシーを適用します。この動作の詳細と変更方法については、階層評価ルールをご覧ください。

始める前に

  1. 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.
  2. 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 role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Install the Google Cloud CLI.

  5. 外部 ID プロバイダ(IdP)を使用している場合は、まず連携 ID を使用して gcloud CLI にログインする必要があります。

  6. gcloud CLI を初期化するには、次のコマンドを実行します。

    gcloud init
  7. 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 role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  8. Verify that billing is enabled for your Google Cloud project.

  9. Install the Google Cloud CLI.

  10. 外部 ID プロバイダ(IdP)を使用している場合は、まず連携 ID を使用して gcloud CLI にログインする必要があります。

  11. gcloud CLI を初期化するには、次のコマンドを実行します。

    gcloud init
  12. 組織 ID を確認します。
  13. 必要なロール

    カスタムの組織のポリシーを管理するために必要な権限を取得するには、組織のリソースに対する組織のポリシー管理者roles/orgpolicy.policyAdmin)の IAM ロールを付与するよう管理者に依頼してください。ロールの付与については、プロジェクト、フォルダ、組織へのアクセス権の管理をご覧ください。

    必要な権限は、カスタムロールや他の事前定義ロールから取得することもできます。

    カスタム制約を設定する

    カスタム制約は、組織のポリシーを適用しているサービスでサポートされるリソース、メソッド、条件、アクションを使用して YAML ファイルで定義されます。カスタム制約の条件は、Common Expression Language(CEL)を使用して定義されます。CEL を使用してカスタム制約で条件を作成する方法については、カスタム制約の作成と管理の CEL セクションをご覧ください。

    コンソール

    カスタム制約を作成する手順は次のとおりです。

    1. Google Cloud コンソールで [組織のポリシー] ページに移動します。

      [組織のポリシー] に移動

    2. プロジェクト選択ツールから、組織のポリシーを設定するプロジェクトを選択します。
    3. [ カスタム制約] をクリックします。
    4. [表示名] ボックスに、制約のわかりやすい名前を入力します。この名前はエラー メッセージで使用され、識別とデバッグに使用できます。エラー メッセージで漏えいする可能性があるため、表示名には PII や機密データを使用しないでください。このフィールドには、最大 200 文字まで入力できます。
    5. [制約 ID] ボックスに、新しいカスタム制約の名前を入力します。カスタム制約には、英字(大文字と小文字を含む)または数字のみを含めることができます(例: custom.disableGkeAutoUpgrade)。このフィールドには、接頭辞(custom.)を除き、最大 70 文字まで含めることができます(例: organizations/123456789/customConstraints/custom)。エラー メッセージで漏えいする可能性があるため、制約 ID には PII や機密データを含めないでください。
    6. [説明] ボックスに、制約の説明を入力します。この説明は、ポリシー違反時にエラー メッセージとして使用されます。ポリシー違反が発生した理由と、ポリシー違反を解決する方法に関する詳細を含めます。エラー メッセージで漏えいする可能性があるため、説明には PII や機密データを含めないでください。このフィールドには、最大 2,000 文字を入力できます。
    7. [リソースの種類] ボックスで、制限するオブジェクトとフィールドを含む Google Cloud REST リソースの名前(container.googleapis.com/NodePool など)を選択します。ほとんどのリソースタイプは、最大 20 個のカスタム制約をサポートしています。これより多くのカスタム制約を作成しようとすると、オペレーションは失敗します。
    8. [適用方法] で、REST CREATE メソッドに制約を適用するのか、または CREATE メソッドと UPDATE メソッドの両方に制約を適用するのかを選択します。制約に違反するリソースに対して UPDATE メソッドを使用して制約を適用すると、そのリソースに対する変更は、違反が解決されない限り、組織のポリシーによってブロックされます。
    9. すべての Google Cloud サービスが両方のメソッドをサポートしているわけではありません。各サービスでサポートされているメソッドを確認するには、 サポートされているサービスをご覧ください。

    10. 条件を定義するには、[ 条件を編集] をクリックします。
      1. [条件を追加] パネルで、サポートされているサービス リソースを参照する CEL 条件を作成します(例: resource.management.autoUpgrade == false)。このフィールドには、最大 1,000 文字を入力できます。CEL の使用方法の詳細については、 Common Expression Language をご覧ください。カスタム制約で使用できるサービス リソースの詳細については、 カスタム制約でサポートされているサービスをご覧ください。
      2. [保存] をクリックします。
    11. [アクション] で、条件を満たしている場合に、評価された方法を許可するかどうかを選択します。
    12. 拒否アクションは、条件が true と評価された場合に、リソースを作成または更新するオペレーションがブロックされることを意味します。

      許可アクションは、条件が true と評価された場合にのみ、リソースを作成または更新するオペレーションが許可されることを意味します。条件に明示的にリストされているケースを除き、他のすべてのケースはブロックされます。

    13. [制約を作成] をクリックします。
    14. 各フィールドに値を入力すると、このカスタム制約の YAML 構成が右側に表示されます。

    gcloud

    1. カスタム制約を作成するには、次の形式で YAML ファイルを作成します。
    2.       name: organizations/ORGANIZATION_ID/customConstraints/CONSTRAINT_NAME
            resourceTypes:
            - RESOURCE_NAME
            methodTypes:
            - CREATE
      - UPDATE
      condition: "CONDITION" actionType: ACTION displayName: DISPLAY_NAME description: DESCRIPTION

      次のように置き換えます。

      • ORGANIZATION_ID: 組織 ID(123456789 など)。
      • CONSTRAINT_NAME: 新しいカスタム制約に付ける名前。カスタム制約には、文字(大文字と小文字を含む)または数字のみを含めることができます(例: custom.SccNotificationConfig)。このフィールドには、最大 70 文字まで入力できます。
      • RESOURCE_NAME: 制限するオブジェクトとフィールドを含む Google Cloudリソースの完全修飾名。例: securitycenter.googleapis.com/NotificationConfig
      • CONDITION: サポートされているサービス リソースの表現に対して書き込まれる CEL 条件。このフィールドには、最大 1,000 文字を入力できます。例: "resource.pubsubTopic != 'projects/PROJECT_ID/topics/TOPIC_ID'"
      • 条件の書き込み先として使用できるリソースの詳細については、サポート対象のリソースをご覧ください。

      • ACTION: condition が満たされている場合に実行するアクション。有効な値は ALLOWDENY です。
      • 許可アクションは、条件が true と評価された場合に、リソースを作成または更新するオペレーションが許可されることを意味します。つまり、条件に明示的にリストされているケースを除き、他のすべてのケースはブロックされます。

        拒否アクションは、条件が true と評価された場合に、リソースを作成または更新するオペレーションがブロックされることを意味します。

      • DISPLAY_NAME: 制約の名前。わかりやすい名前を入力してください。このフィールドには、最大 200 文字を入力できます。
      • DESCRIPTION: ポリシー違反時にエラー メッセージとして表示される制約の説明。わかりやすい説明を入力してください。このフィールドには、最大 2,000 文字を入力できます。
    3. 新しいカスタム制約の YAML ファイルを作成したら、組織のポリシーで使用できるように設定する必要があります。カスタム制約を設定するには、 gcloud org-policies set-custom-constraint コマンドを使用します。
    4.         gcloud org-policies set-custom-constraint CONSTRAINT_PATH
            

      CONSTRAINT_PATH は、カスタム制約ファイルのフルパスに置き換えます。例: /home/user/customconstraint.yaml

      このオペレーションが完了すると、カスタム制約が Google Cloud 組織のポリシーのリストに表示され、使用可能になります。

    5. カスタム制約が存在することを確認するには、 gcloud org-policies list-custom-constraints コマンドを使用します。
    6.       gcloud org-policies list-custom-constraints --organization=ORGANIZATION_ID
            

      ORGANIZATION_ID は、組織リソースの ID に置き換えます。

      詳細については、 組織のポリシーの表示をご覧ください。

    カスタムの組織のポリシーを適用する

    制約を適用するには、それを参照する組織のポリシーを作成し、その組織のポリシーを Google Cloud リソースに適用します。

    コンソール

    1. Google Cloud コンソールで [組織のポリシー] ページに移動します。

      [組織のポリシー] に移動

    2. プロジェクト選択ツールから、組織のポリシーを設定するプロジェクトを選択します。
    3. [組織のポリシー] ページのリストで制約を選択して、その制約の [ポリシーの詳細] ページを表示します。
    4. このリソースの組織のポリシーを構成するには、[ポリシーを管理] をクリックします。
    5. [ポリシーの編集] ページで、[Override parent's policy] を選択します。
    6. [ルールを追加] をクリックします。
    7. [適用] セクションで、この組織のポリシーを適用するかどうかを選択します。
    8. 省略可: タグで組織のポリシーに条件を設定するには、[条件を追加] をクリックします。組織のポリシーに条件付きルールを追加する場合は、少なくとも 1 つは無条件のルールを追加する必要があります。そうしないとポリシーを保存できないのでご注意ください。詳細については、 タグを使用した組織のポリシーの設定をご覧ください。
    9. [変更内容をテスト] をクリックして、組織のポリシーの効果をシミュレートします。詳細については、 Policy Simulator で組織のポリシーの変更をテストするをご覧ください。
    10. ドライラン モードで組織のポリシーを適用するには、[ドライラン ポリシーを設定] をクリックします。詳細については、 ドライラン モードで組織のポリシーを作成するをご覧ください。
    11. ドライラン モードの組織のポリシーが意図したとおりに動作していることを確認したら、[ポリシーを設定] をクリックしてライブポリシーを設定します。

    gcloud

    1. ブール型ルールを含む組織のポリシーを作成するには、制約を参照するポリシー YAML ファイルを作成します。
    2.         name: projects/PROJECT_ID/policies/CONSTRAINT_NAME
              spec:
                rules:
                - enforce: true
              
              dryRunSpec:
                rules:
                - enforce: true
              
            

      次のように置き換えます。

      • PROJECT_ID: 制約を適用するプロジェクト。
      • CONSTRAINT_NAME: カスタム制約に定義した名前。例: custom.SccNotificationConfig
    3. ドライラン モードで組織のポリシーを適用するには、dryRunSpec フラグを指定して次のコマンドを実行します。
    4.         gcloud org-policies set-policy POLICY_PATH \
                --update-mask=dryRunSpec
            

      POLICY_PATH は、組織のポリシーの YAML ファイルのパスに置き換えます。ポリシーが有効になるまでに最大 15 分かかります。

    5. ドライラン モードの組織のポリシーが意図したとおりに動作していることを確認したら、org-policies set-policy コマンドと spec フラグを使用してライブポリシーを設定します。
    6.         gcloud org-policies set-policy POLICY_PATH \
                --update-mask=spec
            

      POLICY_PATH は、組織のポリシーの YAML ファイルのパスに置き換えます。ポリシーが有効になるまでに最大 15 分かかります。

    カスタム組織のポリシーをテストする

    次の例では、securitycenter.googleapis.com/NotificationConfig リソースのカスタム制約を作成します。この制約により、ユーザーは指定された Pub/Sub トピックにサブスクライブされている通知構成のみを作成または変更できます。

    始める前に、以下を把握しておく必要があります。

    • 組織の ID
    • プロジェクト ID
    • Pub/Sub トピック ID

    制約を作成する

    1. カスタム制約を定義する notificationConfig_constraint.yaml という名前の YAML ファイルを作成します。

       name: organizations/ORGANIZATION_ID/customConstraints/custom.SccNotificationConfig
       resourceTypes:
       - securitycenter.googleapis.com/NotificationConfig
       methodTypes:
       - CREATE
       - UPDATE
       condition: "resource.pubsubTopic != 'projects/PROJECT_ID/topics/TOPIC_ID'"
       actionType: DENY
       displayName: Only let users create or modify notification configs that
         are subscribed to a specific Pub/Sub topic.
       description: "Can't create or modify notification configs that are subscribed
         to the specified Pub/Sub topic."
      
    2. 制約を適用します。

      gcloud org-policies set-custom-constraint ~/notificationConfig_constraint.yaml
      
    3. 制約が存在することを確認します。

      gcloud org-policies list-custom-constraints --organization=ORGANIZATION_ID
      --filter="RESOURCE_TYPES='securitycenter.googleapis.com/NotificationConfig'"
      

    ポリシーを作成する

    1. 組織のポリシーを定義する notificationConfig_policy.yaml という名前の YAML ファイルを作成します。

       name: projects/PROJECT_ID/policies/custom.SccNotificationConfig
       spec:
         rules:
         - enforce: true
      
    2. ポリシーを適用します。

      gcloud org-policies set-policy ~/notificationConfig_policy.yaml
      
    3. ポリシーが存在することを確認します。

      gcloud org-policies list --organization=ORGANIZATION_ID
      --filter="constraint:custom.SccNotificationConfig"
      

    ポリシーをテストする

    組織のポリシーに違反する通知構成を作成してみます。

      gcloud scc notifications create NOTIFICATION_CONFIG_ID \
      --pubsub-topic=projects/PROJECT_ID/topics/example_topic \
      --project=PROJECT_ID  \
      --filter="state=\"ACTIVE\""
    

    次のような出力が表示されます。

      Operation denied by custom org policies:
      ["customConstraints/SccNotificationConfig": "Can't create or modify
      notification configs that are subscribed to the specified Pub/Sub
      topic."]
    

    一般的なユースケースのカスタム組織ポリシーの例

    次の表では一般的なカスタム制約の構文例をまとめています。

    説明 制約の構文
    ユーザーが特定の Pub/Sub トピックにサブスクライブされている通知構成のみを作成または変更できるようにします。
          name: organizations/ORGANIZATION_ID/customConstraints/custom.SccNotificationConfig
          resourceTypes:
          - securitycenter.googleapis.com/NotificationConfig
          methodTypes:
          - CREATE
          - UPDATE
          condition: "resource.pubsubTopic != 'projects/PROJECT_ID/topics/TOPIC_ID'"
          actionType: DENY
          displayName: Only let users create or modify notification configs
            that are subscribed to a specific Pub/Sub topic.
          description: "Can't create or modify notification configs that are subscribed
          to the specified Pub/Sub topic."
          
    ユーザーが特定 BigQuery データセットのみをエクスポートできるようにします。
          name: organizations/ORGANIZATION_ID/customConstraints/custom.SccBigQueryExport
          resourceTypes:
          - securitycenter.googleapis.com/BigQueryExport
          methodTypes:
          - CREATE
          - UPDATE
          condition: "resource.dataset != 'projects/PROJECT_ID/datasets/DATASET_ID'"
          actionType: DENY
          displayName: Only let users export a specific BigQuery dataset.
          description: "Can't export the specified BigQuery dataset."
          
    ユーザーが Container Threat Detection 設定リソースのサービス有効化状態を変更できないようにします。このユースケースは、Event Threat Detection、Security Health Analytics、Virtual Machine Threat Detection、Web Security Scanner の設定リソースにも適用されます。
          name: organizations/ORGANIZATION_ID/customConstraints/custom.SccKtdSettings
          resourceTypes:
          - securitycenter.googleapis.com/securitycenter.googleapis.com/ContainerThreatDetectionSettings
          methodTypes:
          - CREATE
          - UPDATE
          condition: "resource.serviceEnablementState != ENABLED"
          actionType: DENY
          displayName: Prevent users from changing the Container Threat Detection service
            enablement state.
          description: "Can't change the Container Threat Detection service enablement
            state."
          
    ユーザーが Security Health Analytics カスタム モジュール リソースの有効状態を変更できないようにします。このユースケースは、Event Threat Detection カスタム モジュール リソースにも適用されます。
          name: organizations/ORGANIZATION_ID/customConstraints/custom.SccShaCustomModule
          resourceTypes:
          - securitycentermanagement.googleapis.com/SecurityHealthAnalyticsCustomModule
          methodTypes:
          - CREATE
          - UPDATE
          condition: "resource.serviceEnablementState != ENABLED"
          actionType: DENY
          displayName: Prevent users from changing the Security Health Analytics custom
            module enablement state.
          description: "Can't change the Security Health Analytics custom module enablement
            state."
          
    最大 QPS の上限が 10 を超える Web Security Scanner スキャン構成をユーザーが作成または変更できないようにします。
          name: organizations/ORGANIZATION_ID/customConstraints/custom.WssScanConfig
          resourceTypes:
          - websecurityscanner.googleapis.com/ScanConfig
          methodTypes:
          - CREATE
          - UPDATE
          condition: "resource.maxQps > 10"
          actionType: DENY
          displayName: Only let users create or modify scan configs with a maximum
            QPS limit of 10 or less.
          description: "Can't create or modify scan configs that have a maximum QPS
            limit greater than 10."
          

    Security Command Center でサポートされているリソース

    次の表に、カスタム制約で参照できる Security Command Center リソースを示します。

    リソース フィールド
    securitycenter.googleapis.com/BigQueryExport resource.dataset
    resource.description
    resource.name
    securitycenter.googleapis.com/ContainerThreatDetectionSettings resource.modules[*].moduleEnablementState
    resource.name
    resource.serviceEnablementState
    securitycenter.googleapis.com/EventThreatDetectionSettings resource.modules[*].moduleEnablementState
    resource.name
    resource.serviceEnablementState
    securitycenter.googleapis.com/MuteConfig resource.description
    resource.expiryTime
    resource.name
    resource.type
    securitycenter.googleapis.com/NotificationConfig resource.description
    resource.name
    resource.pubsubTopic
    securitycenter.googleapis.com/ResourceValueConfig resource.cloudProvider
    resource.description
    resource.name
    resource.resourceLabelsSelector
    resource.resourceType
    resource.resourceValue
    resource.scope
    resource.tagValues
    securitycenter.googleapis.com/SecurityHealthAnalyticsSettings resource.modules[*].moduleEnablementState
    resource.name
    resource.serviceEnablementState
    securitycenter.googleapis.com/VirtualMachineThreatDetectionSettings resource.modules[*].moduleEnablementState
    resource.name
    resource.serviceEnablementState
    securitycenter.googleapis.com/WebSecurityScannerSettings resource.modules[*].moduleEnablementState
    resource.name
    resource.serviceEnablementState
    securitycentermanagement.googleapis.com/EventThreatDetectionCustomModule resource.description
    resource.displayName
    resource.enablementState
    resource.name
    resource.type
    securitycentermanagement.googleapis.com/SecurityCenterService resource.intendedEnablementState
    resource.modules[*].intendedEnablementState
    resource.name
    securitycentermanagement.googleapis.com/SecurityHealthAnalyticsCustomModule resource.customConfig.customOutput.properties.name
    resource.customConfig.description
    resource.customConfig.recommendation
    resource.customConfig.resourceSelector.resourceTypes
    resource.customConfig.severity
    resource.displayName
    resource.enablementState
    resource.name
    websecurityscanner.googleapis.com/ScanConfig resource.authentication.customAccount.loginUrl
    resource.authentication.customAccount.password
    resource.authentication.customAccount.username
    resource.authentication.googleAccount.password
    resource.authentication.googleAccount.username
    resource.authentication.iapCredential.iapTestServiceAccountInfo.targetAudienceClientId
    resource.blacklistPatterns
    resource.displayName
    resource.exportToSecurityCommandCenter
    resource.ignoreHttpStatusErrors
    resource.managedScan
    resource.maxQps
    resource.name
    resource.riskLevel
    resource.schedule.intervalDurationDays
    resource.schedule.scheduleTime
    resource.startingUrls
    resource.staticIpScan
    resource.targetPlatforms
    resource.userAgent

    次のステップ