カスタム制約を作成する

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

組織のポリシーは、さまざまなGoogle Cloud サービスに事前に定義された制約を提供します。ただし、組織のポリシーで制限されている特定のフィールドをきめ細かく制御する必要がある場合は、カスタム制約を作成して、組織のポリシーでそれらのカスタム制約を使用することもできます。

利点

カスタムの組織のポリシーを使用すると、Managed Service for Apache Spark バッチ、セッション、セッション テンプレートに対する特定のオペレーションを許可または拒否できます。たとえば、バッチ ワークロードの作成リクエストが、組織のポリシーによって設定されたカスタム制約検証を満たしていない場合、リクエストは失敗し、エラーが呼び出し元に返されます。

ポリシーの継承

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

料金

事前に定義された制約やカスタム制約を含む組織のポリシー サービスは無料です。

始める前に

  1. プロジェクトを設定する
    1. Google Cloud アカウントにログインします。 Google Cloudを初めて使用する場合は、 アカウントを作成して、実際のシナリオでの Google プロダクトのパフォーマンスを評価してください。新規のお客様には、ワークロードの実行、テスト、デプロイができる無料クレジット $300 分を差し上げます。
    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. Enable the Managed Service for Apache Spark API.

      Roles required to enable APIs

      To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

      Enable the API

    5. Google Cloud CLI をインストールします。

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

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

      gcloud init
    8. 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

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

    10. Enable the Managed Service for Apache Spark API.

      Roles required to enable APIs

      To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

      Enable the API

    11. Google Cloud CLI をインストールします。

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

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

      gcloud init
    14. 組織 ID を確認します。

必要なロール

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

この事前定義ロールには、組織のポリシーを管理するために必要な権限が含まれています。必要とされる正確な権限については、「必要な権限」セクションを開いてご確認ください。

必要な権限

組織のポリシーを管理するには、次の権限が必要です。

  • orgpolicy.constraints.list
  • orgpolicy.policies.create
  • orgpolicy.policies.delete
  • orgpolicy.policies.list
  • orgpolicy.policies.update
  • orgpolicy.policy.get
  • orgpolicy.policy.set

カスタムロールや他の事前定義ロールを使用して、これらの権限を取得することもできます。

カスタム制約を作成する

カスタム制約は、適用されるリソース、メソッド、条件、アクションを使用して YAML ファイルで定義されます。Managed Service for Apache Spark は、バッチ リソースとセッション リソースの CREATE メソッドに適用されるカスタム制約をサポートしています。

カスタム制約の作成方法の詳細については、カスタム組織のポリシーの作成と管理をご覧ください。

バッチリソースのカスタム制約を作成する

バッチリソースの Managed Service for Apache Spark カスタム制約の YAML ファイルを作成するには、次の形式を使用します。

name: organizations/ORGANIZATION_ID/customConstraints/CONSTRAINT_NAME
resourceTypes:
- dataproc.googleapis.com/Batch
methodTypes: 
- CREATE
condition: CONDITION
actionType: ACTION
displayName: DISPLAY_NAME
description: DESCRIPTION

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

  • ORGANIZATION_ID: 組織 ID(123456789 など)。

  • CONSTRAINT_NAME: 新しいカスタム制約に付ける名前。カスタム制約は custom. で始まる必要があり、大文字、小文字、数字のみを含めることができます(例: custom.batchMustHaveSpecifiedCategoryLabel)。このフィールドの最大長は 70 文字です。接頭辞(例: organizations/123456789/customConstraints/custom.)はカウントされません。

  • CONDITION: サポート対象のサービス リソースの表現に対して書き込まれる CEL 条件。このフィールドの最大長は 1,000 文字です。条件の書き込み先として使用できるリソースの詳細については、リソースとオペレーションに対する Dataproc サーバーレスの制約をご覧ください。条件の例: ("category" in resource.labels) && (resource.labels['category'] in ['retail', 'ads', 'service'])

  • ACTION: 条件が満たされている場合に実行するアクション。ALLOW または DENY になります。

  • DISPLAY_NAME: 制約の名前。わかりやすい名前を入力してください。表示名の例: 「バッチの「category」ラベルの要件を適用する」。このフィールドの最大長は 200 文字です。

  • DESCRIPTION: ポリシー違反時にエラー メッセージとして表示される制約の説明。わかりやすい説明を入力してください。このフィールドの最大長は 2,000 文字です。説明の例: 「「retail」、「ads」、「service」の値を持つ「category」ラベルがある場合にのみ、Dataproc のバッチ作成を許可します」。

セッション リソースのカスタム制約を作成する

セッション リソースの Managed Service for Apache Spark カスタム制約の YAML ファイルを作成するには、次の形式を使用します。

name: organizations/ORGANIZATION_ID/customConstraints/CONSTRAINT_NAME
resourceTypes:
- dataproc.googleapis.com/Session
methodTypes: 
- CREATE
condition: CONDITION
actionType: ACTION
displayName: DISPLAY_NAME
description: DESCRIPTION

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

  • ORGANIZATION_ID: 組織 ID(123456789 など)。

  • CONSTRAINT_NAME: 新しいカスタム制約に付ける名前。カスタム制約は custom. で始まる必要があり、大文字、小文字、数字のみを含めることができます(例: custom.SessionNameMustStartWithTeamName)。このフィールドの最大長は 70 文字です。接頭辞はカウントされません(例: organizations/123456789/customConstraints/custom.)。

  • CONDITION: サポート対象のサービス リソースの表現に対して書き込まれる CEL 条件。このフィールドの最大長は 1,000 文字です。条件を記述できるリソースの詳細については、リソースとオペレーションに対する Dataproc サーバーレスの制約をご覧ください。条件の例: (resource.name.startsWith("dataproc")

  • ACTION: 条件が満たされている場合に実行するアクション。ALLOW または DENY になります。

  • DISPLAY_NAME: 制約の名前。わかりやすい名前を入力してください。表示名の例: 「セッションの TTL を 2 時間未満に設定する」。このフィールドの最大長は 200 文字です。

  • DESCRIPTION: ポリシー違反時にエラー メッセージとして表示される制約の説明。わかりやすい説明を入力してください。このフィールドの最大長は 2,000 文字です。説明の例: 「許容可能な TTL が設定されている場合にのみ、セッションの作成を許可します」。

セッション テンプレート リソースのカスタム制約を作成する

セッション テンプレート リソースの Managed Service for Apache Spark カスタム制約の YAML ファイルを作成するには、次の形式を使用します。

name: organizations/ORGANIZATION_ID/customConstraints/CONSTRAINT_NAME
resourceTypes:
- dataproc.googleapis.com/SessionTemplate
methodTypes: 
- CREATE
- UPDATE
condition: CONDITION
actionType: ACTION
displayName: DISPLAY_NAME
description: DESCRIPTION

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

  • ORGANIZATION_ID: 組織 ID(123456789 など)。

  • CONSTRAINT_NAME: 新しいカスタム制約に付ける名前。カスタム制約は custom. で始まる必要があり、大文字、小文字、数字のみを含めることができます(例: custom.SessionTemplateNameMustStartWithTeamName)。このフィールドの最大長は 70 文字です。接頭辞はカウントされません(例: organizations/123456789/customConstraints/custom.)。

  • CONDITION: サポート対象のサービス リソースの表現に対して書き込まれる CEL 条件。このフィールドの最大長は 1,000 文字です。条件を記述できるリソースの詳細については、リソースとオペレーションの制約をご覧ください。条件の例: (resource.name.startsWith("dataproc")

  • ACTION: 条件が満たされている場合に実行するアクション。ALLOW または DENY になります。

  • DISPLAY_NAME: 制約の名前。わかりやすい名前を入力してください。表示名の例: 「セッション テンプレートの TTL を 2 時間未満に設定する」。このフィールドの最大長は 200 文字です。

  • DESCRIPTION: ポリシー違反時にエラー メッセージとして表示される制約の説明。わかりやすい説明を入力してください。このフィールドの最大長は 2,000 文字です。説明の例: 「許容される TTL が設定されている場合にのみ、セッション テンプレートの作成を許可します」。

カスタム制約を設定する

コンソール

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

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

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

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

  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
    condition: "CONDITION"
    actionType: ACTION
    displayName: DISPLAY_NAME
    description: DESCRIPTION

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

    • ORGANIZATION_ID: 組織 ID(例: 123456789)。
    • CONSTRAINT_NAME: 新しいカスタム制約の名前。カスタム制約の名前に使用できるのは、英字(大文字と小文字)と数字のみです(例: custom.batchMustHaveSpecifiedCategoryLabel)。このフィールドには、接頭辞(custom.)を除き、最大 70 文字まで入力できます(例: organizations/123456789/customConstraints/custom)。エラー メッセージで公開される可能性があるため、制約 ID に個人情報(PII)やセンシティブ データを含めないでください。
    • RESOURCE_NAME: 制限するオブジェクトとフィールドを含む Google Cloudリソースの完全修飾名。たとえば、dataproc.googleapis.com/batch のようにします。ほとんどの種類のリソースは、最大 20 個のカスタム制約をサポートしています。これより多くのカスタム制約を作成しようとすると、オペレーションは失敗します。
    • methodTypes: 制約が適用される REST メソッド。CREATE のみです。
    • 各サービスでサポートされているメソッドを確認するには、 カスタム制約をサポートするサービスをご覧ください。

    • CONDITION: サポート対象のサービス リソースの表現に対して記述する CEL 条件。このフィールドには、最大 1,000 文字まで入力できます。例: ("category" in resource.labels) && (resource.labels['category'] in ['retail', 'ads', 'service'])
    • 条件を記述できるリソースの詳細については、サポートされているリソースをご覧ください。

    • ACTION: condition が満たされている場合に実行するアクション。ALLOW のみを設定できます。
    • 許可アクションは、条件が true と評価された場合に、リソースを作成または更新するオペレーションが許可されることを意味します。つまり、条件に明記されているケース以外はすべてブロックされます。

    • DISPLAY_NAME: 制約の名前。わかりやすい名前を入力してください。この名前はエラー メッセージで使用されるほか、識別やデバッグにも使用できます。エラー メッセージで公開される可能性があるため、表示名に個人情報(PII)やセンシティブ データを使用しないでください。このフィールドには、最大 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.batchMustHaveSpecifiedCategoryLabel
  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 分かかります。

カスタム制約をテストする

このセクションでは、バッチ、セッション、セッション テンプレート リソースのカスタム制約をテストする方法について説明します。

バッチリソースのカスタム制約をテストする

次のバッチ作成の例では、カスタム制約が作成され、バッチ作成時に適用され、バッチに「retail」、「ads」、「service」の値が設定された「category」ラベルが付加されている必要があります: ("category" in resource.labels) && (resource.labels['category'] in ['retail', 'ads', 'service'])

gcloud dataproc batches submit spark \
  --region us-west1
  --jars file:///usr/lib/spark/examples/jars/spark-examples.jar \
  --class org.apache.spark.examples.SparkPi  \
  --network default \
  --labels category=foo \
  --100

出力例:

Operation denied by custom org policies: ["customConstraints/custom.batchMustHaveSpecifiedCategoryLabel": ""Only allow Dataproc batch creation if it has a 'category' label with
  a 'retail', 'ads', or 'service' value""]

セッション リソースのカスタム制約をテストする

次のセッション作成例では、カスタム制約が作成され、セッション作成時に適用され、セッションに orgName で始まる name が必要であることを前提としています。

gcloud beta dataproc sessions create spark test-session
  --location us-central1

出力例:

Operation denied by custom org policy:
["customConstraints/custom.denySessionNameNotStartingWithOrgName": "Deny session
creation if its name does not start with 'orgName'"]

セッション テンプレート リソースのカスタム制約をテストする

次のセッション テンプレート作成の例では、カスタム制約が作成され、セッション テンプレートの作成と更新時に適用され、セッション テンプレートに orgName で始まる name が必要であることを前提としています。

gcloud beta dataproc session-templates import test-session-template
--source=saved-template.yaml

出力例:

Operation denied by custom org policy:
["customConstraints/custom.denySessionTemplateNameNotStartingWithOrgName":
"Deny session template creation or update if its name does not start with
'orgName'"]

リソースとオペレーションに対する制約

このセクションでは、バッチ リソースとセッション リソースで使用可能な Managed Service for Apache Spark のカスタム制約を一覧表示します。

サポートされているバッチ制約

バッチ ワークロードを作成(送信)するときに、次の Managed Service for Apache Spark カスタム制約を使用できます。

全般

  • resource.labels

PySparkBatch

  • resource.pysparkBatch.mainPythonFileUri
  • resource.pysparkBatch.args
  • resource.pysparkBatch.pythonFileUris
  • resource.pysparkBatch.jarFileUris
  • resource.pysparkBatch.fileUris
  • resource.pysparkBatch.archiveUris

SparkBatch

  • resource.sparkBatch.mainJarFileUri
  • resource.sparkBatch.mainClass
  • resource.sparkBatch.args
  • resource.sparkBatch.jarFileUris
  • resource.sparkBatch.fileUris
  • resource.sparkBatch.archiveUris

SparRBatch

  • resource.sparkRBatch.mainRFileUri
  • resource.sparkRBatch.args
  • resource.sparkRBatch.fileUris
  • resource.sparkRBatch.archiveUris

SparkSqlBatch

  • resource.sparkSqlBatch.queryFileUri
  • resource.sparkSqlBatch.queryVariables
  • resource.sparkSqlBatch.jarFileUris

RuntimeConfig

  • resource.runtimeConfig.version
  • resource.runtimeConfig.containerImage
  • resource.runtimeConfig.properties
  • resource.runtimeConfig.repositoryConfig.pypiRepositoryConfig.pypiRepository
  • resource.runtimeConfig.autotuningConfig.scenarios
  • resource.runtimeConfig.cohort

ExecutionConfig

  • resource.environmentConfig.executionConfig.serviceAccount
  • resource.environmentConfig.executionConfig.networkUri
  • resource.environmentConfig.executionConfig.subnetworkUri
  • resource.environmentConfig.executionConfig.networkTags
  • resource.environmentConfig.executionConfig.kmsKey
  • resource.environmentConfig.executionConfig.idleTtl
  • resource.environmentConfig.executionConfig.ttl
  • resource.environmentConfig.executionConfig.stagingBucket
  • resource.environmentConfig.executionConfig.authenticationConfig.userWorkloadAuthenticationType

PeripheralsConfig

  • resource.environmentConfig.peripheralsConfig.metastoreService
  • resource.environmentConfig.peripheralsConfig.sparkHistoryServerConfig.dataprocCluster

サポートされているセッション制約

サーバーレス セッションにカスタム制約を作成するときに、次のセッション属性を使用できます。

全般

  • resource.name
  • resource.sparkConnectSession
  • resource.user
  • resource.sessionTemplate

JupyterSession

  • resource.jupyterSession.kernel
  • resource.jupyterSession.displayName

RuntimeConfig

  • resource.runtimeConfig.version
  • resource.runtimeConfig.containerImage
  • resource.runtimeConfig.properties
  • resource.runtimeConfig.repositoryConfig.pypiRepositoryConfig.pypiRepository
  • resource.runtimeConfig.autotuningConfig.scenarios
  • resource.runtimeConfig.cohort

ExecutionConfig

  • resource.environmentConfig.executionConfig.serviceAccount
  • resource.environmentConfig.executionConfig.networkUri
  • resource.environmentConfig.executionConfig.subnetworkUri
  • resource.environmentConfig.executionConfig.networkTags
  • resource.environmentConfig.executionConfig.kmsKey
  • resource.environmentConfig.executionConfig.idleTtl
  • resource.environmentConfig.executionConfig.ttl
  • resource.environmentConfig.executionConfig.stagingBucket
  • resource.environmentConfig.executionConfig.authenticationConfig.userWorkloadAuthenticationType

PeripheralsConfig

  • resource.environmentConfig.peripheralsConfig.metastoreService
  • resource.environmentConfig.peripheralsConfig.sparkHistoryServerConfig.dataprocCluster

サポートされているセッション テンプレートの制約

サーバーレス セッション テンプレートにカスタム制約を作成するときに、次のセッション テンプレート属性を使用できます。

全般

  • resource.name
  • resource.description
  • resource.sparkConnectSession

JupyterSession

  • resource.jupyterSession.kernel
  • resource.jupyterSession.displayName

RuntimeConfig

  • resource.runtimeConfig.version
  • resource.runtimeConfig.containerImage
  • resource.runtimeConfig.properties
  • resource.runtimeConfig.repositoryConfig.pypiRepositoryConfig.pypiRepository
  • resource.runtimeConfig.autotuningConfig.scenarios
  • resource.runtimeConfig.cohort

ExecutionConfig

  • resource.environmentConfig.executionConfig.serviceAccount
  • resource.environmentConfig.executionConfig.networkUri
  • resource.environmentConfig.executionConfig.subnetworkUri
  • resource.environmentConfig.executionConfig.networkTags
  • resource.environmentConfig.executionConfig.kmsKey
  • resource.environmentConfig.executionConfig.idleTtl
  • resource.environmentConfig.executionConfig.ttl
  • resource.environmentConfig.executionConfig.stagingBucket
  • resource.environmentConfig.executionConfig.authenticationConfig.userWorkloadAuthenticationType

PeripheralsConfig

  • resource.environmentConfig.peripheralsConfig.metastoreService
  • resource.environmentConfig.peripheralsConfig.sparkHistoryServerConfig.dataprocCluster

一般的なユースケースのカスタム制約の例

このセクションでは、バッチリソースとセッション リソースの一般的なユースケースのカスタム制約の例を示します。

バッチリソースのカスタム制約の例

次の表に、Managed Service for Apache Spark バッチのカスタム制約の例を示します。

説明 制約の構文
Batch では、許可された値を含む「カテゴリ」ラベルを付加する必要があります。
    name: organizations/ORGANIZATION_ID/customConstraints/custom.batchMustHaveSpecifiedCategoryLabel
    resourceTypes:
    - dataproc.googleapis.com/Batch
    methodTypes:
    - CREATE
    condition: ("category" in resource.labels) && (resource.labels['category'] in ['retail', 'ads', 'service'])
    actionType: ALLOW
    displayName: Enforce batch "category" label requirement.
    description: Only allow batch creation if it attaches a "category" label with an allowable value.
Batch では、使用できるランタイム バージョンを設定する必要があります。
    name: organizations/ORGANIZATION_ID/customConstraints/custom.batchMustUseAllowedVersion
    resourceTypes:
    - dataproc.googleapis.com/Batch
    methodTypes:
    - CREATE
    condition:  (has(resource.runtimeConfig.version)) && (resource.runtimeConfig.version in ["2.0.45", "2.0.48"])
    actionType: ALLOW
    displayName: Enforce batch runtime version.
    description: Only allow batch creation if it sets an allowable runtime version.
SparkSQL を使用する必要があります。
    name: organizations/ORGANIZATION_ID/customConstraints/custom.batchMustUseSparkSQL
    resourceTypes:
    - dataproc.googleapis.com/Batch
    methodTypes:
    - CREATE
    condition: (has(resource.sparkSqlBatch))
    actionType: ALLOW
    displayName: Enforce batch only use SparkSQL Batch.
    description: Only allow creation of SparkSQL Batch.
バッチでは、TTL を 2 時間未満に設定する必要があります。
    name: organizations/ORGANIZATION_ID/customConstraints/custom.batchMustSetLessThan2hTtl
    resourceTypes:
    - dataproc.googleapis.com/Batch
    methodTypes:
    - CREATE
    condition:  (has(resource.environmentConfig.executionConfig.ttl)) && (resource.environmentConfig.executionConfig.ttl <= duration('2h'))
    actionType: ALLOW
    displayName: Enforce batch TTL.
    description: Only allow batch creation if it sets an allowable TTL.
Batch では、20 個を超える Spark 初期エグゼキュータを設定できません。
    name: organizations/ORGANIZATION_ID/customConstraints/custom.batchInitialExecutorMax20
    resourceTypes:
    - dataproc.googleapis.com/Batch
    methodTypes:
    - CREATE
    condition: (has(resource.runtimeConfig.properties)) && ('spark.executor.instances' in resource.runtimeConfig.properties)
     && (int(resource.runtimeConfig.properties['spark.executor.instances'])>20)
    actionType: DENY
    displayName: Enforce maximum number of batch Spark executor instances.
    description: Deny batch creation if it specifies more than 20 Spark executor instances.
Batch では、20 個を超える Spark 動的割り当ての初期エグゼキュータを設定できません。
    name: organizations/ORGANIZATION_ID/customConstraints/custom.batchDynamicAllocationInitialExecutorMax20
    resourceTypes:
    - dataproc.googleapis.com/Batch
    methodTypes:
    - CREATE
    condition: (has(resource.runtimeConfig.properties)) && ('spark.dynamicAllocation.initialExecutors' in resource.runtimeConfig.properties)
     && (int(resource.runtimeConfig.properties['spark.dynamicAllocation.initialExecutors'])>20)
    actionType: DENY
    displayName: Enforce maximum number of batch dynamic allocation initial executors.
    description: Deny batch creation if it specifies more than 20 Spark dynamic allocation initial executors.
Batch では、20 個を超える動的割り当てエグゼキュータを許可してはなりません。
    name: organizations/ORGANIZATION_ID/customConstraints/custom.batchDynamicAllocationMaxExecutorMax20
    resourceTypes:
    - dataproc.googleapis.com/Batch
    methodTypes:
    - CREATE
    condition: (resource.runtimeConfig.properties['spark.dynamicAllocation.enabled']=='false') || (('spark.dynamicAllocation.maxExecutors' in resource.runtimeConfig.properties) && (int(resource.runtimeConfig.properties['spark.dynamicAllocation.maxExecutors'])<=20))
    actionType: ALLOW
    displayName: Enforce batch maximum number of dynamic allocation executors.
    description:  Only allow batch creation if dynamic allocation is disabled or
    the maximum number of dynamic allocation executors is set to less than or equal to 20.
Batch では、KMS 鍵を許可されたパターンに設定する必要があります。
    name: organizations/ORGANIZATION_ID/custom.batchKmsPattern
    resourceTypes:
    - dataproc.googleapis.com/Batch
    methodTypes:
    - CREATE
    condition:  matches(resource.environmentConfig.executionConfig.kmsKey, '^keypattern[a-z]$')
    actionType: ALLOW
    displayName: Enforce batch KMS Key pattern.
    description: Only allow batch creation if it sets the KMS key to an allowable pattern.
Batch では、ステージング バケットの接頭辞を許可された値に設定する必要があります。
    name: organizations/ORGANIZATION_ID/customConstraints/custom.batchStagingBucketPrefix
    resourceTypes:
    - dataproc.googleapis.com/Batch
    methodTypes:
    - CREATE
    condition:  resource.environmentConfig.executionConfig.stagingBucket.startsWith(ALLOWED_PREFIX)
    actionType: ALLOW
    displayName: Enforce batch staging bucket prefix.
    description: Only allow batch creation if it sets the staging bucket prefix to ALLOWED_PREFIX.
バッチ エグゼキュータのメモリ設定は、接尾辞 m で終わり、20000 m 未満にする必要があります。
    name: organizations/ORGANIZATION_ID/customConstraints/custom.batchExecutorMemoryMax
    resourceTypes:
    - dataproc.googleapis.com/Batch
    methodTypes:
    - CREATE
    condition:  ('spark.executor.memory' in resource.runtimeConfig.properties) && (resource.runtimeConfig.properties['spark.executor.memory'].endsWith('m')) && (int(resource.runtimeConfig.properties['spark.executor.memory'].split('m')[0])<20000)
    actionType: ALLOW
    displayName: Enforce batch executor maximum memory.
    description: Only allow batch creation if the executor memory setting ends with a suffix 'm' and is less than 20000 m.

セッション リソースのカスタム制約の例

次の表に、Managed Service for Apache Spark セッションのカスタム制約の例を示します。

説明 制約の構文
セッションは sessionTemplate を空の文字列に設定する必要があります。
    name: organizations/ORGANIZATION_ID/customConstraints/custom.sessionTemplateMustBeEmpty
    resourceTypes:
    - dataproc.googleapis.com/Session
    methodTypes:
    - CREATE
    condition: resource.sessionTemplate == ""
    actionType: ALLOW
    displayName: Enforce empty session templates.
    description: Only allow session creation if session template is empty string.
sessionTemplate は承認済みのテンプレート ID と同じである必要があります。
    name: organizations/ORGANIZATION_ID/customConstraints/custom.sessionTemplateIdMustBeApproved
    resourceTypes:
    - dataproc.googleapis.com/Session
    methodTypes:
    - CREATE
    condition:
    resource.sessionTemplate.startsWith("https://www.googleapis.com/compute/v1/projects/")
      &&
      resource.sessionTemplate.contains("/locations/") &&
      resource.sessionTemplate.contains("/sessionTemplates/") &&
       (
         resource.sessionTemplate.endsWith("/1") ||
         resource.sessionTemplate.endsWith("/2") ||
         resource.sessionTemplate.endsWith("/13")
       )
    actionType: ALLOW
    displayName: Enforce templateId must be 1, 2, or 13.
    description: Only allow session creation if session template ID is in the
    approved list, that is, 1, 2 and 13.
セッションは、エンドユーザー認証情報を使用してワークロードを認証する必要があります。
    name: organizations/ORGANIZATION_ID/customConstraints/custom.AllowEUCSessions
    resourceTypes:
    - dataproc.googleapis.com/Session
    methodTypes:
    - CREATE
    condition:
    resource.environmentConfig.executionConfig.authenticationConfig.userWorkloadAuthenticationType=="END_USER_CREDENTIALS"
    actionType: ALLOW
    displayName: Require end user credential authenticated sessions.
    description: Allow session creation only if the workload is authenticated
    using end-user credentials.
セッションでは、使用できるランタイム バージョンを設定する必要があります。
    name: organizations/ORGANIZATION_ID/custom.sessionMustUseAllowedVersion
    resourceTypes:
    - dataproc.googleapis.com/Session
    methodTypes:
    - CREATE
    condition: (has(resource.runtimeConfig.version)) &&
    (resource.runtimeConfig.version in ["2.0.45", "2.0.48"])
    actionType: ALLOW
    displayName: Enforce session runtime version.
    description: Only allow session creation if it sets an allowable runtime
    version.
セッションでは、TTL を 2 時間未満に設定する必要があります。
    name: organizations/ORGANIZATION_ID/customConstraints/custom.sessionMustSetLessThan2hTtl
    resourceTypes:
    - dataproc.googleapis.com/Session
    methodTypes:
    - CREATE
    condition: (has(resource.environmentConfig.executionConfig.ttl)) &&
    (resource.environmentConfig.executionConfig.ttl <= duration('2h'))
    actionType: ALLOW
    displayName: Enforce session TTL.
    description: Only allow session creation if it sets an allowable TTL.
セッションでは、20 個を超える Spark 初期エグゼキュータを設定できません。
    name: organizations/ORGANIZATION_ID/customConstraints/custom.sessionInitialExecutorMax20
    resourceTypes:
    - dataproc.googleapis.com/Session
    methodTypes:
    - CREATE
    condition: (has(resource.runtimeConfig.properties)) &&
    ('spark.executor.instances' in resource.runtimeConfig.properties) &&
    (int(resource.runtimeConfig.properties['spark.executor.instances'])>20)
    actionType: DENY
    displayName: Enforce maximum number of session Spark executor instances.
    description: Deny session creation if it specifies more than 20 Spark executor
    instances.
セッションでは、20 個を超える Spark 動的割り当て初期エグゼキュータを設定できません。
    name: organizations/ORGANIZATION_ID/customConstraints/custom.sessionDynamicAllocationInitialExecutorMax20
    resourceTypes:
    - dataproc.googleapis.com/Session
    methodTypes:
    - CREATE
    condition: (has(resource.runtimeConfig.properties)) &&
    ('spark.dynamicAllocation.initialExecutors' in resource.runtimeConfig.properties)
    && (int(resource.runtimeConfig.properties['spark.dynamicAllocation.initialExecutors'])>20)
    actionType: DENY
    displayName: Enforce maximum number of session dynamic allocation initial executors.
    description: Deny session creation if it specifies more than 20 Spark dynamic
    allocation initial executors.
Session では、KMS 鍵を許可されたパターンに設定する必要があります。
    name: organizations/ORGANIZATION_ID/customConstraints/custom.sessionKmsPattern
    resourceTypes:
    - dataproc.googleapis.com/Session
    methodTypes:
    - CREATE
    condition: matches(resource.environmentConfig.executionConfig.kmsKey, '^keypattern[a-z]$')
    actionType: ALLOW
    displayName: Enforce session KMS Key pattern.
    description: Only allow session creation if it sets the KMS key to an
    allowable pattern.
セッションでは、ステージング バケットの接頭辞を許可された値に設定する必要があります。
    name: organizations/ORGANIZATION_ID/customConstraints/custom.sessionStagingBucketPrefix
    resourceTypes:
    - dataproc.googleapis.com/Session
    methodTypes:
    - CREATE
    condition: resource.environmentConfig.executionConfig.stagingBucket.startsWith(ALLOWED_PREFIX)
    actionType: ALLOW
    displayName: Enforce session staging bucket prefix.
    description: Only allow session creation if it sets the staging bucket prefix
    to ALLOWED_PREFIX.
セッション エグゼキュータのメモリ設定は、接尾辞 m で終わり、20000 m 未満である必要があります。
    name: organizations/ORGANIZATION_ID/customConstraints/custom.sessionExecutorMemoryMax
    resourceTypes:
    - dataproc.googleapis.com/Session
    methodTypes:
    - CREATE
    condition: ('spark.executor.memory' in resource.runtimeConfig.properties) &&
    (resource.runtimeConfig.properties['spark.executor.memory'].endsWith('m')) &&
    (int(resource.runtimeConfig.properties['spark.executor.memory'].split('m')[0])<20000)
    actionType: ALLOW
    displayName: Enforce session executor maximum memory.
    description: Only allow session creation if the executor memory setting ends
    with a suffix 'm' and is less than 20000 m.

セッション テンプレート リソースのカスタム制約の例

次の表に、Managed Service for Apache Spark セッション テンプレートのカスタム制約の例を示します。

説明 制約の構文
セッション テンプレート名の末尾は org-name にする必要があります。
    name: organizations/ORGANIZATION_ID/customConstraints/custom.denySessionTemplateNameNotEndingWithOrgName
    resourceTypes:
    - dataproc.googleapis.com/SessionTemplate
    methodTypes:
    - CREATE
    - UPDATE
    condition: '!resource.name.endsWith(''org-name'')'
    actionType: DENY
    displayName: DenySessionTemplateNameNotEndingWithOrgName
    description: Deny session template creation/update if its name does not end with 'org-name'
セッション テンプレートでは、使用できるランタイム バージョンを設定する必要があります。
    name: organizations/ORGANIZATION_ID/custom.sessionTemplateMustUseAllowedVersion
    resourceTypes:
    - dataproc.googleapis.com/SessionTemplate
    methodTypes:
    - CREATE
    - UPDATE
    condition: (has(resource.runtimeConfig.version)) &&
    (resource.runtimeConfig.version in ["2.0.45", "2.0.48"])
    actionType: ALLOW
    displayName: Enforce session template runtime version.
    description: Only allow session template creation or update if it sets an
    allowable runtime version.
セッション テンプレートでは、TTL を 2 時間未満に設定する必要があります。
    name: organizations/ORGANIZATION_ID/customConstraints/custom.sessionTemplateMustSetLessThan2hTtl
    resourceTypes:
    - dataproc.googleapis.com/SessionTemplate
    methodTypes:
    - CREATE
    - UPDATE
    condition: (has(resource.environmentConfig.executionConfig.ttl)) &&
    (resource.environmentConfig.executionConfig.ttl <= duration('2h'))
    actionType: ALLOW
    displayName: Enforce session template TTL.
    description: Only allow session template creation or update if it sets an
    allowable TTL.
セッション テンプレートでは、20 個を超える Spark 初期エグゼキュータを設定できません。
    name: organizations/ORGANIZATION_ID/customConstraints/custom.sessionTemplateInitialExecutorMax20
    resourceTypes:
    - dataproc.googleapis.com/SessionTemplate
    methodTypes:
    - CREATE
    - UPDATE
    condition: (has(resource.runtimeConfig.properties)) &&
    ('spark.executor.instances' in resource.runtimeConfig.properties) &&
    (int(resource.runtimeConfig.properties['spark.executor.instances'])>20)
    actionType: DENY
    displayName: Enforce maximum number of session Spark executor instances.
    description: Deny session template creation or update if it specifies more
    than 20 Spark executor instances.
セッション テンプレートでは、20 個を超える Spark 動的割り当て初期エグゼキュータを設定できません。
    name: organizations/ORGANIZATION_ID/customConstraints/custom.sessionTemplateDynamicAllocationInitialExecutorMax20
    resourceTypes:
    - dataproc.googleapis.com/SessionTemplate
    methodTypes:
    - CREATE
    - UPDATE
    condition: (has(resource.runtimeConfig.properties)) &&
    ('spark.dynamicAllocation.initialExecutors' in resource.runtimeConfig.properties)
    && (int(resource.runtimeConfig.properties['spark.dynamicAllocation.initialExecutors'])>20)
    actionType: DENY
    displayName: Enforce maximum number of session dynamic allocation initial executors.
    description: Deny session template creation or update if it specifies more than 20
    Spark dynamic allocation initial executors.
セッション テンプレートでは、KMS 鍵を許可されたパターンに設定する必要があります。
    name: organizations/ORGANIZATION_ID/customConstraints/custom.sessionTemplateKmsPattern
    resourceTypes:
    - dataproc.googleapis.com/SessionTemplate
    methodTypes:
    - CREATE
    - UPDATE
    condition: matches(resource.environmentConfig.executionConfig.kmsKey, '^keypattern[a-z]$')
    actionType: ALLOW
    displayName: Enforce session KMS Key pattern.
    description: Only allow session template creation or update if it sets the KMS key to an
    allowable pattern.
セッション テンプレートでは、ステージング バケットの接頭辞を許可された値に設定する必要があります。
    name: organizations/ORGANIZATION_ID/customConstraints/custom.sessionTemplateStagingBucketPrefix
    resourceTypes:
    - dataproc.googleapis.com/SessionTemplate
    methodTypes:
    - CREATE
    - UPDATE
    condition: resource.environmentConfig.executionConfig.stagingBucket.startsWith(ALLOWED_PREFIX)
    actionType: ALLOW
    displayName: Enforce session staging bucket prefix.
    description: Only allow session template creation or update if it sets the staging
    bucket prefix to ALLOWED_PREFIX.
セッション テンプレートの実行プログラムのメモリ設定は、接尾辞 m で終わり、20,000 m 未満である必要があります。
    name: organizations/ORGANIZATION_ID/customConstraints/custom.sessionTemplateExecutorMemoryMax
    resourceTypes:
    - dataproc.googleapis.com/SessionTemplate
    methodTypes:
    - CREATE
    - UPDATE
    condition: ('spark.executor.memory' in resource.runtimeConfig.properties) &&
    (resource.runtimeConfig.properties['spark.executor.memory'].endsWith('m')) &&
    (int(resource.runtimeConfig.properties['spark.executor.memory'].split('m')[0])<20000)
    actionType: ALLOW
    displayName: Enforce session executor maximum memory.
    description: Only allow session template creation or update if the executor memory setting ends
    with a suffix 'm' and is less than 20000 m.

次のステップ