Model Armor のフロア設定を構成する

このドキュメントでは、Model Armor のフロア設定を表示して更新する方法について説明し、フロア設定違反の例を示します。

Model Armor のフロア設定は、 Google Cloud リソース階層の特定のポイント(組織レベル、フォルダレベル、プロジェクト レベル)で作成されたすべての Model Armor テンプレートの最小要件を指定するルールを定義します。複数のフロア設定が競合する場合は、リソース階層の下位にある設定が優先されます。たとえば、フロア設定ポリシーがフォルダレベルとプロジェクト レベルで作成されている場合、プロジェクト レベルのポリシーが適用されます。この動作は、その特定のフォルダ内のプロジェクトにのみ適用されます。

たとえば、特定のフォルダにフォルダレベルのポリシーを設定し、そのフォルダ内のすべてのコンテンツに対して悪意のある URI フィルタを有効にしたとします。そのフォルダ内に特定のプロジェクトがあります。このプロジェクトでは、より具体的なプロジェクト レベルのポリシーを構成しています。このプロジェクト レベルのポリシーでは、中程度の信頼度しきい値でプロンプト インジェクションとジェイルブレイクの検出が必要です。

結果は次のとおりです。

  • この特定のプロジェクト内に作成される Model Armor テンプレートには、少なくとも中程度の信頼度しきい値で設定されたプロンプト インジェクションとジェイルブレイクの検出フィルタを含める必要があります。これは、プロジェクト レベルのポリシーによって、そのプロジェクト内のすべてのテンプレートの最小要件が確立されるためです。

  • このプロジェクトの親フォルダの外で作成されたテンプレートは、その特定のフォルダのポリシーの影響を受けません。そのため、別のフォルダ内またはルートレベルでテンプレートを作成した場合、この特定のフォルダに設定された悪意のある URI フィルタは自動的には適用されません。これは、これらのポリシーが特定の階層レベルにスコープ設定されており、より上位の広範な組織レベルで設定されていない限り、グローバルに適用されないことを示しています。

フロア設定により、CISO とセキュリティ アーキテクトは、組織内のすべての Model Armor テンプレートに最小限のセキュリティ ポスチャーを適用できます。これらの設定は、デベロッパーがセキュリティ標準を損なうことを防ぐために役立ちます。Security Command Center のプレミアム サービスティアまたはエンタープライズ サービスティアを使用している場合、フロア設定の違反によって検出結果がトリガーされます。制限の緩い設定のテンプレートがフロア設定の前に作成されると、Security Command Center は検出結果を表示します。これらの設定は、安全性の低い Model Armor テンプレートを特定して修復するのに役立ちます。フロア設定では Sensitive Data Protection を適用できません。

始める前に

始める前に、次のタスクを完了します。

必要な権限を取得する

フロア設定の管理に必要な権限を取得するには、Model Armor フロア設定に対する Model Armor Floor Setting 管理者roles/modelarmor.floorSettingsAdmin)IAM ロールを付与するよう管理者に依頼してください。ロールの付与については、プロジェクト、フォルダ、組織へのアクセス権の管理をご覧ください。

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

API を有効にする

Model Armor を使用するには、Model Armor API を有効にする必要があります。

コンソール

  1. Enable the Model Armor 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

  2. Model Armor を有効にするプロジェクトを選択します。

gcloud

始める前に、Google Cloud CLI で Model Armor API を使用して、次の処理を行います。

  1. In the Google Cloud console, activate Cloud Shell.

    Activate Cloud Shell

    At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.

  2. 次のコマンドを実行して、Model Armor サービスの API エンドポイントを設定します。

    gcloud config set api_endpoint_overrides/modelarmor "https://modelarmor.LOCATION.rep.googleapis.com/"

    LOCATION は、Model Armor を使用するリージョンに置き換えます。

  3. 次のコマンドを実行して、Model Armor を有効にします。

      gcloud services enable modelarmor.googleapis.com --project=PROJECT_ID
       

    PROJECT_ID は、プロジェクトの ID に置き換えます。

    Vertex AI との統合

    Model Armor は Vertex AI と統合され、定義されたフロア設定に基づいて Gemini モデルのリクエストとレスポンスをスクリーニングします。プロンプトとレスポンスを可視化するには、Cloud Logging を有効にする必要があります。詳細については、Vertex AI との Model Armor の統合をご覧ください。

    フロア設定を構成する

    フロア設定を使用して、Model Armor テンプレートの最小検出しきい値を構成します。これらの設定により、新規および変更済みのテンプレートがすべて特定の要件を満たしていることを確認します。フロア設定を構成する手順は次のとおりです。

    1. Google Cloud コンソールで、[Model Armor] ページに移動します。

      [Model Armor] に移動

    2. プロジェクトを選択します。
    3. [Model Armor] ページで、[フロア設定] タブに移動し、[フロア設定を構成] をクリックします。
    4. [フロア設定を構成] ページで、構成オプションを選択します。
    5. [検出] セクションで、検出設定を構成します
    6. 省略可: Sensitive Data Protection の検出を選択する場合は、Sensitive Data Protection の設定を構成する必要があります。
    7. [責任ある AI] セクションで、コンテンツ フィルタごとに信頼度を設定します。

    8. [サービス] セクションで、これらのフロア設定を適用するサービスを選択します。

    9. [ログ] セクションで、[Cloud Logging を有効にする] を選択して、すべてのユーザー プロンプト、モデル レスポンス、フロア設定の検出機能の結果をログに記録します。

    10. 多言語検出の設定を使用するには、[多言語サポートを有効にする] を選択します。

    11. [フロア設定を保存] をクリックします。

    フロア設定の継承方法を定義する

    フロア設定を構成するときに、構成オプションを選択します。

    • 親のフロア設定を継承する: リソース階層の上位で設定されたフロア設定を継承します。[フロア設定を保存] をクリックして、次の手順をスキップします。継承された設定を表示するには、[フロア設定] タブに移動します。

    • カスタム: このプロジェクトのフロア設定を定義します。プロジェクトに定義したカスタム設定によって、継承されたフロア設定がオーバーライドされます。

    • 無効にする: 継承されたフロア設定を無効にします。つまり、Gemini ワークロードの Model Armor テンプレートと Vertex AI に検出ルールが適用されません。[フロア設定を保存] をクリックして、次の手順をスキップします。[フロア設定] タブで無効ステータスを確認します。

    フロア設定の適用先を定義する

    構成したフロア設定が適用される次のいずれかのサービスを選択します。

    • Model Armor - テンプレートの作成と更新: フロア設定に従って、プロジェクト内の新規および変更済みのすべての Model Armor テンプレートに最小設定が指定されていることを確認します。
    • Vertex AI: Gemini モデルに送信されたリクエストをスクリーニングし、フロア設定のしきい値を満たすリクエストをログに記録するかブロックします。

      [Vertex AI] を選択すると、[Vertex AI] セクションが表示され、フロア設定の適用方法を選択できます。

      • 検査のみ: フロア設定を満たしていないリクエストを検出しますが、ブロックしません。
      • 違反を検出し、ブロックする: フロア設定を満たしていないリクエストを検出してブロックします。

    Model Armor のフロア設定を表示する

    Model Armor のフロア設定を表示して、既存の設定の確認、AI アプリケーションの最小要件の特定、テンプレートが想定どおりに動作しない場合の問題のトラブルシューティングを行います。

    次のコマンドを実行して、Model Armor のフロア設定を表示します。

    コンソール

    1. Google Cloud コンソールで、[Model Armor] ページに移動します。

      [Model Armor] に移動

    2. Model Armor を有効にしたプロジェクトが表示されていることを確認します。

    3. [Model Armor] ページの [フロア設定] タブに移動します。フロア設定が組織レベルで設定されている場合は、ここで確認できます。フロア設定が定義されていない場合は、構成する必要があります。詳細については、フロア設定を構成するをご覧ください。

    gcloud

    • 特定のプロジェクトの Model Armor のフロア設定を表示します。

        gcloud model-armor floorsettings describe \
            --full-uri='projects/PROJECT_ID/locations/global/floorSetting'
    • 特定の組織の Model Armor のフロア設定を表示します。

        gcloud model-armor floorsettings describe \
            --full-uri='organizations/ORGANIZATION_ID/locations/global/floorSetting'
    • 特定のフォルダの Model Armor のフロア設定を表示します。

         gcloud model-armor floorsettings describe \
             --full-uri='folders/FOLDER_ID/locations/global/floorSetting'

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

      • PROJECT_ID: フロア設定のプロジェクトの ID。
      • FOLDER_ID: フロア設定のフォルダの ID。
      • ORGANIZATION_ID: フロア設定の組織の ID。

    REST

    • 特定のプロジェクトの Model Armor のフロア設定を表示します。

      curl -X GET \
        -H "Authorization: Bearer $(gcloud auth print-access-token)" \
        -H "Content-Type: application/json" \
        "https://modelarmor.googleapis.com/v1/projects/PROJECT_ID/locations/global/floorSetting"
    • 特定のフォルダの Model Armor のフロア設定を表示します。

      curl -X GET \
        -H "Authorization: Bearer $(gcloud auth print-access-token)" \
        -H "Content-Type: application/json" \
        "https://modelarmor.googleapis.com/v1/folders/FOLDER_ID/locations/global/floorSetting"
    • 特定の組織の Model Armor のフロア設定を表示します。

      curl -X GET \
        -H "Authorization: Bearer $(gcloud auth print-access-token)" \
        -H "Content-Type: application/json" \
        "https://modelarmor.googleapis.com/v1/organizations/ORGANIZATION_ID/locations/global/floorSetting"

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

    • PROJECT_ID: フロア設定のプロジェクトの ID。
    • FOLDER_ID: フロア設定のフォルダの ID。
    • ORGANIZATION_ID: フロア設定の組織の ID。

    Go

    このコードを実行するには、まず Go 開発環境を設定し、Model Armor Go SDK をインストールします。

    • 特定のプロジェクトの Model Armor のフロア設定を表示します。

      
      import (
      	"context"
      	"fmt"
      	"io"
      
      	modelarmor "cloud.google.com/go/modelarmor/apiv1"
      	modelarmorpb "cloud.google.com/go/modelarmor/apiv1/modelarmorpb"
      )
      
      // getProjectFloorSettings gets details of a single floor setting of a project.
      //
      // This method retrieves the details of a single floor setting of a project.
      //
      // w io.Writer: The writer to use for logging.
      // projectID string: The ID of the project.
      func getProjectFloorSettings(w io.Writer, projectID string) error {
      	ctx := context.Background()
      
      	// Create the Model Armor client.
      	client, err := modelarmor.NewClient(ctx)
      	if err != nil {
      		return fmt.Errorf("failed to create client: %w", err)
      	}
      	defer client.Close()
      
      	floorSettingsName := fmt.Sprintf("projects/%s/locations/global/floorSetting", projectID)
      
      	// Get the project floor setting.
      	req := &modelarmorpb.GetFloorSettingRequest{
      		Name: floorSettingsName,
      	}
      
      	response, err := client.GetFloorSetting(ctx, req)
      	if err != nil {
      		return fmt.Errorf("failed to get floor setting: %w", err)
      	}
      
      	// Print the retrieved floor setting using fmt.Fprintf with the io.Writer.
      	fmt.Fprintf(w, "Retrieved floor setting: %v\n", response)
      
      	return nil
      }
      
    • 特定のフォルダの Model Armor のフロア設定を表示します。

      
      import (
      	"context"
      	"fmt"
      	"io"
      
      	modelarmor "cloud.google.com/go/modelarmor/apiv1"
      	modelarmorpb "cloud.google.com/go/modelarmor/apiv1/modelarmorpb"
      )
      
      // getFolderFloorSettings gets details of a single floor setting of a folder.
      //
      // This method retrieves the details of a single floor setting of a folder.
      //
      // w io.Writer: The writer to use for logging.
      // folderID string: The ID of the folder.
      func getFolderFloorSettings(w io.Writer, folderID string) error {
      	ctx := context.Background()
      
      	// Create the Model Armor client.
      	client, err := modelarmor.NewClient(ctx)
      	if err != nil {
      		return fmt.Errorf("failed to create client: %w", err)
      	}
      	defer client.Close()
      
      	// Prepare folder floor setting path/name
      	floorSettingsName := fmt.Sprintf("folders/%s/locations/global/floorSetting", folderID)
      
      	// Get the folder floor setting.
      	req := &modelarmorpb.GetFloorSettingRequest{
      		Name: floorSettingsName,
      	}
      
      	response, err := client.GetFloorSetting(ctx, req)
      	if err != nil {
      		return fmt.Errorf("failed to get floor setting: %w", err)
      	}
      
      	// Print the retrieved floor setting using fmt.Fprintf with the io.Writer.
      	fmt.Fprintf(w, "Retrieved folder floor setting: %v\n", response)
      
      	return nil
      }
      
    • 特定の組織の Model Armor のフロア設定を表示します。

      
      import (
      	"context"
      	"fmt"
      	"io"
      
      	modelarmor "cloud.google.com/go/modelarmor/apiv1"
      	modelarmorpb "cloud.google.com/go/modelarmor/apiv1/modelarmorpb"
      )
      
      // getOrganizationFloorSettings gets details of a single floor setting of an organization.
      //
      // This method retrieves the details of a single floor setting of an organization.
      //
      // w io.Writer: The writer to use for logging.
      // organizationID string: The ID of the organization.
      func getOrganizationFloorSettings(w io.Writer, organizationID string) error {
      	ctx := context.Background()
      
      	// Create the Model Armor client.
      	client, err := modelarmor.NewClient(ctx)
      	if err != nil {
      		return fmt.Errorf("failed to create client: %w", err)
      	}
      	defer client.Close()
      
      	floorSettingsName := fmt.Sprintf("organizations/%s/locations/global/floorSetting", organizationID)
      
      	// Get the organization floor setting.
      	req := &modelarmorpb.GetFloorSettingRequest{
      		Name: floorSettingsName,
      	}
      
      	response, err := client.GetFloorSetting(ctx, req)
      	if err != nil {
      		return fmt.Errorf("failed to get floor setting: %w", err)
      	}
      
      	// Print the retrieved floor setting using fmt.Fprintf with the io.Writer.
      	fmt.Fprintf(w, "Retrieved org floor setting: %v\n", response)
      
      	return nil
      }
      

    Java

    このコードを実行するには、まず Java 開発環境を設定し、Model Armor Java SDK をインストールします。

    • 特定のプロジェクトの Model Armor のフロア設定を表示します。

      
      import com.google.cloud.modelarmor.v1.FloorSetting;
      import com.google.cloud.modelarmor.v1.FloorSettingName;
      import com.google.cloud.modelarmor.v1.GetFloorSettingRequest;
      import com.google.cloud.modelarmor.v1.ModelArmorClient;
      import java.io.IOException;
      
      public class GetProjectFloorSetting {
      
        public static void main(String[] args) throws IOException {
          // TODO(developer): Replace these variables before running the sample.
          String projectId = "your-project-id";
      
          getProjectFloorSetting(projectId);
        }
      
        public static FloorSetting getProjectFloorSetting(String projectId) throws IOException {
      
          // Initialize client that will be used to send requests. This client only
          // needs to be created once, and can be reused for multiple requests.
          try (ModelArmorClient client = ModelArmorClient.create()) {
            String name = FloorSettingName.of(projectId, "global").toString();
      
            GetFloorSettingRequest request = GetFloorSettingRequest.newBuilder().setName(name).build();
      
            FloorSetting floorSetting = client.getFloorSetting(request);
            System.out.println("Fetched floor setting for project: " + projectId);
      
            return floorSetting;
          }
        }
      }
    • 特定のフォルダの Model Armor のフロア設定を表示します。

      
      import com.google.cloud.modelarmor.v1.FloorSetting;
      import com.google.cloud.modelarmor.v1.FloorSettingName;
      import com.google.cloud.modelarmor.v1.GetFloorSettingRequest;
      import com.google.cloud.modelarmor.v1.ModelArmorClient;
      import java.io.IOException;
      
      public class GetFolderFloorSetting {
      
        public static void main(String[] args) throws IOException {
          // TODO(developer): Replace these variables before running the sample.
          String folderId = "your-folder-id";
      
          getFolderFloorSetting(folderId);
        }
      
        public static FloorSetting getFolderFloorSetting(String folderId) throws IOException {
      
          // Initialize client that will be used to send requests. This client only
          // needs to be created once, and can be reused for multiple requests.
          try (ModelArmorClient client = ModelArmorClient.create()) {
            String name = FloorSettingName.ofFolderLocationName(folderId, "global").toString();
      
            GetFloorSettingRequest request = GetFloorSettingRequest.newBuilder().setName(name).build();
      
            FloorSetting floorSetting = client.getFloorSetting(request);
            System.out.println("Fetched floor setting for folder: " + folderId);
      
            return floorSetting;
          }
        }
      }
    • 特定の組織の Model Armor のフロア設定を表示します。

      
      import com.google.cloud.modelarmor.v1.FloorSetting;
      import com.google.cloud.modelarmor.v1.FloorSettingName;
      import com.google.cloud.modelarmor.v1.GetFloorSettingRequest;
      import com.google.cloud.modelarmor.v1.ModelArmorClient;
      import java.io.IOException;
      
      public class GetOrganizationFloorSetting {
      
        public static void main(String[] args) throws IOException {
          // TODO(developer): Replace these variables before running the sample.
          String organizationId = "your-organization-id";
      
          getOrganizationFloorSetting(organizationId);
        }
      
        public static FloorSetting getOrganizationFloorSetting(String organizationId) throws IOException {
      
          // Initialize client that will be used to send requests. This client only
          // needs to be created once, and can be reused for multiple requests.
          try (ModelArmorClient client = ModelArmorClient.create()) {
            String name = FloorSettingName.ofOrganizationLocationName(organizationId, "global")
                .toString();
      
            GetFloorSettingRequest request = GetFloorSettingRequest.newBuilder().setName(name).build();
      
            FloorSetting floorSetting = client.getFloorSetting(request);
            System.out.println("Fetched floor setting for organization: " + organizationId);
      
            return floorSetting;
          }
        }
      }

    Node.js

    このコードを実行するには、まず Node.js 開発環境を設定し、Model Armor Node.js SDK をインストールします。

    • 特定のプロジェクトの Model Armor のフロア設定を表示します。

      /**
       * TODO(developer): Uncomment these variables before running the sample.
       */
      // const projectId = 'your-project-id';
      
      const name = `projects/${projectId}/locations/global/floorSetting`;
      
      // Imports the Modelarmor library
      const {ModelArmorClient} = require('@google-cloud/modelarmor').v1;
      
      // Instantiates a client
      const modelarmorClient = new ModelArmorClient();
      
      async function getProjectFloorSettings() {
        // Construct request
        const request = {
          name,
        };
      
        // Run request
        const [response] = await modelarmorClient.getFloorSetting(request);
        return response;
      }
      
      return await getProjectFloorSettings();
    • 特定のフォルダの Model Armor のフロア設定を表示します。

      /**
       * TODO(developer): Uncomment these variables before running the sample.
       */
      // const folderId = 'your-folder-id';
      
      const name = `folders/${folderId}/locations/global/floorSetting`;
      
      // Imports the Modelarmor library
      const {ModelArmorClient} = require('@google-cloud/modelarmor').v1;
      
      // Instantiates a client
      const modelarmorClient = new ModelArmorClient();
      
      async function getFolderFloorSettings() {
        // Construct request
        const request = {
          name,
        };
      
        const [response] = await modelarmorClient.getFloorSetting(request);
        return response;
      }
      
      return await getFolderFloorSettings();
    • 特定の組織の Model Armor のフロア設定を表示します。

      /**
       * TODO(developer): Uncomment these variables before running the sample.
       */
      // const organizationId = 'your-organization-id';
      const name = `organizations/${organizationId}/locations/global/floorSetting`;
      
      // Imports the Modelarmor library
      const {ModelArmorClient} = require('@google-cloud/modelarmor').v1;
      
      // Instantiates a client
      const modelarmorClient = new ModelArmorClient();
      
      async function getOrganizationFloorSettings() {
        // Construct request
        const request = {
          name,
        };
      
        // Run request
        const [response] = await modelarmorClient.getFloorSetting(request);
        return response;
      }
      
      return await getOrganizationFloorSettings();

    PHP

    このコードを実行するには、まず PHP 開発環境を設定し、Model Armor PHP SDK をインストールします。

    • 特定のプロジェクトの Model Armor のフロア設定を表示します。

      use Google\Cloud\ModelArmor\V1\Client\ModelArmorClient;
      use Google\Cloud\ModelArmor\V1\GetFloorSettingRequest;
      
      /**
       * Gets the floor settings for a given project.
       *
       * @param string $projectId The project Id for which the floor settings is to be retrieved.
       *
       */
      function get_project_floor_settings(string $projectId): void
      {
          $client = new ModelArmorClient();
      
          $floorSettingsName = sprintf('projects/%s/locations/global/floorSetting', $projectId);
      
          $response = $client->getFloorSetting((new GetFloorSettingRequest())->setName($floorSettingsName));
      
          printf("Floor settings retrieved successfully: %s\n", $response->serializeToJsonString());
      }
    • 特定のフォルダの Model Armor のフロア設定を表示します。

      use Google\Cloud\ModelArmor\V1\Client\ModelArmorClient;
      use Google\Cloud\ModelArmor\V1\GetFloorSettingRequest;
      
      /**
       * Gets the floor settings for a given folder.
       *
       * @param string $folderId The folder Id for which the floor settings is to be retrieved.
       *
       */
      function get_folder_floor_settings(string $folderId): void
      {
          $client = new ModelArmorClient();
      
          $floorSettingsName = sprintf('folders/%s/locations/global/floorSetting', $folderId);
      
          $response = $client->getFloorSetting((new GetFloorSettingRequest())->setName($floorSettingsName));
      
          printf("Floor settings retrieved successfully: %s\n", $response->serializeToJsonString());
      }
    • 特定の組織の Model Armor のフロア設定を表示します。

      use Google\Cloud\ModelArmor\V1\Client\ModelArmorClient;
      use Google\Cloud\ModelArmor\V1\GetFloorSettingRequest;
      
      /**
       * Gets the floor settings for a given organization.
       *
       * @param string $organizationId The organization Id for which the floor settings is to be retrieved.
       *
       */
      function get_organization_floor_settings(string $organizationId): void
      {
          $client = new ModelArmorClient();
      
          $floorSettingsName = sprintf('organizations/%s/locations/global/floorSetting', $organizationId);
      
          $response = $client->getFloorSetting((new GetFloorSettingRequest())->setName($floorSettingsName));
      
          printf("Floor settings retrieved successfully: %s\n", $response->serializeToJsonString());
      }

    Python

    このコードを実行するには、まず Python 開発環境を設定し、Model Armor Python SDK をインストールします。

    • 特定のプロジェクトの Model Armor のフロア設定を表示します。

      
      from google.cloud import modelarmor_v1
      
      # Create the Model Armor client.
      client = modelarmor_v1.ModelArmorClient(transport="rest")
      
      # TODO(Developer): Uncomment below variable.
      # project_id = "YOUR_PROJECT_ID"
      
      floor_settings_name = f"projects/{project_id}/locations/global/floorSetting"
      
      # Get the project floor setting.
      response = client.get_floor_setting(
          request=modelarmor_v1.GetFloorSettingRequest(name=floor_settings_name)
      )
      
      # Print the retrieved floor setting.
      print(response)
      
    • 特定のフォルダの Model Armor のフロア設定を表示します。

      
      from google.cloud import modelarmor_v1
      
      # Create the Model Armor client.
      client = modelarmor_v1.ModelArmorClient(transport="rest")
      
      # TODO(Developer): Uncomment below variable.
      # folder_id = "YOUR_FOLDER_ID"
      
      # Prepare folder floor setting path/name
      floor_settings_name = f"folders/{folder_id}/locations/global/floorSetting"
      
      # Get the folder floor setting.
      response = client.get_floor_setting(
          request=modelarmor_v1.GetFloorSettingRequest(name=floor_settings_name)
      )
      
      # Print the retrieved floor setting.
      print(response)
      
    • 特定の組織の Model Armor のフロア設定を表示します。

      
      from google.cloud import modelarmor_v1
      
      # Create the Model Armor client.
      client = modelarmor_v1.ModelArmorClient(transport="rest")
      
      # TODO(Developer): Uncomment below variable.
      # organization_id = "YOUR_ORGANIZATION_ID"
      
      floor_settings_name = (
          f"organizations/{organization_id}/locations/global/floorSetting"
      )
      
      # Get the organization floor setting.
      response = client.get_floor_setting(
          request=modelarmor_v1.GetFloorSettingRequest(name=floor_settings_name)
      )
      
      # Print the retrieved floor setting.
      print(response)
      

    Model Armor のフロア設定を更新する

    Model Armor のフロア設定を更新して、セキュリティ ポリシーの変更を反映するためのテンプレートの最小要件の変更、構成ミスの修正、フロア設定間の競合の解決を行います。

    次のコマンドを実行して、Model Armor のフロア設定を更新します。

    コンソール

    1. Google Cloud コンソールで、[Model Armor] ページに移動します。

      [Model Armor] に移動

    2. Model Armor を有効にしたプロジェクトが表示されていることを確認します。

    3. [Model Armor] ページで、[フロア設定] タブに移動し、[フロア設定を構成] をクリックします。

    4. 必須フィールドを更新して、[フロア設定を保存] をクリックします。

    gcloud

       gcloud model-armor floorsettings update --full-uri=<full-uri-of-the-floorsetting>
    

    コマンドの例:

           gcloud model-armor floorsettings update \
               --malicious-uri-filter-settings-enforcement=ENABLED \
               --pi-and-jailbreak-filter-settings-enforcement=DISABLED \
               --pi-and-jailbreak-filter-settings-confidence-level=LOW_AND_ABOVE \
               --basic-config-filter-enforcement=ENABLED \
               --add-rai-settings-filters='[{"confidenceLevel": "low_and_above", "filterType": "HARASSMENT"}, {"confidenceLevel": "high", "filterType": "SEXUALLY_EXPLICIT"}]'
               --full-uri='folders/FOLDER_ID/locations/global/floorSetting' \
               --enable-floor-setting-enforcement=true
    

    FOLDER_ID は、フロア設定のフォルダの ID に置き換えます。

    REST

    • 特定のプロジェクトの Model Armor のフロア設定を更新します。

      curl -X PATCH
        -d '{"filterConfig" :{"piAndJailbreakFilterSettings": { "filterEnforcement": "ENABLED"}, "maliciousUriFilterSettings": { "filterEnforcement": "ENABLED" }, "rai_settings":{"rai_filters":{"filter_type":"DANGEROUS", "confidence_level":"LOW_AND_ABOVE" }, \
        "rai_filters":{"filter_type":"HATE_SPEECH", "confidence_level":"LOW_AND_ABOVE" }, "rai_filters":{"filter_type":"HARASSMENT", "confidence_level":"LOW_AND_ABOVE" }, "rai_filters":{"filter_type":"SEXUALLY_EXPLICIT", "confidence_level":"LOW_AND_ABOVE" }}},"enableFloorSettingEnforcement":"true"}' \
        -H "Content-Type: application/json" \
        -H "Authorization: Bearer $(gcloud auth print-access-token) \
        "https://modelarmor.googleapis.com/v1/projects/PROJECT_ID/locations/global/floorSetting"
    • 特定のフォルダの Model Armor のフロア設定を更新します。

      curl -X PATCH \
        -d '{"filterConfig" :{"piAndJailbreakFilterSettings": { "filterEnforcement": "ENABLED"}, "maliciousUriFilterSettings": {"filterEnforcement": "ENABLED" }},"enableFloorSettingEnforcement":"true"}' \
        -H "Content-Type: application/json" \
        -H "Authorization: Bearer $(gcloud auth print-access-token)" \
        "https://modelarmor.googleapis.com/v1/folders/FOLDER_ID/locations/global/floorSetting"
    • 特定の組織の Model Armor のフロア設定を更新します。

      curl -X PATCH \
        -d '{"filterConfig" :{"piAndJailbreakFilterSettings": { "filterEnforcement": "ENABLED"}, "maliciousUriFilterSettings": {
            "filterEnforcement": "ENABLED" }},"enableFloorSettingEnforcement":"true"}' \
        -H "Content-Type: application/json" \
        -H "Authorization: Bearer $(gcloud auth print-access-token)" \
            "https://modelarmor.googleapis.com/v1/organizations/ORGANIZATION_ID/locations/global/floorSetting"

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

      • PROJECT_ID: フロア設定のプロジェクトの ID。
      • FOLDER_ID: フロア設定のフォルダの ID。
      • ORGANIZATION_ID: フロア設定の組織の ID。

      更新コマンドは、次のレスポンスを返します。

      {
      "name": "projects/PROJECT_ID/locations/global/floorSetting",
      "updateTime": "2024-12-19T15:36:21.318191Z",
      "filterConfig": {
      "piAndJailbreakFilterSettings": {
        "filterEnforcement": "ENABLED"
      },
      "maliciousUriFilterSettings": {
      "filterEnforcement": "ENABLED"
      }
      }
      }

    Go

    このコードを実行するには、まず Go 開発環境を設定し、Model Armor Go SDK をインストールします。

    • 特定のプロジェクトの Model Armor のフロア設定を更新します。

      
      import (
      	"context"
      	"fmt"
      	"io"
      
      	modelarmor "cloud.google.com/go/modelarmor/apiv1"
      	modelarmorpb "cloud.google.com/go/modelarmor/apiv1/modelarmorpb"
      )
      
      // updateProjectFloorSettings updates the floor settings of a project.
      //
      // This method updates the floor settings of a project.
      //
      // w io.Writer: The writer to use for logging.
      // projectID string: The ID of the project.
      func updateProjectFloorSettings(w io.Writer, projectID string) error {
      	ctx := context.Background()
      
      	// Create the Model Armor client.
      	client, err := modelarmor.NewClient(ctx)
      	if err != nil {
      		return fmt.Errorf("failed to create client: %w", err)
      	}
      	defer client.Close()
      
      	// Prepare project floor setting path/name
      	floorSettingsName := fmt.Sprintf("projects/%s/locations/global/floorSetting", projectID)
      
      	// Update the project floor setting
      	// For more details on filters, please refer to the following doc:
      	// [https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters](https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters)
      	enableEnforcement := true
      	req := &modelarmorpb.UpdateFloorSettingRequest{
      		FloorSetting: &modelarmorpb.FloorSetting{
      			Name: floorSettingsName,
      			FilterConfig: &modelarmorpb.FilterConfig{
      				RaiSettings: &modelarmorpb.RaiFilterSettings{
      					RaiFilters: []*modelarmorpb.RaiFilterSettings_RaiFilter{
      						{
      							FilterType:      modelarmorpb.RaiFilterType_HATE_SPEECH,
      							ConfidenceLevel: modelarmorpb.DetectionConfidenceLevel_HIGH,
      						},
      					},
      				},
      			},
      			EnableFloorSettingEnforcement: &enableEnforcement,
      		},
      	}
      
      	response, err := client.UpdateFloorSetting(ctx, req)
      	if err != nil {
      		return fmt.Errorf("failed to update floor setting: %w", err)
      	}
      
      	// Print the updated config
      	fmt.Fprintf(w, "Updated project floor setting: %+v\n", response)
      
      	return nil
      }
      
    • 特定のフォルダの Model Armor のフロア設定を更新します。

      
      import (
      	"context"
      	"fmt"
      	"io"
      
      	modelarmor "cloud.google.com/go/modelarmor/apiv1"
      	modelarmorpb "cloud.google.com/go/modelarmor/apiv1/modelarmorpb"
      )
      
      // updateFolderFloorSettings updates floor settings of a folder.
      //
      // This method updates the floor settings of a folder.
      //
      // w io.Writer: The writer to use for logging.
      // folderID string: The ID of the folder.
      func updateFolderFloorSettings(w io.Writer, folderID string) error {
      	ctx := context.Background()
      
      	// Create the Model Armor client.
      	client, err := modelarmor.NewClient(ctx)
      	if err != nil {
      		return fmt.Errorf("failed to create client: %w", err)
      	}
      	defer client.Close()
      
      	// Prepare folder floor settings path/name
      	floorSettingsName := fmt.Sprintf("folders/%s/locations/global/floorSetting", folderID)
      
      	// Prepare the floor setting update
      	enableEnforcement := true
      	floorSetting := &modelarmorpb.FloorSetting{
      		Name: floorSettingsName,
      		FilterConfig: &modelarmorpb.FilterConfig{
      			RaiSettings: &modelarmorpb.RaiFilterSettings{
      				RaiFilters: []*modelarmorpb.RaiFilterSettings_RaiFilter{
      					{
      						FilterType:      modelarmorpb.RaiFilterType_HATE_SPEECH,
      						ConfidenceLevel: modelarmorpb.DetectionConfidenceLevel_HIGH,
      					},
      				},
      			},
      		},
      		EnableFloorSettingEnforcement: &enableEnforcement,
      	}
      
      	// Prepare request for updating the floor setting.
      	req := &modelarmorpb.UpdateFloorSettingRequest{
      		FloorSetting: floorSetting,
      	}
      
      	// Update the floor setting.
      	response, err := client.UpdateFloorSetting(ctx, req)
      	if err != nil {
      		return fmt.Errorf("failed to update floor setting: %w", err)
      	}
      
      	// Print the updated config
      	fmt.Fprintf(w, "Updated folder floor setting: %v\n", response)
      
      	return nil
      
      }
      
    • 特定の組織の Model Armor のフロア設定を更新します。

      
      import (
      	"context"
      	"fmt"
      	"io"
      
      	modelarmor "cloud.google.com/go/modelarmor/apiv1"
      	modelarmorpb "cloud.google.com/go/modelarmor/apiv1/modelarmorpb"
      )
      
      // updateOrganizationFloorSettings updates floor settings of an organization.
      //
      // This method updates the floor settings of an organization.
      //
      // w io.Writer: The writer to use for logging.
      // organizationID string: The ID of the organization.
      func updateOrganizationFloorSettings(w io.Writer, organizationID string) error {
      	ctx := context.Background()
      
      	// Create the Model Armor client.
      	client, err := modelarmor.NewClient(ctx)
      	if err != nil {
      		return fmt.Errorf("failed to create client: %w", err)
      	}
      	defer client.Close()
      
      	// Prepare organization floor setting path/name
      	floorSettingsName := fmt.Sprintf("organizations/%s/locations/global/floorSetting", organizationID)
      
      	// Update the organization floor setting
      	// For more details on filters, please refer to the following doc:
      	// [https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters](https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters)
      	enableEnforcement := true
      	req := &modelarmorpb.UpdateFloorSettingRequest{
      		FloorSetting: &modelarmorpb.FloorSetting{
      			Name: floorSettingsName,
      			FilterConfig: &modelarmorpb.FilterConfig{
      				RaiSettings: &modelarmorpb.RaiFilterSettings{
      					RaiFilters: []*modelarmorpb.RaiFilterSettings_RaiFilter{
      						{
      							FilterType:      modelarmorpb.RaiFilterType_HATE_SPEECH,
      							ConfidenceLevel: modelarmorpb.DetectionConfidenceLevel_HIGH,
      						},
      					},
      				},
      			},
      			EnableFloorSettingEnforcement: &enableEnforcement,
      		},
      	}
      
      	response, err := client.UpdateFloorSetting(ctx, req)
      	if err != nil {
      		return fmt.Errorf("failed to update floor setting: %w", err)
      	}
      
      	// Print the updated config
      	fmt.Fprintf(w, "Updated org floor setting: %+v\n", response)
      

    Java

    このコードを実行するには、まず Java 開発環境を設定し、Model Armor Java SDK をインストールします。

    • 特定のプロジェクトの Model Armor のフロア設定を更新します。

      
      import com.google.cloud.modelarmor.v1.DetectionConfidenceLevel;
      import com.google.cloud.modelarmor.v1.FilterConfig;
      import com.google.cloud.modelarmor.v1.FloorSetting;
      import com.google.cloud.modelarmor.v1.FloorSettingName;
      import com.google.cloud.modelarmor.v1.ModelArmorClient;
      import com.google.cloud.modelarmor.v1.RaiFilterSettings;
      import com.google.cloud.modelarmor.v1.RaiFilterSettings.RaiFilter;
      import com.google.cloud.modelarmor.v1.RaiFilterType;
      import com.google.cloud.modelarmor.v1.UpdateFloorSettingRequest;
      import com.google.protobuf.FieldMask;
      import java.io.IOException;
      import java.util.List;
      
      public class UpdateProjectFloorSetting {
      
        public static void main(String[] args) throws IOException {
          // TODO(developer): Replace these variables before running the sample.
          String projectId = "your-project-id";
      
          updateProjectFloorSetting(projectId);
        }
      
        public static FloorSetting updateProjectFloorSetting(String projectId)
            throws IOException {
      
          // Initialize client that will be used to send requests. This client only
          // needs to be created once, and can be reused for multiple requests.
          try (ModelArmorClient client = ModelArmorClient.create()) {
            String name = FloorSettingName.of(projectId, "global").toString();
      
            // For more details on filters, please refer to the following doc:
            // https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters
            RaiFilterSettings raiFilterSettings =
                RaiFilterSettings.newBuilder()
                    .addAllRaiFilters(
                        List.of(
                            RaiFilter.newBuilder()
                                .setFilterType(RaiFilterType.HARASSMENT)
                                .setConfidenceLevel(DetectionConfidenceLevel.LOW_AND_ABOVE)
                                .build(),
                            RaiFilter.newBuilder()
                                .setFilterType(RaiFilterType.SEXUALLY_EXPLICIT)
                                .setConfidenceLevel(DetectionConfidenceLevel.HIGH)
                                .build()))
                    .build();
      
            FilterConfig modelArmorFilter = FilterConfig.newBuilder()
                .setRaiSettings(raiFilterSettings)
                .build();
      
            // Create a field mask to specify which fields to update.
            // Ref: https://protobuf.dev/reference/protobuf/google.protobuf/#field-mask
            FieldMask updateMask = FieldMask.newBuilder().addPaths("filter_config.rai_settings").build();
      
            FloorSetting floorSetting = FloorSetting.newBuilder()
                .setName(name)
                .setFilterConfig(modelArmorFilter)
                .setEnableFloorSettingEnforcement(true)
                .build();
      
            UpdateFloorSettingRequest request = UpdateFloorSettingRequest.newBuilder()
                .setFloorSetting(floorSetting)
                .setUpdateMask(updateMask)
                .build();
      
            FloorSetting updatedFloorSetting = client.updateFloorSetting(request);
            System.out.println("Updated floor setting for project: " + projectId);
      
            return updatedFloorSetting;
          }
        }
      }
    • 特定のフォルダの Model Armor のフロア設定を更新します。

      
      import com.google.cloud.modelarmor.v1.DetectionConfidenceLevel;
      import com.google.cloud.modelarmor.v1.FilterConfig;
      import com.google.cloud.modelarmor.v1.FloorSetting;
      import com.google.cloud.modelarmor.v1.FloorSettingName;
      import com.google.cloud.modelarmor.v1.ModelArmorClient;
      import com.google.cloud.modelarmor.v1.RaiFilterSettings;
      import com.google.cloud.modelarmor.v1.RaiFilterSettings.RaiFilter;
      import com.google.cloud.modelarmor.v1.RaiFilterType;
      import com.google.cloud.modelarmor.v1.UpdateFloorSettingRequest;
      import com.google.protobuf.FieldMask;
      import java.io.IOException;
      import java.util.List;
      
      public class UpdateFolderFloorSetting {
      
        public static void main(String[] args) throws IOException {
          // TODO(developer): Replace these variables before running the sample.
          String folderId = "your-folder-id";
      
          updateFolderFloorSetting(folderId);
        }
      
        public static FloorSetting updateFolderFloorSetting(String folderId)
            throws IOException {
      
          // Initialize client that will be used to send requests. This client only
          // needs to be created once, and can be reused for multiple requests.
          try (ModelArmorClient client = ModelArmorClient.create()) {
            String name = FloorSettingName.ofFolderLocationName(folderId, "global").toString();
      
            // For more details on filters, please refer to the following doc:
            // https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters
            RaiFilterSettings raiFilterSettings =
                RaiFilterSettings.newBuilder()
                    .addAllRaiFilters(
                        List.of(
                            RaiFilter.newBuilder()
                                .setFilterType(RaiFilterType.HARASSMENT)
                                .setConfidenceLevel(DetectionConfidenceLevel.LOW_AND_ABOVE)
                                .build(),
                            RaiFilter.newBuilder()
                                .setFilterType(RaiFilterType.SEXUALLY_EXPLICIT)
                                .setConfidenceLevel(DetectionConfidenceLevel.HIGH)
                                .build()))
                    .build();
      
            FilterConfig modelArmorFilter = FilterConfig.newBuilder()
                .setRaiSettings(raiFilterSettings)
                .build();
      
            // Create a field mask to specify which fields to update.
            // Ref: https://protobuf.dev/reference/protobuf/google.protobuf/#field-mask
            FieldMask updateMask = FieldMask.newBuilder().addPaths("filter_config.rai_settings").build();
      
            FloorSetting floorSetting = FloorSetting.newBuilder()
                .setName(name)
                .setFilterConfig(modelArmorFilter)
                .setEnableFloorSettingEnforcement(true)
                .build();
      
            UpdateFloorSettingRequest request = UpdateFloorSettingRequest.newBuilder()
                .setFloorSetting(floorSetting)
                .setUpdateMask(updateMask)
                .build();
      
            FloorSetting updatedFloorSetting = client.updateFloorSetting(request);
            System.out.println("Updated floor setting for folder: " + folderId);
      
            return updatedFloorSetting;
          }
        }
      }
    • 特定の組織の Model Armor のフロア設定を更新します。

      
      import com.google.cloud.modelarmor.v1.DetectionConfidenceLevel;
      import com.google.cloud.modelarmor.v1.FilterConfig;
      import com.google.cloud.modelarmor.v1.FloorSetting;
      import com.google.cloud.modelarmor.v1.FloorSettingName;
      import com.google.cloud.modelarmor.v1.ModelArmorClient;
      import com.google.cloud.modelarmor.v1.RaiFilterSettings;
      import com.google.cloud.modelarmor.v1.RaiFilterSettings.RaiFilter;
      import com.google.cloud.modelarmor.v1.RaiFilterType;
      import com.google.cloud.modelarmor.v1.UpdateFloorSettingRequest;
      import com.google.protobuf.FieldMask;
      import java.io.IOException;
      import java.util.List;
      
      public class UpdateOrganizationsFloorSetting {
      
        public static void main(String[] args) throws IOException {
          // TODO(developer): Replace these variables before running the sample.
          String organizationId = "your-organization-id";
      
          updateOrganizationFloorSetting(organizationId);
        }
      
        public static FloorSetting updateOrganizationFloorSetting(String organizationId)
            throws IOException {
      
          // Initialize client that will be used to send requests. This client only
          // needs to be created once, and can be reused for multiple requests.
          try (ModelArmorClient client = ModelArmorClient.create()) {
            String name = FloorSettingName.ofOrganizationLocationName(organizationId, "global")
                .toString();
      
            // For more details on filters, please refer to the following doc:
            // https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters
            RaiFilterSettings raiFilterSettings =
                RaiFilterSettings.newBuilder()
                    .addAllRaiFilters(
                        List.of(
                            RaiFilter.newBuilder()
                                .setFilterType(RaiFilterType.HARASSMENT)
                                .setConfidenceLevel(DetectionConfidenceLevel.LOW_AND_ABOVE)
                                .build(),
                            RaiFilter.newBuilder()
                                .setFilterType(RaiFilterType.SEXUALLY_EXPLICIT)
                                .setConfidenceLevel(DetectionConfidenceLevel.HIGH)
                                .build()))
                    .build();
      
            FilterConfig modelArmorFilter = FilterConfig.newBuilder()
                .setRaiSettings(raiFilterSettings)
                .build();
      
            // Create a field mask to specify which fields to update.
            // Ref: https://protobuf.dev/reference/protobuf/google.protobuf/#field-mask
            FieldMask updateMask = FieldMask.newBuilder()
                .addPaths("filter_config.rai_settings")
                .build();
      
            FloorSetting floorSetting = FloorSetting.newBuilder()
                .setName(name)
                .setFilterConfig(modelArmorFilter)
                .setEnableFloorSettingEnforcement(true)
                .build();
      
            UpdateFloorSettingRequest request = UpdateFloorSettingRequest.newBuilder()
                .setFloorSetting(floorSetting)
                .setUpdateMask(updateMask)
                .build();
      
            FloorSetting updatedFloorSetting = client.updateFloorSetting(request);
            System.out.println("Updated floor setting for organization: " + organizationId);
      
            return updatedFloorSetting;
          }
        }
      }

    Node.js

    このコードを実行するには、まず Node.js 開発環境を設定し、Model Armor Node.js SDK をインストールします。

    • 特定のプロジェクトの Model Armor のフロア設定を更新します。

      /**
       * TODO(developer): Uncomment these variables before running the sample.
       */
      // const projectId = 'your-project-id';
      
      const modelarmor = require('@google-cloud/modelarmor');
      const {ModelArmorClient} = modelarmor.v1;
      const {protos} = modelarmor;
      
      // Initiate client
      const client = new ModelArmorClient();
      
      async function updateProjectFloorSettings() {
        const floorSettingsName = `projects/${projectId}/locations/global/floorSetting`;
      
        // Build the floor settings with your preferred filters
        // For more details on filters, please refer to the following doc:
        // https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters
        const floorSetting = {
          name: floorSettingsName,
          filterConfig: {
            raiSettings: {
              raiFilters: [
                {
                  filterType:
                    protos.google.cloud.modelarmor.v1.RaiFilterType.HARASSMENT,
                  confidenceLevel:
                    protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel
                      .LOW_AND_ABOVE,
                },
                {
                  filterType:
                    protos.google.cloud.modelarmor.v1.RaiFilterType
                      .SEXUALLY_EXPLICIT,
                  confidenceLevel:
                    protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel
                      .LOW_AND_ABOVE,
                },
              ],
            },
          },
          enableFloorSettingEnforcement: true,
        };
      
        const request = {
          floorSetting: floorSetting,
        };
      
        const [response] = await client.updateFloorSetting(request);
        return response;
      }
      
      return await updateProjectFloorSettings();
    • 特定のフォルダの Model Armor のフロア設定を更新します。

      /**
       * TODO(developer): Uncomment these variables before running the sample.
       */
      // const folderId = 'your-folder-id';
      
      // Imports the Model Armor library
      const modelarmor = require('@google-cloud/modelarmor');
      const {ModelArmorClient} = modelarmor.v1;
      const {protos} = modelarmor;
      
      // Instantiates a client
      const client = new ModelArmorClient();
      
      async function updateFolderFloorSettings() {
        const floorSettingsName = `folders/${folderId}/locations/global/floorSetting`;
      
        // Build the floor settings with your preferred filters
        // For more details on filters, please refer to the following doc:
        // https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters
        const floorSetting = {
          name: floorSettingsName,
          filterConfig: {
            raiSettings: {
              raiFilters: [
                {
                  filterType:
                    protos.google.cloud.modelarmor.v1.RaiFilterType.HARASSMENT,
                  confidenceLevel:
                    protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel
                      .LOW_AND_ABOVE,
                },
                {
                  filterType:
                    protos.google.cloud.modelarmor.v1.RaiFilterType
                      .SEXUALLY_EXPLICIT,
                  confidenceLevel:
                    protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel
                      .LOW_AND_ABOVE,
                },
              ],
            },
          },
          enableFloorSettingEnforcement: true,
        };
      
        const request = {
          floorSetting: floorSetting,
        };
      
        const [response] = await client.updateFloorSetting(request);
        return response;
      }
      
      return await updateFolderFloorSettings();
    • 特定の組織の Model Armor のフロア設定を更新します。

      /**
       * TODO(developer): Uncomment these variables before running the sample.
       */
      // const organizationId = 'your-organization-id';
      
      const modelarmor = require('@google-cloud/modelarmor');
      const {ModelArmorClient} = modelarmor.v1;
      const {protos} = modelarmor;
      
      const client = new ModelArmorClient();
      
      async function updateOrganizationFloorSettings() {
        const floorSettingsName = `organizations/${organizationId}/locations/global/floorSetting`;
      
        // Build the floor settings with your preferred filters
        // For more details on filters, please refer to the following doc:
        // https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters
        const floorSetting = {
          name: floorSettingsName,
          filterConfig: {
            raiSettings: {
              raiFilters: [
                {
                  filterType:
                    protos.google.cloud.modelarmor.v1.RaiFilterType.HARASSMENT,
                  confidenceLevel:
                    protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel
                      .LOW_AND_ABOVE,
                },
                {
                  filterType:
                    protos.google.cloud.modelarmor.v1.RaiFilterType
                      .SEXUALLY_EXPLICIT,
                  confidenceLevel:
                    protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel
                      .LOW_AND_ABOVE,
                },
              ],
            },
          },
          enableFloorSettingEnforcement: true,
        };
      
        const request = {
          floorSetting: floorSetting,
        };
      
        const [response] = await client.updateFloorSetting(request);
        return response;
      }
      
      return await updateOrganizationFloorSettings();

    PHP

    このコードを実行するには、まず PHP 開発環境を設定し、Model Armor PHP SDK をインストールします。

    • 特定のプロジェクトの Model Armor のフロア設定を更新します。

      use Google\Cloud\ModelArmor\V1\Client\ModelArmorClient;
      use Google\Cloud\ModelArmor\V1\RaiFilterType;
      use Google\Cloud\ModelArmor\V1\DetectionConfidenceLevel;
      use Google\Cloud\ModelArmor\V1\UpdateFloorSettingRequest;
      use Google\Cloud\ModelArmor\V1\FilterConfig;
      use Google\Cloud\ModelArmor\V1\FloorSetting;
      use Google\Cloud\ModelArmor\V1\RaiFilterSettings;
      use Google\Cloud\ModelArmor\V1\RaiFilterSettings\RaiFilter;
      
      /**
       * Updates the floor settings for a given project.
       *
       * @param string $projectId The project Id for which the floor settings is to be updated.
       *
       */
      function update_project_floor_settings(string $projectId): void
      {
          $client = new ModelArmorClient();
      
          $floorSettingsName = sprintf('projects/%s/locations/global/floorSetting', $projectId);
      
          // Build the floor settings with your preferred filters
          // For more details on filters, please refer to the following doc:
          // https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters
      
          $raiFilterSetting = (new RaiFilterSettings())
              ->setRaiFilters([
                  (new RaiFilter())
                      ->setFilterType(RaiFilterType::HATE_SPEECH)
                      ->setConfidenceLevel(DetectionConfidenceLevel::HIGH)
              ]);
      
          $filterConfig = (new FilterConfig())->setRaiSettings($raiFilterSetting);
          $floorSetting = (new FloorSetting())
              ->setName($floorSettingsName)
              ->setFilterConfig($filterConfig)
              ->setEnableFloorSettingEnforcement(true);
      
          $updateRequest = (new UpdateFloorSettingRequest())->setFloorSetting($floorSetting);
      
          $response = $client->updateFloorSetting($updateRequest);
      
          printf("Floor setting updated: %s\n", $response->getName());
      }
    • 特定のフォルダの Model Armor のフロア設定を更新します。

      use Google\Cloud\ModelArmor\V1\Client\ModelArmorClient;
      use Google\Cloud\ModelArmor\V1\RaiFilterType;
      use Google\Cloud\ModelArmor\V1\DetectionConfidenceLevel;
      use Google\Cloud\ModelArmor\V1\UpdateFloorSettingRequest;
      use Google\Cloud\ModelArmor\V1\FilterConfig;
      use Google\Cloud\ModelArmor\V1\FloorSetting;
      use Google\Cloud\ModelArmor\V1\RaiFilterSettings;
      use Google\Cloud\ModelArmor\V1\RaiFilterSettings\RaiFilter;
      
      /**
       * Updates the floor settings for a given folder.
       *
       * @param string $folderId The folder Id for which the floor settings is to be updated.
       *
       */
      function update_folder_floor_settings(string $folderId): void
      {
          $client = new ModelArmorClient();
      
          $floorSettingsName = sprintf('folders/%s/locations/global/floorSetting', $folderId);
      
          // Build the floor settings with your preferred filters
          // For more details on filters, please refer to the following doc:
          // https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters
      
          $raiFilterSetting = (new RaiFilterSettings())
              ->setRaiFilters([
                  (new RaiFilter())
                      ->setFilterType(RaiFilterType::HATE_SPEECH)
                      ->setConfidenceLevel(DetectionConfidenceLevel::HIGH)
              ]);
      
          $filterConfig = (new FilterConfig())->setRaiSettings($raiFilterSetting);
          $floorSetting = (new FloorSetting())
              ->setName($floorSettingsName)
              ->setFilterConfig($filterConfig)
              ->setEnableFloorSettingEnforcement(true);
      
          $updateRequest = (new UpdateFloorSettingRequest())->setFloorSetting($floorSetting);
      
          $response = $client->updateFloorSetting($updateRequest);
      
          printf("Floor setting updated: %s\n", $response->getName());
      }
    • 特定の組織の Model Armor のフロア設定を更新します。

      use Google\Cloud\ModelArmor\V1\Client\ModelArmorClient;
      use Google\Cloud\ModelArmor\V1\RaiFilterType;
      use Google\Cloud\ModelArmor\V1\DetectionConfidenceLevel;
      use Google\Cloud\ModelArmor\V1\UpdateFloorSettingRequest;
      use Google\Cloud\ModelArmor\V1\FilterConfig;
      use Google\Cloud\ModelArmor\V1\FloorSetting;
      use Google\Cloud\ModelArmor\V1\RaiFilterSettings;
      use Google\Cloud\ModelArmor\V1\RaiFilterSettings\RaiFilter;
      
      /**
       * Updates the floor settings for a given organization.
       *
       * @param string $organizationId The organization Id for which the floor settings is to be updated.
       *
       */
      function update_organization_floor_settings(string $organizationId)
      {
          $client = new ModelArmorClient();
      
          $floorSettingsName = sprintf('organizations/%s/locations/global/floorSetting', $organizationId);
      
          // Build the floor settings with your preferred filters
          // For more details on filters, please refer to the following doc:
          // https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters
      
          $raiFilterSetting = (new RaiFilterSettings())
              ->setRaiFilters([
                  (new RaiFilter())
                      ->setFilterType(RaiFilterType::HATE_SPEECH)
                      ->setConfidenceLevel(DetectionConfidenceLevel::HIGH)
              ]);
      
          $filterConfig = (new FilterConfig())->setRaiSettings($raiFilterSetting);
          $floorSetting = (new FloorSetting())
              ->setName($floorSettingsName)
              ->setFilterConfig($filterConfig)
              ->setEnableFloorSettingEnforcement(true);
      
          $updateRequest = (new UpdateFloorSettingRequest())->setFloorSetting($floorSetting);
      
          $response = $client->updateFloorSetting($updateRequest);
      
          printf("Floor setting updated: %s\n", $response->getName());
      }

    Python

    このコードを実行するには、まず Python 開発環境を設定し、Model Armor Python SDK をインストールします。

    • 特定のプロジェクトの Model Armor のフロア設定を更新します。

      
      from google.cloud import modelarmor_v1
      
      # Create the Model Armor client.
      client = modelarmor_v1.ModelArmorClient(transport="rest")
      
      # TODO(Developer): Uncomment these variables.
      # project_id = "YOUR_PROJECT_ID"
      
      # Prepare project floor setting path/name
      floor_settings_name = f"projects/{project_id}/locations/global/floorSetting"
      
      # Update the project floor setting
      # For more details on filters, please refer to the following doc:
      # https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters
      response = client.update_floor_setting(
          request=modelarmor_v1.UpdateFloorSettingRequest(
              floor_setting=modelarmor_v1.FloorSetting(
                  name=floor_settings_name,
                  filter_config=modelarmor_v1.FilterConfig(
                      rai_settings=modelarmor_v1.RaiFilterSettings(
                          rai_filters=[
                              modelarmor_v1.RaiFilterSettings.RaiFilter(
                                  filter_type=modelarmor_v1.RaiFilterType.HATE_SPEECH,
                                  confidence_level=modelarmor_v1.DetectionConfidenceLevel.HIGH,
                              )
                          ]
                      ),
                  ),
                  enable_floor_setting_enforcement=True,
              )
          )
      )
      # Print the updated config
      print(response)
      
    • 特定のフォルダの Model Armor のフロア設定を更新します。

      
      from google.cloud import modelarmor_v1
      
      # Create the Model Armor client.
      client = modelarmor_v1.ModelArmorClient(transport="rest")
      
      # TODO (Developer): Uncomment these variables and initialize
      # folder_id = "YOUR_FOLDER_ID"
      
      # Prepare folder floor settings path/name
      floor_settings_name = f"folders/{folder_id}/locations/global/floorSetting"
      
      # Update the folder floor setting
      # For more details on filters, please refer to the following doc:
      # https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters
      response = client.update_floor_setting(
          request=modelarmor_v1.UpdateFloorSettingRequest(
              floor_setting=modelarmor_v1.FloorSetting(
                  name=floor_settings_name,
                  filter_config=modelarmor_v1.FilterConfig(
                      rai_settings=modelarmor_v1.RaiFilterSettings(
                          rai_filters=[
                              modelarmor_v1.RaiFilterSettings.RaiFilter(
                                  filter_type=modelarmor_v1.RaiFilterType.HATE_SPEECH,
                                  confidence_level=modelarmor_v1.DetectionConfidenceLevel.HIGH,
                              )
                          ]
                      ),
                  ),
                  enable_floor_setting_enforcement=True,
              )
          )
      )
      # Print the updated config
      print(response)
      
    • 特定の組織の Model Armor のフロア設定を更新します。

      
      from google.cloud import modelarmor_v1
      
      # Create the Model Armor client.
      client = modelarmor_v1.ModelArmorClient(transport="rest")
      
      # TODO (Developer): Uncomment these variables and initialize
      # organization_id = "YOUR_ORGANIZATION_ID"
      
      # Prepare organization floor setting path/name
      floor_settings_name = (
          f"organizations/{organization_id}/locations/global/floorSetting"
      )
      
      # Update the organization floor setting
      # For more details on filters, please refer to the following doc:
      # https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters
      response = client.update_floor_setting(
          request=modelarmor_v1.UpdateFloorSettingRequest(
              floor_setting=modelarmor_v1.FloorSetting(
                  name=floor_settings_name,
                  filter_config=modelarmor_v1.FilterConfig(
                      rai_settings=modelarmor_v1.RaiFilterSettings(
                          rai_filters=[
                              modelarmor_v1.RaiFilterSettings.RaiFilter(
                                  filter_type=modelarmor_v1.RaiFilterType.HATE_SPEECH,
                                  confidence_level=modelarmor_v1.DetectionConfidenceLevel.HIGH,
                              )
                          ]
                      ),
                  ),
                  enable_floor_setting_enforcement=True,
              )
          )
      )
      # Print the updated config
      print(response)
      

    フロア設定違反に関する検出結果を確認する

    Model Armor の検出結果は、フロア設定の違反を特定します。Model Armor テンプレートがリソース階層のフロア設定で定義された最小セキュリティ基準を満たしていない場合に違反が発生します。フロア設定では、テンプレートの最小要件を定義します。フロア設定の違反には、必須フィルタがテンプレートにないか、またはそれらのフィルタの最小信頼レベルを満たしていないことが含まれる場合があります。違反が検出されると、Security Command Center に重大度の高い検出結果が生成されます。この検出結果は、違反したフロア設定、非準拠のテンプレート、違反の詳細が示します。

    次の例は、検出結果の sourceProperties フィールドを示しています。悪意のある URI フィルタに関連するこの違反は、maliciousUriFilterSettings のテンプレート設定が DISABLED であるのに対し、フロア設定では ENABLED にする必要があるために発生しました。

    {
      "filterConfig": {
        "raiSettings": {
          "raiFilters": [
            {
              "filterType": "HATE_SPEECH",
              "confidenceLevel": {
                "floorSettings": "LOW_AND_ABOVE",
                "template": "MEDIUM_AND_ABOVE"
              }
            },
            {
              "filterType": "HARASSMENT",
              "confidenceLevel": {
                "floorSettings": "MEDIUM_AND_ABOVE",
                "template": "HIGH"
              }
            }
          ]
        },
        "piAndJailbreakFilterSettings": {
          "confidenceLevel": {
            "floorSettings": "LOW_AND_ABOVE",
            "template": "HIGH"
          }
        },
        "maliciousUriFilterSettings": {
          "floorSettings": "ENABLED",
          "template": "DISABLED"
        }
      }
    }

    次のステップ